]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu*xml2*test: Cache capabilities between tests
authorPeter Krempa <pkrempa@redhat.com>
Fri, 19 Feb 2021 15:46:45 +0000 (16:46 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Sat, 20 Feb 2021 12:28:50 +0000 (13:28 +0100)
Invoking the XML parser every time is quite expensive. Since we have a
deep copy function for 'virQEMUCapsPtr' object, we can cache the parsed
results lazily.

This brings significant speedup to qemuxml2argvtest:

real 0m2.234s
user 0m2.140s
sys 0m0.089s

vs.

real 0m1.161s
user 0m1.087s
sys 0m0.072s

qemuxml2xmltest benefits too:

real 0m0.879s
user 0m0.801s
sys 0m0.071s

vs.

real 0m0.466s
user 0m0.424s
sys 0m0.040s

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tests/qemustatusxml2xmltest.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index 39be0edf69d28cc7af6c9abd053c8b3c588e0427..a39ad87ae57c4ab1428a6e11e2ed61ece929b885 100644 (file)
@@ -73,6 +73,7 @@ mymain(void)
     g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
     g_autoptr(virConnect) conn = NULL;
 
     capslatest = testQemuGetLatestCaps();
@@ -109,7 +110,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
-        if (testQemuInfoSetArgs(&info, capslatest, \
+        if (testQemuInfoSetArgs(&info, capscache, capslatest, \
                                 ARG_QEMU_CAPS, QEMU_CAPS_LAST, \
                                 ARG_END) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
index 2d538bee9ce2c9b0e6e1e14a3f2304529cbcb3e1..d6d707cd24c5b0785c17cf6bf9b91bcc8725760e 100644 (file)
@@ -789,6 +789,7 @@ mymain(void)
     g_autofree char *fakerootdir = NULL;
     g_autoptr(GHashTable) capslatest = NULL;
     g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) virHashFree);
+    g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
 
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
@@ -883,7 +884,7 @@ mymain(void)
             .name = _name, \
         }; \
         info.qapiSchemaCache = qapiSchemaCache; \
-        if (testQemuInfoSetArgs(&info, capslatest, \
+        if (testQemuInfoSetArgs(&info, capscache, capslatest, \
                                 __VA_ARGS__, ARG_END) < 0) \
             return EXIT_FAILURE; \
         testInfoSetPaths(&info, _suffix); \
index 5cd945f28fceed11183aa3d3107c644770dafdd0..01ac5886f2913d7bd5b15345ee5f880795fdd8cd 100644 (file)
@@ -85,6 +85,7 @@ mymain(void)
     g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
     g_autoptr(virConnect) conn = NULL;
 
     capslatest = testQemuGetLatestCaps();
@@ -130,7 +131,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
-        if (testQemuInfoSetArgs(&info, capslatest, \
+        if (testQemuInfoSetArgs(&info, capscache, capslatest, \
                                 __VA_ARGS__, \
                                 ARG_END) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
index a96c9d487a78e83fceab71d5cf5f5298cc99d82e..22f43c3bec08e63eff777b43bb3e6ed1e6a03dd1 100644 (file)
@@ -681,6 +681,7 @@ testQemuCapsIterate(const char *suffix,
 
 int
 testQemuInfoSetArgs(struct testQemuInfo *info,
+                    GHashTable *capscache,
                     GHashTable *capslatest, ...)
 {
     va_list argptr;
@@ -773,6 +774,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
 
     if (!qemuCaps && capsarch && capsver) {
         bool stripmachinealiases = false;
+        virQEMUCapsPtr cachedcaps = NULL;
 
         info->arch = virArchFromString(capsarch);
 
@@ -784,11 +786,21 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
                                        TEST_QEMU_CAPS_PATH, capsver, capsarch);
         }
 
-        if (!(qemuCaps = qemuTestParseCapabilitiesArch(info->arch, capsfile)))
+        if (!g_hash_table_lookup_extended(capscache, capsfile, NULL, (void **) &cachedcaps)) {
+            if (!(qemuCaps = qemuTestParseCapabilitiesArch(info->arch, capsfile)))
+                goto cleanup;
+
+            if (stripmachinealiases)
+                virQEMUCapsStripMachineAliases(qemuCaps);
+
+            cachedcaps = qemuCaps;
+
+            g_hash_table_insert(capscache, g_strdup(capsfile), g_steal_pointer(&qemuCaps));
+        }
+
+        if (!(qemuCaps = virQEMUCapsNewCopy(cachedcaps)))
             goto cleanup;
 
-        if (stripmachinealiases)
-            virQEMUCapsStripMachineAliases(qemuCaps);
         info->flags |= FLAG_REAL_CAPS;
 
         /* provide path to the replies file for schema testing */
index 86ba69e96b799eeac7fa34ca5c5fa9677f1f6602..e1b386f234f5c14295c0015a47edac73149a3331 100644 (file)
@@ -110,6 +110,7 @@ int testQemuCapsIterate(const char *suffix,
                         void *opaque);
 
 int testQemuInfoSetArgs(struct testQemuInfo *info,
+                        GHashTable *capscache,
                         GHashTable *capslatest, ...);
 void testQemuInfoClear(struct testQemuInfo *info);