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

[libvirt] [PATCH 06/11] qemu: bulk stats: implement CPU stats group



This patch implements the VIR_DOMAIN_STATS_CPU_TOTAL
group of statistics.

Signed-off-by: Francesco Romani <fromani redhat com>
---
 include/libvirt/libvirt.h.in |  1 +
 src/qemu/qemu_driver.c       | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 9358314..992b124 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2511,6 +2511,7 @@ struct _virDomainStatsRecord {
 
 typedef enum {
     VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
+    VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d4eda06..7ffd052 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -96,6 +96,7 @@
 #include "storage/storage_driver.h"
 #include "virhostdev.h"
 #include "domain_capabilities.h"
+#include "vircgroup.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -17343,6 +17344,60 @@ qemuDomainGetStatsState(virConnectPtr conn ATTRIBUTE_UNUSED,
     return 0;
 }
 
+
+static int
+qemuDomainGetStatsCpu(virConnectPtr conn ATTRIBUTE_UNUSED,
+                      virDomainObjPtr dom,
+                      virDomainStatsRecordPtr record,
+                      int *maxparams,
+                      unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    qemuDomainObjPrivatePtr priv = dom->privateData;
+    unsigned long long cpu_time = 0;
+    unsigned long long user_time = 0;
+    unsigned long long sys_time = 0;
+    int ncpus = 0;
+
+    ncpus = nodeGetCPUCount();
+
+    if (virTypedParamsAddInt(&record->params,
+                             &record->nparams,
+                             maxparams,
+                             "cpu.count",
+                             ncpus) < 0)
+        return -1;
+
+    if (virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time) < 0)
+        return -1;
+
+    if (virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time) < 0)
+        return -1;
+
+    if (virTypedParamsAddULLong(&record->params,
+                                &record->nparams,
+                                maxparams,
+                                "cpu.time",
+                                cpu_time) < 0)
+        return -1;
+
+    if (virTypedParamsAddULLong(&record->params,
+                                &record->nparams,
+                                maxparams,
+                                "cpu.user",
+                                user_time) < 0)
+        return -1;
+
+    if (virTypedParamsAddULLong(&record->params,
+                                &record->nparams,
+                                maxparams,
+                                "cpu.system",
+                                sys_time) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 typedef int
 (*qemuDomainGetStatsFunc)(virConnectPtr conn,
                           virDomainObjPtr dom,
@@ -17357,6 +17412,7 @@ struct qemuDomainGetStatsWorker {
 
 static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE},
+    { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL },
     { NULL, 0 }
 };
 
-- 
1.9.3


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