|
Pablo Greco |
40546a |
From d54383e93c3d3a71008d4b3a48b4dafba2368609 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <d54383e93c3d3a71008d4b3a48b4dafba2368609@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Mon, 1 Jul 2019 17:07:51 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] vircgroup: introduce virCgroupV2GetCpuacctStat
|
|
Pablo Greco |
40546a |
MIME-Version: 1.0
|
|
Pablo Greco |
40546a |
Content-Type: text/plain; charset=UTF-8
|
|
Pablo Greco |
40546a |
Content-Transfer-Encoding: 8bit
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
(cherry picked from commit 4d1d5c92bdefc38bc68bde5f9bd2dbd3c11bff2a)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Message-Id: <62365d349154035cfab2115d66430dcf3c7bdd03.1561993100.git.phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
src/util/vircgroupv2.c | 49 ++++++++++++++++++++++++++++++++++++++++++
|
|
Pablo Greco |
40546a |
1 file changed, 49 insertions(+)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
index afa243b3c7..d6362e2b05 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
@@ -1487,6 +1487,54 @@ virCgroupV2GetCpuacctUsage(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+static int
|
|
Pablo Greco |
40546a |
+virCgroupV2GetCpuacctStat(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
+ unsigned long long *user,
|
|
Pablo Greco |
40546a |
+ unsigned long long *sys)
|
|
Pablo Greco |
40546a |
+{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) str = NULL;
|
|
Pablo Greco |
40546a |
+ char *tmp;
|
|
Pablo Greco |
40546a |
+ unsigned long long userVal = 0;
|
|
Pablo Greco |
40546a |
+ unsigned long long sysVal = 0;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
|
|
Pablo Greco |
40546a |
+ "cpu.stat", &str) < 0) {
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!(tmp = strstr(str, "user_usec "))) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("cannot parse cpu user stat '%s'"), str);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ tmp += strlen("user_usec ");
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virStrToLong_ull(tmp, &tmp, 10, &userVal) < 0) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("Failed to parse value '%s' as number."), tmp);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!(tmp = strstr(str, "system_usec "))) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("cannot parse cpu sys stat '%s'"), str);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ tmp += strlen("system_usec ");
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virStrToLong_ull(tmp, &tmp, 10, &sysVal) < 0) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("Failed to parse value '%s' as number."), tmp);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ *user = userVal * 1000;
|
|
Pablo Greco |
40546a |
+ *sys = sysVal * 1000;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ return 0;
|
|
Pablo Greco |
40546a |
+}
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
virCgroupBackend virCgroupV2Backend = {
|
|
Pablo Greco |
40546a |
.type = VIR_CGROUP_BACKEND_TYPE_V2,
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -1544,6 +1592,7 @@ virCgroupBackend virCgroupV2Backend = {
|
|
Pablo Greco |
40546a |
.supportsCpuBW = virCgroupV2SupportsCpuBW,
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
.getCpuacctUsage = virCgroupV2GetCpuacctUsage,
|
|
Pablo Greco |
40546a |
+ .getCpuacctStat = virCgroupV2GetCpuacctStat,
|
|
Pablo Greco |
40546a |
};
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|