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