On 11/6/2018 3:27 AM, John Ferlan wrote:
On 10/22/18 4:01 AM, Wang Huaqiang wrote:
> 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(-)
>
Maybe instead of inverting the logic, let's create a cgroup helper...
qemuDomainGetStatsCpuCgroup(dom, record, *maxparams)
{
logic as is now
}
static int
qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams,
unsigned int privflags ATTRIBUTE_UNUSED)
{
return qemuDomainGetStatsCpuCgroup(dom, record, maxparams);
}
Then the subsequent patch would alter the above check and add the new call.
John
Thanks for advice. Will be done in next series.
Huaqiang
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index a52e249..12a5f8f 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -19711,30 +19711,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;
> }
>