From a3173fef9dde49d7577e283109281e43d399b3a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Thu, 5 Jun 2014 13:16:00 +0200 Subject: [PATCH] Implement pretty flag for vcpuinfo and nodecpumap 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 | 21 +++++++++++++++++++-- tools/virsh-host.c | 25 ++++++++++++++++++++++--- tools/virsh.pod | 8 ++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e85c9068d0..4f45ed1fcf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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)) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index cac6086e9b..8091437d3b 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -32,6 +32,7 @@ #include #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 }, diff --git a/tools/virsh.pod b/tools/virsh.pod index 02671b4f8c..80501f98a3 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -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 +=item B [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 [I] [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 I +=item B I [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 I [I] [I] [[I<--live>] [I<--config>] | [I<--current>]] -- 2.39.5