This method is responsible to fetch all CPU Cgroup Stats and store data into virDomainStatsRecordPtr structure. Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx> --- src/lxc/lxc_driver.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index be26cf18a4..0e6d5743d0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5299,6 +5299,53 @@ lxcDomainGetStatsState(virDomainObjPtr dom, } +static int +lxcDomainGetStatsCpu(virDomainObjPtr dom, + virDomainStatsRecordPtr record, + int *maxparams, + unsigned int supported) +{ + virLXCDomainObjPrivatePtr priv = dom->privateData; + unsigned long long cpu_time = 0; + unsigned long long user_time = 0; + unsigned long long sys_time = 0; + unsigned int flags = VIR_DOMAIN_STATS_CPU_TOTAL; + int err = 0; + + virCheckFlags(supported, 0); + + if (virDomainObjCheckActive(dom) < 0) + return 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; + + 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; +} + + static virDomainStatsRecordPtr lxcDomainGetStats(virConnectPtr conn, virDomainObjPtr dom, @@ -5320,6 +5367,9 @@ lxcDomainGetStats(virConnectPtr conn, if (lxcDomainGetStatsState(dom, stat, &maxparams, flags) < 0) goto endjob; + if (lxcDomainGetStatsCpu(dom, stat, &maxparams, flags) < 0) + goto endjob; + virLXCDomainObjEndJob(driver, dom); return stat; -- 2.19.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list