diff mbox series

[WIP,11/16] WIP: tools/xl: Replace most of list_domains with use of format()

Message ID 6d58dc4f945abebfab21d46cd52940e984eb8ae6.1608663694.git.ehem+xen@m5p.com (mailing list archive)
State New, archived
Headers show
Series Addition of formatting options to `xl list` subcommands | expand

Commit Message

Elliott Mitchell Dec. 12, 2020, 6:18 a.m. UTC
With a generalized formatting function now available, start to replace
the old specialized formatting bits.

Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
 tools/xl/xl_list.c | 40 ++++++++++------------------------------
 1 file changed, 10 insertions(+), 30 deletions(-)
diff mbox series

Patch

diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index c79b5e041b..10d076864e 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -369,16 +369,18 @@  static void list_domains(bool verbose, bool context, bool claim, bool numa,
                          bool cpupool, const libxl_dominfo *info, int nb_domain)
 {
     int i;
-    static const char shutdown_reason_letters[]= "-rscwS";
+    const char lead[] = "%-40n %5i %5m %5v     %s  %8.1t";
+
     libxl_bitmap nodemap;
     libxl_physinfo physinfo;
 
     libxl_bitmap_init(&nodemap);
     libxl_physinfo_init(&physinfo);
 
-    printf("Name                                        ID   Mem VCPUs\tState\tTime(s)");
-    if (verbose) printf("   UUID                            Reason-Code\tSecurity Label");
-    if (context && !verbose) printf("   Security Label");
+    format(formats, lead, NULL);
+    if (verbose) {
+        format(formats, " %u %r %16l", NULL);
+    } else if (context) format(formats, " %16l", NULL);
     if (claim) printf("  Claimed");
     if (cpupool) printf("         Cpupool");
     if (numa) {
@@ -396,35 +398,13 @@  static void list_domains(bool verbose, bool context, bool claim, bool numa,
     }
     printf("\n");
     for (i = 0; i < nb_domain; i++) {
-        char *domname;
-        libxl_shutdown_reason shutdown_reason;
-        domname = libxl_domid_to_name(ctx, info[i].domid);
-        shutdown_reason = info[i].shutdown ? info[i].shutdown_reason : 0;
-        printf("%-40s %5d %5lu %5d     %c%c%c%c%c%c  %8.1f",
-                domname,
-                info[i].domid,
-                (unsigned long) ((info[i].current_memkb +
-                    info[i].outstanding_memkb)/ 1024),
-                info[i].vcpu_online,
-                info[i].running ? 'r' : '-',
-                info[i].blocked ? 'b' : '-',
-                info[i].paused ? 'p' : '-',
-                info[i].shutdown ? 's' : '-',
-                (shutdown_reason >= 0 &&
-                 shutdown_reason < sizeof(shutdown_reason_letters)-1
-                 ? shutdown_reason_letters[shutdown_reason] : '?'),
-                info[i].dying ? 'd' : '-',
-                ((float)info[i].cpu_time / 1e9));
-        free(domname);
-        if (verbose) {
-            printf(" " LIBXL_UUID_FMT, LIBXL_UUID_BYTES(info[i].uuid));
-            if (info[i].shutdown) printf(" %8x", shutdown_reason);
-            else printf(" %8s", "-");
-        }
+        format(formats, lead, info + i);
+        if (verbose)
+            format(formats, " %u %r", info + i);
         if (claim)
             printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024);
         if (verbose || context)
-            printf(" %16s", info[i].ssid_label ? : "-");
+            format(formats, " %16l", info + i);
         if (cpupool) {
             char *poolname = libxl_cpupoolid_to_name(ctx, info[i].cpupool);
             printf("%16s", poolname);