]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
* src/cgroup.c src/cgroup.h src/lxc_driver.c: allows to get
authorDaniel Veillard <veillard@redhat.com>
Fri, 6 Mar 2009 14:44:04 +0000 (14:44 +0000)
committerDaniel Veillard <veillard@redhat.com>
Fri, 6 Mar 2009 14:44:04 +0000 (14:44 +0000)
  CPU usage of a lxc using cpuacct subsystem of cgroups, patch
  by Ryota Ozaki
Daniel

ChangeLog
src/cgroup.c
src/cgroup.h
src/lxc_driver.c

index f06074e3256937f2847e82506d6cb72af5b1695c..94f1cad0226f9970f7e42ef87ea97e7233fc5673 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
index 8bd6e87309fc5ce971f81cd8ecfcf762007931ff..5af44bd93ee73602302473d999b3990a11fc0fca 100644 (file)
@@ -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);
+}
index db68bace76ab4bf4009db3b80b98e7c1cf8a2ff2..11c44f98e87816c50c35fca932c0f21687d56ece 100644 (file)
@@ -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);
index dff05b67a1cf1b8119ad2594f1b726666e65909b..c08ca9cdef29cdcc14c27db1303607e4f751d691 100644 (file)
@@ -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;