[PATCHv4 1/2] Add a new param 'vcpu_time' to virDomainGetCPUStats

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

 



Currently virDomainGetCPUStats gets total cpu usage, which consists
of:

  1. vcpu usage: the physical cpu time consumed by virtual cpu(s) of
     domain
  2. hypervisor: `total cpu usage' - `vcpu usage'

The param 'vcpu_time' is for getting vcpu usages.
---
 include/libvirt/libvirt.h.in |    6 ++++++
 tools/virsh.c                |   14 ++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index ac5df95..2449cee 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1355,6 +1355,12 @@ int                     virDomainGetState       (virDomainPtr domain,
  */
 #define VIR_DOMAIN_CPU_STATS_SYSTEMTIME "system_time"
 
+/**
+ * VIR_DOMAIN_CPU_STATS_VCPUTIME:
+ * vcpu usage in nanoseconds, as a ullong
+ */
+#define VIR_DOMAIN_CPU_STATS_VCPUTIME "vcpu_time"
+
 int virDomainGetCPUStats(virDomainPtr domain,
                          virTypedParameterPtr params,
                          unsigned int nparams,
diff --git a/tools/virsh.c b/tools/virsh.c
index dd9292a..b9d05a2 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -5572,6 +5572,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
     virTypedParameterPtr params = NULL;
     int i, j, pos, max_id, cpu = -1, show_count = -1, nparams;
     bool show_total = false, show_per_cpu = false;
+    unsigned int flags = 0;
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         return false;
@@ -5599,13 +5600,13 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
         cpu = 0;
 
     /* get number of cpus on the node */
-    if ((max_id = virDomainGetCPUStats(dom, NULL, 0, 0, 0, 0)) < 0)
+    if ((max_id = virDomainGetCPUStats(dom, NULL, 0, 0, 0, flags)) < 0)
         goto failed_stats;
     if (show_count < 0 || show_count > max_id)
         show_count = max_id;
 
     /* get percpu information */
-    if ((nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0)) < 0)
+    if ((nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, flags)) < 0)
         goto failed_stats;
 
     if (!nparams) {
@@ -5619,7 +5620,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
     while (show_count) {
         int ncpus = MIN(show_count, 128);
 
-        if (virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, 0) < 0)
+        if (virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, flags) < 0)
             goto failed_stats;
 
         for (i = 0; i < ncpus; i++) {
@@ -5630,7 +5631,8 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
             for (j = 0; j < nparams; j++) {
                 pos = i * nparams + j;
                 vshPrint(ctl, "\t%-12s ", params[pos].field);
-                if (STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME) &&
+                if ((STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
+                     STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) &&
                     params[j].type == VIR_TYPED_PARAM_ULLONG) {
                     vshPrint(ctl, "%9lld.%09lld seconds\n",
                              params[pos].value.ul / 1000000000,
@@ -5653,7 +5655,7 @@ do_show_total:
         goto cleanup;
 
     /* get supported num of parameter for total statistics */
-    if ((nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, 0)) < 0)
+    if ((nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, flags)) < 0)
         goto failed_stats;
 
     if (!nparams) {
@@ -5665,7 +5667,7 @@ do_show_total:
         goto failed_params;
 
     /* passing start_cpu == -1 gives us domain's total status */
-    if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, 0)) < 0)
+    if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
         goto failed_stats;
 
     vshPrint(ctl, _("Total:\n"));
-- 
1.7.4.4

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