|
|
9119d9 |
From 8d1fbc8b00507f0874106b40fe9b72f4779ba7de Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <8d1fbc8b00507f0874106b40fe9b72f4779ba7de@dist-git>
|
|
|
9119d9 |
From: Francesco Romani <fromani@redhat.com>
|
|
|
9119d9 |
Date: Wed, 1 Oct 2014 11:20:12 +0200
|
|
|
9119d9 |
Subject: [PATCH] qemu: bulk stats: implement CPU stats group
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1113116
|
|
|
9119d9 |
|
|
|
9119d9 |
This patch implements the VIR_DOMAIN_STATS_CPU_TOTAL group of
|
|
|
9119d9 |
statistics.
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Francesco Romani <fromani@redhat.com>
|
|
|
9119d9 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit 9ebbb8699eab6f9115b8ecbe171ee687a5dee198)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
include/libvirt/libvirt.h.in | 1 +
|
|
|
9119d9 |
src/libvirt.c | 8 ++++++++
|
|
|
9119d9 |
src/qemu/qemu_driver.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9119d9 |
3 files changed, 53 insertions(+)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
index 972bdfa..349ae93 100644
|
|
|
9119d9 |
--- a/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
+++ b/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
@@ -2514,6 +2514,7 @@ struct _virDomainStatsRecord {
|
|
|
9119d9 |
|
|
|
9119d9 |
typedef enum {
|
|
|
9119d9 |
VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
|
|
|
9119d9 |
+ VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
|
|
|
9119d9 |
} virDomainStatsTypes;
|
|
|
9119d9 |
|
|
|
9119d9 |
typedef enum {
|
|
|
9119d9 |
diff --git a/src/libvirt.c b/src/libvirt.c
|
|
|
9119d9 |
index d0fdf11..70644bc 100644
|
|
|
9119d9 |
--- a/src/libvirt.c
|
|
|
9119d9 |
+++ b/src/libvirt.c
|
|
|
9119d9 |
@@ -21555,6 +21555,14 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
|
|
|
9119d9 |
* "state.reason" - reason for entering given state, returned as int from
|
|
|
9119d9 |
* virDomain*Reason enum corresponding to given state.
|
|
|
9119d9 |
*
|
|
|
9119d9 |
+ * VIR_DOMAIN_STATS_CPU_TOTAL: Return CPU statistics and usage information.
|
|
|
9119d9 |
+ * The typed parameter keys are in this format:
|
|
|
9119d9 |
+ * "cpu.time" - total cpu time spent for this domain in nanoseconds
|
|
|
9119d9 |
+ * as unsigned long long.
|
|
|
9119d9 |
+ * "cpu.user" - user cpu time spent in nanoseconds as unsigned long long.
|
|
|
9119d9 |
+ * "cpu.system" - system cpu time spent in nanoseconds as unsigned long long.
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
* Using 0 for @stats returns all stats groups supported by the given
|
|
|
9119d9 |
* hypervisor.
|
|
|
9119d9 |
*
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
index 1d94330..ea06a0d 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_driver.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
@@ -96,6 +96,7 @@
|
|
|
9119d9 |
#include "storage/storage_driver.h"
|
|
|
9119d9 |
#include "virhostdev.h"
|
|
|
9119d9 |
#include "domain_capabilities.h"
|
|
|
9119d9 |
+#include "vircgroup.h"
|
|
|
9119d9 |
|
|
|
9119d9 |
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -17445,6 +17446,48 @@ typedef enum {
|
|
|
9119d9 |
#define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB)
|
|
|
9119d9 |
|
|
|
9119d9 |
|
|
|
9119d9 |
+static int
|
|
|
9119d9 |
+qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
+ virDomainObjPtr dom,
|
|
|
9119d9 |
+ virDomainStatsRecordPtr record,
|
|
|
9119d9 |
+ int *maxparams,
|
|
|
9119d9 |
+ unsigned int privflags ATTRIBUTE_UNUSED)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ qemuDomainObjPrivatePtr priv = dom->privateData;
|
|
|
9119d9 |
+ unsigned long long cpu_time = 0;
|
|
|
9119d9 |
+ unsigned long long user_time = 0;
|
|
|
9119d9 |
+ unsigned long long sys_time = 0;
|
|
|
9119d9 |
+ int err = 0;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (!priv->cgroup)
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
|
|
|
9119d9 |
+ if (!err && virTypedParamsAddULLong(&record->params,
|
|
|
9119d9 |
+ &record->nparams,
|
|
|
9119d9 |
+ maxparams,
|
|
|
9119d9 |
+ "cpu.time",
|
|
|
9119d9 |
+ cpu_time) < 0)
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
|
|
|
9119d9 |
+ if (!err && virTypedParamsAddULLong(&record->params,
|
|
|
9119d9 |
+ &record->nparams,
|
|
|
9119d9 |
+ maxparams,
|
|
|
9119d9 |
+ "cpu.user",
|
|
|
9119d9 |
+ user_time) < 0)
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+ if (!err && virTypedParamsAddULLong(&record->params,
|
|
|
9119d9 |
+ &record->nparams,
|
|
|
9119d9 |
+ maxparams,
|
|
|
9119d9 |
+ "cpu.system",
|
|
|
9119d9 |
+ sys_time) < 0)
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+
|
|
|
9119d9 |
typedef int
|
|
|
9119d9 |
(*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
|
|
|
9119d9 |
virDomainObjPtr dom,
|
|
|
9119d9 |
@@ -17460,6 +17503,7 @@ struct qemuDomainGetStatsWorker {
|
|
|
9119d9 |
|
|
|
9119d9 |
static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
|
|
|
9119d9 |
{ qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false },
|
|
|
9119d9 |
+ { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, false },
|
|
|
9119d9 |
{ NULL, 0, false }
|
|
|
9119d9 |
};
|
|
|
9119d9 |
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.2
|
|
|
9119d9 |
|