提交 7f39e2e5 编写于 作者: D Daniel Veillard

* 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
上级 e43d1ae0
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册