[PATCHv2 08/11] qemu: bulk stats: implement VCPU group

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch implements the VIR_DOMAIN_STATS_VCPU
group of statistics.

Signed-off-by: Francesco Romani <fromani@xxxxxxxxxx>
---
 include/libvirt/libvirt.h.in |  1 +
 src/libvirt.c                |  8 +++++
 src/qemu/qemu_driver.c       | 72 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 7ec57cd..46f4067 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2513,6 +2513,7 @@ typedef enum {
     VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
     VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
     VIR_DOMAIN_STATS_BALLOON = (1 << 2), /* return domain balloon info */
+    VIR_DOMAIN_STATS_VCPU = (1 << 3), /* return domain virtual CPU info */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/libvirt.c b/src/libvirt.c
index 8b0f589..a5942bc 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -21558,6 +21558,14 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "balloon.current" - the memory in KBytes currently used
  * "balloon.maximum" - the maximum memory in KBytes allowed
  *
+ * VIR_DOMAIN_STATS_VCPU: Return virtual CPU statistics.
+ * The typed parameter keys are in this format:
+ * "vcpu.current" - current number of online virtual CPUs
+ * "vcpu.maximum" - maximum number of online virtual CPUs
+ * "vcpu.<num>.state" - state of the virtual CPU <num>
+ * "vcpu.<num>.time" - virtual cpu time spent by virtual CPU <num>
+ * "vcpu.<num>.cpu" - physical CPU pinned to virtual CPU <num>
+ *
  * Using 0 for @stats returns all stats groups supported by the given
  * hypervisor.
  *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 98f1a31..72ec284 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17391,6 +17391,77 @@ qemuDomainGetStatsBalloon(virConnectPtr conn,
     return 0;
 }
 
+
+static int
+qemuDomainGetStatsVcpu(virConnectPtr conn ATTRIBUTE_UNUSED,
+                       virDomainObjPtr dom,
+                       virDomainStatsRecordPtr record,
+                       int *maxparams,
+                       unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    size_t i;
+    int ret = -1;
+    char param_name[NAME_MAX];
+    virVcpuInfoPtr cpuinfo = NULL;
+
+    if (virTypedParamsAddInt(&record->params,
+                             &record->nparams,
+                             maxparams,
+                             "vcpu.current",
+                             dom->def->vcpus) < 0)
+        return -1;
+
+    if (virTypedParamsAddInt(&record->params,
+                             &record->nparams,
+                             maxparams,
+                             "vcpu.maximum",
+                             dom->def->maxvcpus) < 0)
+        return -1;
+
+    if (VIR_ALLOC_N(cpuinfo, dom->def->vcpus) < 0)
+        return -1;
+
+    if ((ret = qemuDomainHelperGetVcpus(dom,
+                                        cpuinfo,
+                                        dom->def->vcpus,
+                                        NULL,
+                                        0)) < 0)
+        goto cleanup;
+
+    for (i = 0; i < dom->def->vcpus; i++) {
+        snprintf(param_name, NAME_MAX, "vcpu.%u.state", cpuinfo[i].number);
+        if (virTypedParamsAddInt(&record->params,
+                                 &record->nparams,
+                                 maxparams,
+                                 param_name,
+                                 cpuinfo[i].state) < 0)
+            goto cleanup;
+
+        snprintf(param_name, NAME_MAX, "vcpu.%u.time", cpuinfo[i].number);
+        if (virTypedParamsAddULLong(&record->params,
+                                    &record->nparams,
+                                    maxparams,
+                                    param_name,
+                                    cpuinfo[i].cpuTime) < 0)
+            goto cleanup;
+
+        snprintf(param_name, NAME_MAX, "vcpu.%u.cpu", cpuinfo[i].number);
+        if (virTypedParamsAddInt(&record->params,
+                                 &record->nparams,
+                                 maxparams,
+                                 param_name,
+                                 cpuinfo[i].cpu) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(cpuinfo);
+    return ret;
+}
+
+
 typedef int
 (*qemuDomainGetStatsFunc)(virConnectPtr conn,
                           virDomainObjPtr dom,
@@ -17407,6 +17478,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE},
     { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL },
     { qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON },
+    { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU },
     { NULL, 0 }
 };
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]