ia64/xen-unstable

changeset 19399:cbdc022b0035

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>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 19 10:09:59 2009 +0000 (2009-03-19)
parents fe949f9129b0
children 4616acf91797
files tools/misc/xenpm.c
line diff
     1.1 --- a/tools/misc/xenpm.c	Thu Mar 19 10:09:24 2009 +0000
     1.2 +++ b/tools/misc/xenpm.c	Thu Mar 19 10:09:59 2009 +0000
     1.3 @@ -59,8 +59,8 @@ void show_help(void)
     1.4              " set-up-threshold      [cpuid] <num> set up threshold on CPU <cpuid> or all\n"
     1.5              "                                     it is used in ondemand governor.\n"
     1.6              " get-cpu-topology                    get thread/core/socket topology info\n"
     1.7 -            " start                               start collect Cx/Px statistics,\n"
     1.8 -            "                                     output after CTRL-C or SIGINT.\n"
     1.9 +            " start [seconds]                     start collect Cx/Px statistics,\n"
    1.10 +            "                                     output after CTRL-C or SIGINT or several seconds.\n"
    1.11              );
    1.12  }
    1.13  /* wrapper function */
    1.14 @@ -353,6 +353,16 @@ void start_gather_func(int argc, char *a
    1.15  {
    1.16      int i;
    1.17      struct timeval tv;
    1.18 +    int timeout = 0;
    1.19 +
    1.20 +    if ( argc == 1 )
    1.21 +    {
    1.22 +        sscanf(argv[0], "%d", &timeout);
    1.23 +        if ( timeout <= 0 )
    1.24 +            fprintf(stderr, "failed to set timeout seconds, falling back...\n");
    1.25 +        else
    1.26 +            printf("Timeout set to %d seconds\n", timeout);
    1.27 +    }
    1.28  
    1.29      if ( gettimeofday(&tv, NULL) == -1 )
    1.30      {
    1.31 @@ -408,7 +418,21 @@ void start_gather_func(int argc, char *a
    1.32          free(cxstat);
    1.33          return ;
    1.34      }
    1.35 -    printf("Start sampling, waiting for CTRL-C or SIGINT signal ...\n");
    1.36 +
    1.37 +    if ( timeout > 0 )
    1.38 +    {
    1.39 +        if ( signal(SIGALRM, signal_int_handler) == SIG_ERR )
    1.40 +        {
    1.41 +            fprintf(stderr, "failed to set signal alarm handler\n");
    1.42 +            free(sum);
    1.43 +            free(pxstat);
    1.44 +            free(cxstat);
    1.45 +            return ;
    1.46 +        }
    1.47 +        alarm(timeout);
    1.48 +    }
    1.49 +
    1.50 +    printf("Start sampling, waiting for CTRL-C or SIGINT or SIGALARM signal ...\n");
    1.51  
    1.52      pause();
    1.53  }