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

[Xen-changelog] [xen-unstable] [XENTOP] Adds batch mode processing option (output to stdout)



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID e5cf18c05e8b438d5d543fe664aa83bf2c4e70c5
# Parent  3c09a6b27b14ce537555bc533e3022fadf32e7d7
[XENTOP] Adds batch mode processing option (output to stdout)
to the xentop utility. It also adds the ability to specify the
number of iterations xentop should produce before exiting.

a) xentop -b

will output to stdout.

b) xentop -i <number>

will iterate <number> times and exit (option "n" is already used by
xentop. Hence the choice of "i"). This option can be used for both the
curses and batch modes.

From: Hariprasad Nellitheertha <mlisthari@xxxxxxxxx>
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/xenstat/xentop/xentop.1 |    9 ++++
 tools/xenstat/xentop/xentop.c |   83 +++++++++++++++++++++++++++++-------------
 2 files changed, 67 insertions(+), 25 deletions(-)

diff -r 3c09a6b27b14 -r e5cf18c05e8b tools/xenstat/xentop/xentop.1
--- a/tools/xenstat/xentop/xentop.1     Wed Jun 28 10:03:24 2006 +0100
+++ b/tools/xenstat/xentop/xentop.1     Wed Jun 28 10:22:13 2006 +0100
@@ -25,6 +25,8 @@
 [\fB\-n\fR]
 [\fB\-r\fR]
 [\fB\-v\fR]
+[\fB\-b\fR]
+[\fB\-i\fRITERATIONS]
 
 .SH DESCRIPTION
 \fBxentop\fR displays information about the Xen system and domains, in a
@@ -50,6 +52,13 @@ repeat table header before each domain
 .TP
 \fB\-v\fR, \fB\-\-vcpus\fR
 output VCPU data
+.TP
+\fB\-b\fR, \fB\-\-batch\fR
+output data in batch mode (to stdout)
+.TP
+\fB\-i\fR, \fB\-\-iterations\fR=\fIITERATIONS\fR
+maximum number of iterations xentop should produce before ending
+
 
 .SH "INTERACTIVE COMMANDS"
 All interactive commands are case-insensitive.
diff -r 3c09a6b27b14 -r e5cf18c05e8b tools/xenstat/xentop/xentop.c
--- a/tools/xenstat/xentop/xentop.c     Wed Jun 28 10:03:24 2006 +0100
+++ b/tools/xenstat/xentop/xentop.c     Wed Jun 28 10:22:13 2006 +0100
@@ -153,6 +153,9 @@ field_id sort_field = FIELD_DOMID;
 field_id sort_field = FIELD_DOMID;
 unsigned int first_domain_index = 0;
 unsigned int delay = 3;
+unsigned int batch = 0;
+unsigned int loop = 1;
+unsigned int iterations = 0;
 int show_vcpus = 0;
 int show_networks = 0;
 int repeat_header = 0;
@@ -179,6 +182,8 @@ static void usage(const char *program)
               "-n, --networks       output vif network 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"
+              "-i, --iterations     number of iterations before exiting\n"
               "\n" XENTOP_BUGSTO,
               program);
        return;
@@ -236,9 +241,15 @@ static void print(const char *fmt, ...)
 {
        va_list args;
 
-       if(current_row() < lines()-1) {
+       if (!batch) {
+               if((current_row() < lines()-1)) {
+                       va_start(args, fmt);
+                       vw_printw(stdscr, fmt, args);
+                       va_end(args);
+               }
+       } else {
                va_start(args, fmt);
-               vw_printw(stdscr, fmt, args);
+               vprintf(fmt, args);
                va_end(args);
        }
 }
@@ -803,6 +814,7 @@ static void top(void)
                        do_network(domains[i]);
        }
 
+       if(!batch)
        do_bottom_line();
 }
 
@@ -818,9 +830,11 @@ 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' },
                { 0, 0, 0, 0 },
        };
-       const char *sopts = "hVbnvd:";
+       const char *sopts = "hVbnvd:bi:";
 
        if (atexit(cleanup) != 0)
                fail("Failed to install cleanup handler.\n");
@@ -847,6 +861,13 @@ int main(int argc, char **argv)
                case 'd':
                        delay = atoi(optarg);
                        break;
+               case 'b':
+                       batch = 1;
+                       break;
+               case 'i':
+                       iterations = atoi(optarg);
+                       loop = 0;
+                       break;
                }
        }
 
@@ -855,28 +876,40 @@ int main(int argc, char **argv)
        if (xhandle == NULL)
                fail("Failed to initialize xenstat library\n");
 
-       /* Begin curses stuff */
-       initscr();
-       start_color();
-       cbreak();
-       noecho();
-       nonl();
-       keypad(stdscr, TRUE);
-       halfdelay(5);
-       use_default_colors();
-       init_pair(1, -1, COLOR_YELLOW);
-
-       do {
-               gettimeofday(&curtime, NULL);
-               if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= delay) {
-                       clear();
-                       top();
-                       oldtime = curtime;
-                       refresh();
-               }
-               ch = getch();
-       } while (handle_key(ch));
-
+       if (!batch) {
+               /* Begin curses stuff */
+               initscr();
+               start_color();
+               cbreak();
+               noecho();
+               nonl();
+               keypad(stdscr, TRUE);
+               halfdelay(5);
+               use_default_colors();
+               init_pair(1, -1, COLOR_YELLOW);
+
+               do {
+                       gettimeofday(&curtime, NULL);
+                       if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= 
delay) {
+                               clear();
+                               top();
+                               oldtime = curtime;
+                               refresh();
+                               if ((!loop) && !(--iterations))
+                                       break;
+                       }
+                       ch = getch();
+               } while (handle_key(ch));
+       } else {
+                       do {
+                               gettimeofday(&curtime, NULL);
+                               top();
+                               sleep(delay);
+                               if ((!loop) && !(--iterations))
+                                       break;
+                       } while (1);
+       }
+       
        /* Cleanup occurs in cleanup(), so no work to do here. */
 
        return 0;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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