[PATCH v3] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.

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

 



From: Bing Bu Cao <mars@xxxxxxxxxxxxxxxxxx>

To retrieve node cpu statistics on Linux system, the
linuxNodeGetCPUstats function simply uses STRPREFIX() to match the
cpuid with the cpuid read from /proc/stat, it will cause
obvious error.

For example:
'virsh nodecpustats 1' will display stats of cpu1* if the latter is online and cpu1 is offline.

This patch fixes this bug.

Signed-off-by: Bing Bu Cao <mars@xxxxxxxxxxxxxxxxxx>
---
 src/nodeinfo.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 05bc038..cf6d29b 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -691,7 +691,7 @@ linuxNodeGetCPUStats(FILE *procstat,
     char line[1024];
     unsigned long long usr, ni, sys, idle, iowait;
     unsigned long long irq, softirq, steal, guest, guest_nice;
-    char cpu_header[3 + INT_BUFSIZE_BOUND(cpuNum)];
+    char cpu_header[4 + INT_BUFSIZE_BOUND(cpuNum)];
 
     if ((*nparams) == 0) {
         /* Current number of cpu stats supported by linux */
@@ -708,9 +708,9 @@ linuxNodeGetCPUStats(FILE *procstat,
     }
 
     if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
-        strcpy(cpu_header, "cpu");
+        strcpy(cpu_header, "cpu ");
     } else {
-        snprintf(cpu_header, sizeof(cpu_header), "cpu%d", cpuNum);
+        snprintf(cpu_header, sizeof(cpu_header), "cpu%d ", cpuNum);
     }
 
     while (fgets(line, sizeof(line), procstat) != NULL) {
-- 
1.7.7.6

--
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]