diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-03-19 10:09:59 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-03-19 10:09:59 +0000 |
commit | cb4343bf2efe0bea12f8729e0de8bbaa13f19438 (patch) | |
tree | a15013c79a06b31223b1ad8e6f5a08fd00d8e550 /tools/misc/xenpm.c | |
parent | 7dc1bc818a6a4ba81ec923f0ec07a40199349eed (diff) | |
download | xen-cb4343bf2efe0bea12f8729e0de8bbaa13f19438.tar.gz xen-cb4343bf2efe0bea12f8729e0de8bbaa13f19438.tar.bz2 xen-cb4343bf2efe0bea12f8729e0de8bbaa13f19438.zip |
xenpm: add timeout option to 'xenpm start' command.
Thus we can sample a fixed time of period without manual interruption.
Signed-off-by: Guanqun Lu <guanqun.lu@intel.com>
Diffstat (limited to 'tools/misc/xenpm.c')
-rw-r--r-- | tools/misc/xenpm.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 08e26695f9..6dd4c691fe 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -59,8 +59,8 @@ void show_help(void) " set-up-threshold [cpuid] <num> set up threshold on CPU <cpuid> or all\n" " it is used in ondemand governor.\n" " get-cpu-topology get thread/core/socket topology info\n" - " start start collect Cx/Px statistics,\n" - " output after CTRL-C or SIGINT.\n" + " start [seconds] start collect Cx/Px statistics,\n" + " output after CTRL-C or SIGINT or several seconds.\n" ); } /* wrapper function */ @@ -353,6 +353,16 @@ void start_gather_func(int argc, char *argv[]) { int i; struct timeval tv; + int timeout = 0; + + if ( argc == 1 ) + { + sscanf(argv[0], "%d", &timeout); + if ( timeout <= 0 ) + fprintf(stderr, "failed to set timeout seconds, falling back...\n"); + else + printf("Timeout set to %d seconds\n", timeout); + } if ( gettimeofday(&tv, NULL) == -1 ) { @@ -408,7 +418,21 @@ void start_gather_func(int argc, char *argv[]) free(cxstat); return ; } - printf("Start sampling, waiting for CTRL-C or SIGINT signal ...\n"); + + if ( timeout > 0 ) + { + if ( signal(SIGALRM, signal_int_handler) == SIG_ERR ) + { + fprintf(stderr, "failed to set signal alarm handler\n"); + free(sum); + free(pxstat); + free(cxstat); + return ; + } + alarm(timeout); + } + + printf("Start sampling, waiting for CTRL-C or SIGINT or SIGALARM signal ...\n"); pause(); } |