[PATCH v2 39/53] [ACKED] vircgroup: introduce virCgroupV2GetCpuacctUsage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroupv2.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 45af617971..93c1e39119 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1464,6 +1464,37 @@ virCgroupV2SupportsCpuBW(virCgroupPtr cgroup)
 }
 
 
+static int
+virCgroupV2GetCpuacctUsage(virCgroupPtr group,
+                           unsigned long long *usage)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    char *tmp;
+
+    if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
+                             "cpu.stat", &str) < 0) {
+        return -1;
+    }
+
+    if (!(tmp = strstr(str, "usage_usec "))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("cannot parse cpu usage stat '%s'"), str);
+        return -1;
+    }
+    tmp += strlen("usage_usec ");
+
+    if (virStrToLong_ull(tmp, &tmp, 10, usage) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to parse value '%s' as number."), tmp);
+        return -1;
+    }
+
+    *usage *= 1000;
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -1519,6 +1550,8 @@ virCgroupBackend virCgroupV2Backend = {
     .setCpuCfsQuota = virCgroupV2SetCpuCfsQuota,
     .getCpuCfsQuota = virCgroupV2GetCpuCfsQuota,
     .supportsCpuBW = virCgroupV2SupportsCpuBW,
+
+    .getCpuacctUsage = virCgroupV2GetCpuacctUsage,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux