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

[Xen-devel] [PATCH] Adds options for tabs-separators, and including the domain ID in the output.



This change adds two options to xentop:
        -T      adds a tabulator (\t) character after each field, to allow
                easier and more robust parsing. This affects batch mode only.
        -I      includes a column with the domain ID in the output (both the
                graphical output, and the batch output)

This makes the output easier to parse for automated tools.
If none of the options are passed, the output is unchanged, so none of them
would break existing tools.

Signed-off-by: Stefan Wieser <swieser@xxxxxxxxxx>
---
 tools/xenstat/xentop/xentop.c | 88 +++++++++++++++++++++++++++++++++----------
 1 file changed, 68 insertions(+), 20 deletions(-)

diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c
index 2fd2b67..d0e379e 100644
--- a/tools/xenstat/xentop/xentop.c
+++ b/tools/xenstat/xentop/xentop.c
@@ -114,6 +114,8 @@ static int compare_ssid(xenstat_domain *domain1, 
xenstat_domain *domain2);
 static void print_ssid(xenstat_domain *domain);
 static int compare_name(xenstat_domain *domain1, xenstat_domain *domain2);
 static void print_name(xenstat_domain *domain);
+static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2);
+static void print_domid(xenstat_domain *domain);
 static int compare_vbds(xenstat_domain *domain1, xenstat_domain *domain2);
 static void print_vbds(xenstat_domain *domain);
 static int compare_vbd_oo(xenstat_domain *domain1, xenstat_domain *domain2);
@@ -172,6 +174,7 @@ typedef struct field {
 } field;
 
 field fields[] = {
+       { FIELD_DOMID,     "DOMID",      6, compare_domid,     print_domid   },
        { FIELD_NAME,      "NAME",      10, compare_name,      print_name    },
        { FIELD_STATE,     "STATE",      6, compare_state,     print_state   },
        { FIELD_CPU,       "CPU(sec)",  10, compare_cpu,       print_cpu     },
@@ -206,12 +209,14 @@ unsigned int delay = 3;
 unsigned int batch = 0;
 unsigned int loop = 1;
 unsigned int iterations = 0;
+int use_tabs = 0;
 int show_vcpus = 0;
 int show_networks = 0;
 int show_vbds = 0;
 int show_tmem = 0;
 int repeat_header = 0;
 int show_full_name = 0;
+int include_domid = 0;
 #define PROMPT_VAL_LEN 80
 char *prompt = NULL;
 char prompt_val[PROMPT_VAL_LEN];
@@ -238,9 +243,11 @@ static void usage(const char *program)
               "-x, --vbds           output vbd block device data\n"
               "-r, --repeat-header  repeat table header before each domain\n"
               "-v, --vcpus          output vcpu data\n"
-              "-b, --batch          output in batch mode, no user input 
accepted\n"
+              "-b, --batch          output in batch mode, no user input 
accepted\n"
               "-i, --iterations     number of iterations before exiting\n"
               "-f, --full-name      output the full domain name (not 
truncated)\n"
+              "-I, --include-domid  includes the domain ID column\n"
+              "-T, --tabs           use tabs as a field-separator in batch 
mode\n"
               "\n" XENTOP_BUGSTO,
               program);
        return;
@@ -549,6 +556,19 @@ static void print_mem(xenstat_domain *domain)
        print("%10llu", xenstat_domain_cur_mem(domain)/1024);
 }
 
+/* Compares cpu usage of two domains, returning -1,0,1 for <,=,> */
+static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2)
+{
+        return -compare(xenstat_domain_id(domain1),
+                        xenstat_domain_id(domain2));
+}
+
+/* Prints domain cpu usage in seconds */
+static void print_domid(xenstat_domain *domain)
+{
+        print("%6u", xenstat_domain_id(domain));
+}
+
 /* Prints memory percentage statistic, ratio of current domain memory to total
  * node memory */
 static void print_mem_pct(xenstat_domain *domain)
@@ -914,12 +934,16 @@ void do_summary(void)
 void do_header(void)
 {
        field_id i;
+       int fields_shown = 0;
 
        /* Turn on REVERSE highlight attribute for headings */
        xentop_attron(A_REVERSE);
-       for(i = 0; i < NUM_FIELDS; i++) {
-               if (i != 0)
-                       print(" ");
+       for(i = 0; i < NUM_FIELDS; i++, fields_shown++) {
+               /* Skip the domain ID field if it wasn't requested. */
+               if (i == FIELD_DOMID && !include_domid)
+                       continue;
+               if (fields_shown)
+                       print("%c", use_tabs ? '\t' : ' ');
                /* The BOLD attribute is turned on for the sort column */
                if (i == sort_field)
                        xentop_attron(A_BOLD);
@@ -978,17 +1002,22 @@ void do_bottom_line(void)
 /* Prints Domain information */
 void do_domain(xenstat_domain *domain)
 {
-       unsigned int i;
-       for (i = 0; i < NUM_FIELDS; i++) {
-               if (i != 0)
-                       print(" ");
+       field_id i;
+       int fields_shown = 0;
+
+       for (i = 0; i < NUM_FIELDS; i++, fields_shown++) {
+               /* Skip the domain ID field if it wasn't requested. */
+               if (i == FIELD_DOMID && !include_domid)
+                       continue;
+               if (fields_shown)
+                       print(use_tabs ? "\t" : " ");
                if (i == sort_field)
                        xentop_attron(A_BOLD);
                fields[i].print(domain);
                if (i == sort_field)
                        xentop_attroff(A_BOLD);
        }
-       print("\n");
+       print("%c", use_tabs ? '\t' : '\n');
 }
 
 /* Output all vcpu information */
@@ -1007,13 +1036,13 @@ void do_vcpu(xenstat_domain *domain)
                vcpu = xenstat_domain_vcpu(domain,i);
 
                if (xenstat_vcpu_online(vcpu) > 0) {
-                       if (i != 0 && (i%5)==0)
+                       if (i != 0 && (i%5)==0 && !use_tabs)
                                print("\n        ");
                        print(" %2u: %10llus", i, 
                                        xenstat_vcpu_ns(vcpu)/1000000000);
                }
        }
-       print("\n");
+       print(use_tabs ? "\t" : "\n");
 }
 
 /* Output all network information */
@@ -1038,11 +1067,12 @@ void do_network(xenstat_domain *domain)
                      xenstat_network_rerrs(network),
                      xenstat_network_rdrop(network));
 
-               print("TX: %8llubytes %8llupkts %8lluerr %8lludrop\n",
+               print("TX: %8llubytes %8llupkts %8lluerr %8lludrop%c",
                      xenstat_network_tbytes(network),
                      xenstat_network_tpackets(network),
                      xenstat_network_terrs(network),
-                     xenstat_network_tdrop(network));
+                     xenstat_network_tdrop(network),
+                     use_tabs ? '\t' : '\n');
        }
 }
 
@@ -1075,14 +1105,15 @@ void do_vbd(xenstat_domain *domain)
                         MINOR(xenstat_vbd_dev(vbd)));
 #endif
 
-               print("VBD %s %4d %s OO: %8llu   RD: %8llu   WR: %8llu   RSECT: 
%10llu   WSECT: %10llu\n",
+               print("VBD %s %4d %s OO: %8llu   RD: %8llu   WR: %8llu   RSECT: 
%10llu   WSECT: %10llu%c",
                      vbd_type[xenstat_vbd_type(vbd)],
                      xenstat_vbd_dev(vbd), details,
                      xenstat_vbd_oo_reqs(vbd),
                      xenstat_vbd_rd_reqs(vbd),
                      xenstat_vbd_wr_reqs(vbd),
                      xenstat_vbd_rd_sects(vbd),
-                     xenstat_vbd_wr_sects(vbd));
+                     xenstat_vbd_wr_sects(vbd),
+                     use_tabs ? '\t' : '\n');
        }
 }
 
@@ -1097,9 +1128,10 @@ void do_tmem(xenstat_domain *domain)
 
        if (curr_eph_pages | succ_eph_gets | succ_pers_puts | succ_pers_gets)
                print("Tmem:  Curr eph pages: %8llu   Succ eph gets: %8llu   "
-                     "Succ pers puts: %8llu   Succ pers gets: %8llu\n",
+                     "Succ pers puts: %8llu   Succ pers gets: %8llu%c",
                        curr_eph_pages, succ_eph_gets,
-                       succ_pers_puts, succ_pers_gets);
+                       succ_pers_puts, succ_pers_gets,
+                       use_tabs ? '\t' : '\n');
 
 }
 
@@ -1157,6 +1189,10 @@ static void top(void)
                        do_vbd(domains[i]);
                if (show_tmem)
                        do_tmem(domains[i]);
+
+               /* If we were told to separate with tabs, add a new-line once 
the domain is done. */
+               if (use_tabs)
+                       printf("\n");
        }
 
        if (!batch)
@@ -1185,12 +1221,14 @@ int main(int argc, char **argv)
                { "repeat-header", no_argument,       NULL, 'r' },
                { "vcpus",         no_argument,       NULL, 'v' },
                { "delay",         required_argument, NULL, 'd' },
-               { "batch",         no_argument,       NULL, 'b' },
-               { "iterations",    required_argument, NULL, 'i' },
+               { "batch",         no_argument,       NULL, 'b' },
+               { "iterations",    required_argument, NULL, 'i' },
                { "full-name",     no_argument,       NULL, 'f' },
+               { "tabs",          no_argument,       NULL, 'T' },
+               { "include-domid", no_argument,       NULL, 'I' },
                { 0, 0, 0, 0 },
        };
-       const char *sopts = "hVnxrvd:bi:f";
+       const char *sopts = "hVnxrvd:bi:fTI";
 
        if (atexit(cleanup) != 0)
                fail("Failed to install cleanup handler.\n");
@@ -1219,6 +1257,12 @@ int main(int argc, char **argv)
                case 'v':
                        show_vcpus = 1;
                        break;
+               case 'T':
+                       use_tabs = 1;
+                       break;
+               case 'I':
+                       include_domid = 1;
+                       break;
                case 'd':
                        delay = atoi(optarg);
                        break;
@@ -1238,6 +1282,10 @@ int main(int argc, char **argv)
                }
        }
 
+       if (use_tabs && !batch) {
+               fail("Cannot use tabs in interactive mode.\n");
+       }
+
        /* Get xenstat handle */
        xhandle = xenstat_init();
        if (xhandle == NULL)
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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