From: Keir Fraser Date: Thu, 19 Mar 2009 10:09:59 +0000 (+0000) Subject: xenpm: add timeout option to 'xenpm start' command. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13992^2~32 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=cb4343bf2efe0bea12f8729e0de8bbaa13f19438;p=xen.git 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 --- 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] set up threshold on CPU 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(); }