[RFC PATCH 5/6] qemu_driver: add the vCPU stats by KVM to the current stats

Martin Kletzander mkletzan at redhat.com
Wed Oct 19 14:02:02 UTC 2022


On Wed, Sep 07, 2022 at 04:04:22PM +0530, Amneesh Singh wrote:
>This patch adds the stats queried by qemuMonitorQueryStats for vCPU and
>add them according to their QOM device path
>
>Signed-off-by: Amneesh Singh <natto at weirdnatto.in>
>---
> src/qemu/qemu_driver.c | 86 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 86 insertions(+)
>
>diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>index ea7d74806c..79146b6bb8 100644
>--- a/src/qemu/qemu_driver.c
>+++ b/src/qemu/qemu_driver.c
>@@ -17966,6 +17966,68 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_GNUC_UNUSED,
> }
>
>
>+static void
>+qemuDomainAddStatsFromHashTable(GHashTable *stats,
>+                                GHashTable *schema,
>+                                const char *prefix,
>+                                virTypedParamList *params)
>+{
>+    GHashTableIter iter;
>+    virJSONValue *value;
>+    char *key;

This is "const" char* since there is no need to free it and we don't
really want to modify it anyway.

>+
>+    if (!stats || !schema)
>+        return;
>+
>+    g_hash_table_iter_init(&iter, stats);
>+
>+    while (g_hash_table_iter_next(&iter, (gpointer *)&key, (gpointer *)&value)) {
>+        qemuMonitorQueryStatsSchemaData *data = g_hash_table_lookup(schema, key);
>+        const char *type = NULL;
>+
>+        if (!data)
>+            continue;
>+
>+        switch (data->type) {
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_CUMULATIVE:
>+            type = "sum";
>+            break;
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_INSTANT:
>+            type = "cur";
>+            break;
>+
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_PEAK:
>+            type = "max";
>+            break;
>+
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_LOG2_HISTOGRAM:
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_LINEAR_HISTOGRAM:
>+        case QEMU_MONITOR_QUERY_STATS_TYPE_LAST:
>+        default:

By omitting this default branch we get a free check from the compiler
that all the possible types are represented in the switch.

[...]

>@@ -18007,7 +18071,21 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED,
>         goto cleanup;
>     }
>
>+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_STATS) &&

This function already checks for the capability, but as noted in the
previous patch we could make it behave differently and this usage in
particular could benefit from such change to make this condition.

>+        !qemuDomainRefreshStatsSchema(dom) &&
>+        HAVE_JOB(privflags)) {

This could call qemuDomainRefreshStatsSchema even without a job and
that's not what we want here since it enters the monitor *and* can
possibly change data in dom->privateData.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20221019/c9b21a20/attachment.sig>


More information about the libvir-list mailing list