]> xenbits.xensource.com Git - libvirt.git/commitdiff
Implement pretty flag for vcpuinfo and nodecpumap
authorJán Tomko <jtomko@redhat.com>
Thu, 5 Jun 2014 11:16:00 +0000 (13:16 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 6 Jun 2014 12:35:19 +0000 (14:35 +0200)
Report CPU affinities / online CPUs in human-readable form when
this flag is present:

Before:
CPU Affinity:   y-yy

After:
CPU Affinity:   0,2-3 (out of 4)

https://bugzilla.redhat.com/show_bug.cgi?id=985980

tools/virsh-domain.c
tools/virsh-host.c
tools/virsh.pod

index e85c9068d07ebd0ed9b2c4263e046094047ff5a8..4f45ed1fcf0d570c890140c84d34b4468a7072d9 100644 (file)
@@ -5528,6 +5528,10 @@ static const vshCmdOptDef opts_vcpuinfo[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("domain name, id or uuid")
     },
+    {.name = "pretty",
+     .type = VSH_OT_BOOL,
+     .help = N_("return human readable output")
+    },
     {.name = NULL}
 };
 
@@ -5541,6 +5545,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
     int ncpus, maxcpu;
     size_t cpumaplen;
     bool ret = false;
+    bool pretty = vshCommandOptBool(cmd, "pretty");
     int n, m;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -5589,8 +5594,20 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
             vshPrint(ctl, "%-15s %s\n", _("CPU time"), _("N/A"));
         }
         vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
-        for (m = 0; m < maxcpu; m++) {
-            vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+        if (pretty) {
+            char *str;
+
+            str = virBitmapDataToString(VIR_GET_CPUMAP(cpumaps, cpumaplen, n),
+                                        cpumaplen);
+            if (!str)
+                goto cleanup;
+            vshPrint(ctl, _("%s (out of %d)"), str, maxcpu);
+            VIR_FREE(str);
+        } else {
+            for (m = 0; m < maxcpu; m++) {
+                vshPrint(ctl, "%c",
+                         VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+            }
         }
         vshPrint(ctl, "\n");
         if (n < (ncpus - 1))
index cac6086e9bdfbd2eadc7ad6ad0fc2f974d906bcd..8091437d3ba154e2b2a6abce806ca6e4db020753 100644 (file)
@@ -32,6 +32,7 @@
 #include <libxml/xmlsave.h>
 
 #include "internal.h"
+#include "virbitmap.h"
 #include "virbuffer.h"
 #include "viralloc.h"
 #include "virsh-domain.h"
@@ -278,12 +279,21 @@ static const vshCmdInfo info_node_cpumap[] = {
     {.name = NULL}
 };
 
+static const vshCmdOptDef opts_node_cpumap[] = {
+    {.name = "pretty",
+     .type = VSH_OT_BOOL,
+     .help = N_("return human readable output")
+    },
+    {.name = NULL}
+};
+
 static bool
 cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     int cpu, cpunum;
     unsigned char *cpumap = NULL;
     unsigned int online;
+    bool pretty = vshCommandOptBool(cmd, "pretty");
     bool ret = false;
 
     cpunum = virNodeGetCPUMap(ctl->conn, &cpumap, &online, 0);
@@ -296,8 +306,17 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     vshPrint(ctl, "%-15s %d\n", _("CPUs online:"), online);
 
     vshPrint(ctl, "%-15s ", _("CPU map:"));
-    for (cpu = 0; cpu < cpunum; cpu++)
-        vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-');
+    if (pretty) {
+        char *str = virBitmapDataToString(cpumap, cpunum);
+
+        if (!str)
+            goto cleanup;
+        vshPrint(ctl, "%s", str);
+        VIR_FREE(str);
+    } else {
+        for (cpu = 0; cpu < cpunum; cpu++)
+            vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-');
+    }
     vshPrint(ctl, "\n");
 
     ret = true;
@@ -978,7 +997,7 @@ const vshCmdDef hostAndHypervisorCmds[] = {
     },
     {.name = "nodecpumap",
      .handler = cmdNodeCpuMap,
-     .opts = NULL,
+     .opts = opts_node_cpumap,
      .info = info_node_cpumap,
      .flags = 0
     },
index 02671b4f8c71cdb81c55fec21fc18e2f2587f4a4..80501f98a3478c9e3d8e8c94b2529edc728c8d31 100644 (file)
@@ -290,11 +290,13 @@ and size of the physical memory. The output corresponds to virNodeInfo
 structure. Specifically, the "CPU socket(s)" field means number of CPU
 sockets per NUMA cell.
 
-=item B<nodecpumap>
+=item B<nodecpumap> [I<--pretty>]
 
 Displays the node's total number of CPUs, the number of online CPUs
 and the list of online CPUs.
 
+With I<--pretty> the online CPUs are printed as a range instead of a list.
+
 =item B<nodecpustats> [I<cpu>] [I<--percent>]
 
 Returns cpu stats of the node.
@@ -1954,11 +1956,13 @@ If I<--guest> is specified, then the count of cpus is reported from
 the perspective of the guest. This flag is usable only for live domains
 and may require guest agent to be configured in the guest.
 
-=item B<vcpuinfo> I<domain>
+=item B<vcpuinfo> I<domain> [I<--pretty>]
 
 Returns basic information about the domain virtual CPUs, like the number of
 vCPUs, the running time, the affinity to physical processors.
 
+With I<--pretty>, cpu affinities are shown as ranges.
+
 =item B<vcpupin> I<domain> [I<vcpu>] [I<cpulist>] [[I<--live>]
 [I<--config>] | [I<--current>]]