mirror of https://gitee.com/openkylin/libvirt.git
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> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
1f4831ee6e
commit
9ebbb8699e
|
@ -2513,6 +2513,7 @@ struct _virDomainStatsRecord {
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
|
VIR_DOMAIN_STATS_STATE = (1 << 0), /* return domain state */
|
||||||
|
VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
|
||||||
} virDomainStatsTypes;
|
} virDomainStatsTypes;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -21596,6 +21596,14 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
|
||||||
* "state.reason" - reason for entering given state, returned as int from
|
* "state.reason" - reason for entering given state, returned as int from
|
||||||
* virDomain*Reason enum corresponding to given state.
|
* virDomain*Reason enum corresponding to given state.
|
||||||
*
|
*
|
||||||
|
* VIR_DOMAIN_STATS_CPU_TOTAL: Return CPU statistics and usage information.
|
||||||
|
* The typed parameter keys are in this format:
|
||||||
|
* "cpu.time" - total cpu time spent for this domain in nanoseconds
|
||||||
|
* as unsigned long long.
|
||||||
|
* "cpu.user" - user cpu time spent in nanoseconds as unsigned long long.
|
||||||
|
* "cpu.system" - system cpu time spent in nanoseconds as unsigned long long.
|
||||||
|
*
|
||||||
|
*
|
||||||
* Using 0 for @stats returns all stats groups supported by the given
|
* Using 0 for @stats returns all stats groups supported by the given
|
||||||
* hypervisor.
|
* hypervisor.
|
||||||
*
|
*
|
||||||
|
|
|
@ -96,6 +96,7 @@
|
||||||
#include "storage/storage_driver.h"
|
#include "storage/storage_driver.h"
|
||||||
#include "virhostdev.h"
|
#include "virhostdev.h"
|
||||||
#include "domain_capabilities.h"
|
#include "domain_capabilities.h"
|
||||||
|
#include "vircgroup.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
|
@ -17406,6 +17407,48 @@ typedef enum {
|
||||||
#define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB)
|
#define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB)
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainGetStatsCpu(virQEMUDriverPtr driver 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 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
(*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
|
(*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr dom,
|
virDomainObjPtr dom,
|
||||||
|
@ -17421,6 +17464,7 @@ struct qemuDomainGetStatsWorker {
|
||||||
|
|
||||||
static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
|
static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
|
||||||
{ qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false },
|
{ qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false },
|
||||||
|
{ qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, false },
|
||||||
{ NULL, 0, false }
|
{ NULL, 0, false }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue