[PATCH 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/qemu/qemu_driver.c       | 72 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 78eb9b8..86ef18b 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/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9825f61..527a6b4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17429,6 +17429,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,
@@ -17445,6 +17516,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]