Refactoring qemuDomainGetStatsCpu, make it possible to add
more CPU statistics.
Signed-off-by: Wang Huaqiang <huaqiang.wang(a)intel.com>
---
src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 23 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b238309..9cc6910 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19708,30 +19708,29 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
unsigned long long sys_time = 0;
int err = 0;
- if (!priv->cgroup)
- return 0;
-
- err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
- if (!err && virTypedParamsAddULLong(&record->params,
- &record->nparams,
- maxparams,
- "cpu.time",
- cpu_time) < 0)
- return -1;
+ if (priv->cgroup) {
+ err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
+ if (!err && virTypedParamsAddULLong(&record->params,
+ &record->nparams,
+ maxparams,
+ "cpu.time",
+ cpu_time) < 0)
+ return -1;
- err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
- if (!err && virTypedParamsAddULLong(&record->params,
- &record->nparams,
- maxparams,
- "cpu.user",
- user_time) < 0)
- return -1;
- if (!err && virTypedParamsAddULLong(&record->params,
- &record->nparams,
- maxparams,
- "cpu.system",
- sys_time) < 0)
- return -1;
+ err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
+ if (!err && virTypedParamsAddULLong(&record->params,
+ &record->nparams,
+ maxparams,
+ "cpu.user",
+ user_time) < 0)
+ return -1;
+ if (!err && virTypedParamsAddULLong(&record->params,
+ &record->nparams,
+ maxparams,
+ "cpu.system",
+ sys_time) < 0)
+ return -1;
+ }
return 0;
}
--
2.7.4