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@xxxxxxxxxxxxx> --- 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.
Attachment:
signature.asc
Description: PGP signature