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

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



With a generalized formatting function now available, start to replace
the old specialized formatting bits.

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

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);
-- 


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         ehem+sigmsg@xxxxxxx  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445






 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.