mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
* src/cgroup.c src/cgroup.h src/lxc_driver.c: allows to get
CPU usage of a lxc using cpuacct subsystem of cgroups, patch by Ryota Ozaki Daniel
This commit is contained in:
parent
e43d1ae0c6
commit
7f39e2e5e5
@ -1,3 +1,9 @@
|
||||
Fri Mar 6 15:42:46 CET 2009 Daniel Veillard <veilard@redhat.com>
|
||||
|
||||
* src/cgroup.c src/cgroup.h src/lxc_driver.c: allows to get
|
||||
CPU usage of a lxc using cpuacct subsystem of cgroups, patch
|
||||
by Ryota Ozaki
|
||||
|
||||
Wed Mar 4 14:11:15 CET 2009 Daniel Veillard <veilard@redhat.com>
|
||||
|
||||
* NEWS configure.in libvirt.spec.in doc/* include/libvirt/libvirt.h:
|
||||
|
@ -38,6 +38,7 @@ struct virCgroup {
|
||||
const char *supported_controllers[] = {
|
||||
"memory",
|
||||
"devices",
|
||||
"cpuacct",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -797,3 +798,8 @@ int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares)
|
||||
{
|
||||
return virCgroupGetValueU64(group, "cpu.shares", (uint64_t *)shares);
|
||||
}
|
||||
|
||||
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage)
|
||||
{
|
||||
return virCgroupGetValueU64(group, "cpuacct.usage", (uint64_t *)usage);
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ int virCgroupAllowDeviceMajor(virCgroupPtr group,
|
||||
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long shares);
|
||||
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares);
|
||||
|
||||
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
|
||||
|
||||
int virCgroupRemove(virCgroupPtr group);
|
||||
|
||||
void virCgroupFree(virCgroupPtr *group);
|
||||
|
@ -362,6 +362,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
||||
{
|
||||
lxc_driver_t *driver = dom->conn->privateData;
|
||||
virDomainObjPtr vm;
|
||||
virCgroupPtr cgroup = NULL;
|
||||
int ret = -1;
|
||||
|
||||
lxcDriverLock(driver);
|
||||
@ -376,10 +377,19 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
||||
|
||||
info->state = vm->state;
|
||||
|
||||
if (!virDomainIsActive(vm)) {
|
||||
if (!virDomainIsActive(vm) || virCgroupHaveSupport() != 0) {
|
||||
info->cpuTime = 0;
|
||||
} else {
|
||||
info->cpuTime = 0;
|
||||
if (virCgroupForDomain(vm->def, "lxc", &cgroup) != 0) {
|
||||
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to get cgroup for %s\n"), vm->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virCgroupGetCpuacctUsage(cgroup, &(info->cpuTime)) < 0) {
|
||||
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, ("cannot read cputime for domain"));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
info->maxMem = vm->def->maxmem;
|
||||
@ -388,6 +398,8 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
if (cgroup)
|
||||
virCgroupFree(&cgroup);
|
||||
if (vm)
|
||||
virDomainObjUnlock(vm);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user