qemuxml2argvtest: Cache QAPI schema between tests

It's quite wasteful to reparse the QAPI schema for each _CAPS_ test.

Add a simple cache filled lazily by encountered schemas.

The time saving on my box is quite significant:

real	0m3.318s
user	0m3.203s
sys	0m0.107s

vs

real	0m2.223s
user	0m2.134s
sys	0m0.084s

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-19 16:19:09 +01:00
parent 8298a5bd69
commit 9995a1af45
2 changed files with 15 additions and 3 deletions

View File

@ -523,13 +523,22 @@ testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv,
qemuDomainObjPrivatePtr priv = NULL;
size_t nargs = 0;
size_t i;
g_autoptr(GHashTable) schema = NULL;
GHashTable *schema = NULL;
g_autoptr(virCommand) cmd = NULL;
unsigned int parseFlags = info->parseFlags;
bool netdevQAPIfied = false;
if (info->schemafile)
schema = testQEMUSchemaLoad(info->schemafile);
if (info->schemafile) {
/* lookup and insert into cache if not found */
if (!g_hash_table_lookup_extended(info->qapiSchemaCache,
info->schemafile,
NULL, (void **) &schema)) {
schema = testQEMUSchemaLoad(info->schemafile);
g_hash_table_insert(info->qapiSchemaCache,
g_strdup(info->schemafile),
schema);
}
}
/* comment out with line comment to enable schema checking for non _CAPS tests
if (!schema)
@ -779,6 +788,7 @@ mymain(void)
int ret = 0;
g_autofree char *fakerootdir = NULL;
g_autoptr(GHashTable) capslatest = NULL;
g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) virHashFree);
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
@ -872,6 +882,7 @@ mymain(void)
static struct testQemuInfo info = { \
.name = _name, \
}; \
info.qapiSchemaCache = qapiSchemaCache; \
if (testQemuInfoSetArgs(&info, capslatest, \
__VA_ARGS__, ARG_END) < 0) \
return EXIT_FAILURE; \

View File

@ -66,6 +66,7 @@ struct testQemuInfo {
unsigned int parseFlags;
virArch arch;
char *schemafile;
GHashTable *qapiSchemaCache;
};
virCapsPtr testQemuCapsInit(void);