.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}
};
int ncpus, maxcpu;
size_t cpumaplen;
bool ret = false;
+ bool pretty = vshCommandOptBool(cmd, "pretty");
int n, m;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
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))
#include <libxml/xmlsave.h>
#include "internal.h"
+#include "virbitmap.h"
#include "virbuffer.h"
#include "viralloc.h"
#include "virsh-domain.h"
{.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);
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;
},
{.name = "nodecpumap",
.handler = cmdNodeCpuMap,
- .opts = NULL,
+ .opts = opts_node_cpumap,
.info = info_node_cpumap,
.flags = 0
},
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.
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>]]