+ cpustat = g_new0(GuestCpuStats, 1);
+ cpustat->cpu = atoi(&name[3]);
+ cpustat->has_user = true;
+ cpustat->user = user * 10;
proc(5) says that the value is given "in units of USER_HZ (1/100ths of a second on most architectures, use sysconf(_SC_CLK_TCK) to obtain the right value)", so we should adjust this code if we want to return correctly in ms.
+ cpustat->has_system = true;
+ cpustat->system = system * 10;
+ cpustat->has_idle = true;
+ cpustat->idle = idle * 10;
+
+ /* Linux version >= 2.6 */
That's pretty old now (2003), not sure anyone would care about that comment, but np ;)
+ if (i > 5) {
+ cpustat->has_iowait = true;
+ cpustat->iowait = iowait * 10;
+ cpustat->has_irq = true;
+ cpustat->irq = irq * 10;
+ cpustat->has_softirq = true;
+ cpustat->softirq = softirq * 10;
+ }
+
+ if (i > 8) {
+ cpustat->has_steal = true;
+ cpustat->steal = steal * 10;
+ }
+
+ if (i > 9) {
+ cpustat->has_guest = true;
+ cpustat->guest = guest * 10;
+ }
+
+ QAPI_LIST_APPEND(tail, cpustat);
+ }
+
+ free(line);
+ fclose(fp);
+ return head;
+}
+
#else /* defined(__linux__) */
void qmp_guest_suspend_disk(Error **errp)
@@ -3247,6 +3314,11 @@ GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
return NULL;
}
+GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
+{
+ error_setg(errp, QERR_UNSUPPORTED);
+ return NULL;
+}
#endif /* CONFIG_FSFREEZE */
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 36f94c0f9c..7ed7664715 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2543,3 +2543,9 @@ GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
error_setg(errp, QERR_UNSUPPORTED);
return NULL;
}
+
+GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
+{
+ error_setg(errp, QERR_UNSUPPORTED);
+ return NULL;
+}
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 9fa20e791b..4859c887b2 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1576,3 +1576,52 @@
{ 'command': 'guest-get-diskstats',
'returns': ['GuestDiskStatsInfo']
}
+
+##
+# @GuestCpuStats:
+#
+# Get statistics of each CPU in millisecond.
+#
+# @cpu: CPU index in guest OS
+#
+# @user: CPU time of user mode
"Time spent in user mode." is more understandable (from man proc(5))
Same for the other descriptions.
+#
+# @system: CPU time of system mode
+#
+# @idle: CPU time of idle state
+#
+# @iowait: CPU time waiting IO
+#
+# @irq: CPU time of hardware interrupt
+#
+# @softirq: CPU time of soft interrupt
+#
+# @steal: CPU time stolen by host
+#
+# @guest: CPU time of running guest mode
Why not "guest_nice" ?
Do we expect this struct to be equally meaningful for other OSes? Otherwise, I would suggest to make a "linux" variant, perhaps.