mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +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>
|
Wed Mar 4 14:11:15 CET 2009 Daniel Veillard <veilard@redhat.com>
|
||||||
|
|
||||||
* NEWS configure.in libvirt.spec.in doc/* include/libvirt/libvirt.h:
|
* NEWS configure.in libvirt.spec.in doc/* include/libvirt/libvirt.h:
|
||||||
|
@ -38,6 +38,7 @@ struct virCgroup {
|
|||||||
const char *supported_controllers[] = {
|
const char *supported_controllers[] = {
|
||||||
"memory",
|
"memory",
|
||||||
"devices",
|
"devices",
|
||||||
|
"cpuacct",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -797,3 +798,8 @@ int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares)
|
|||||||
{
|
{
|
||||||
return virCgroupGetValueU64(group, "cpu.shares", (uint64_t *)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 virCgroupSetCpuShares(virCgroupPtr group, unsigned long shares);
|
||||||
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares);
|
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares);
|
||||||
|
|
||||||
|
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
|
||||||
|
|
||||||
int virCgroupRemove(virCgroupPtr group);
|
int virCgroupRemove(virCgroupPtr group);
|
||||||
|
|
||||||
void virCgroupFree(virCgroupPtr *group);
|
void virCgroupFree(virCgroupPtr *group);
|
||||||
|
@ -362,6 +362,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
|||||||
{
|
{
|
||||||
lxc_driver_t *driver = dom->conn->privateData;
|
lxc_driver_t *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virCgroupPtr cgroup = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
lxcDriverLock(driver);
|
lxcDriverLock(driver);
|
||||||
@ -376,10 +377,19 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
|||||||
|
|
||||||
info->state = vm->state;
|
info->state = vm->state;
|
||||||
|
|
||||||
if (!virDomainIsActive(vm)) {
|
if (!virDomainIsActive(vm) || virCgroupHaveSupport() != 0) {
|
||||||
info->cpuTime = 0;
|
info->cpuTime = 0;
|
||||||
} else {
|
} 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;
|
info->maxMem = vm->def->maxmem;
|
||||||
@ -388,6 +398,8 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (cgroup)
|
||||||
|
virCgroupFree(&cgroup);
|
||||||
if (vm)
|
if (vm)
|
||||||
virDomainObjUnlock(vm);
|
virDomainObjUnlock(vm);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user