xentrace, xenmon: make them work on Solaris and *BSD
PATCH 1/1 xentrace, xenmon: make them work on Solaris and *BSD
Hi!
Attached patch makes xentrace and xenmon work on Solaris and *BSD. Patch applies against changeset 16371.
- Use getopt() to get rid of argp dependency which does not exist on Solaris and *BSD. Done by Tariq Magdon-Ismail.
- Minor modifications by me (Christoph) to make it also work on *BSD.
- Tested on Linux by me (Christoph). No functional change on Linux.
- Tariq ok'd BSD modifications for Solaris
- Tariq ok'd submission by me :)
Signed-off-by Tariq Magdon-Ismail <[email protected]>
Signed-off-by Christoph Egger <[email protected]>
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
tools/xenmon/xenbaked.c +101 -96
@@ -37,12 +37,12 @@#include <fcntl.h> #include <unistd.h> #include <errno.h> -#include <argp.h> #include <signal.h> #include <xenctrl.h> #include <xen/xen.h> #include <string.h> #include <sys/select.h> +#include <getopt.h> #define PERROR(_m, _a...) \ do { \
@@ -58,7 +58,6 @@ typedef struct { int counter; } atomic_t#include <xen/trace.h> #include "xenbaked.h" -extern FILE *stderr;/***** Compile time configuration of defaults ********************************/
@@ -78,7 +77,6 @@ extern FILE *stderr;/***** The code **************************************************************/ typedef struct settings_st { - char *outfile; struct timespec poll_sleep; unsigned long new_data_thresh; unsigned long ms_per_sample;
@@ -230,10 +228,10 @@ void dump_stats(void) }printf ("processed %d total records in %d seconds (%ld per second)\n" , - rec_count, (int )run_time, rec_count/run_time); + rec_count, (int )run_time, (long )(rec_count/run_time));printf ("woke up %d times in %d seconds (%ld per second)\n" , wakeups, - (int ) run_time, wakeups/run_time); + (int ) run_time, (long )(wakeups/run_time));check_gotten_sum (); }
@@ -535,58 +533,106 @@ int monitor_tbufs(void)/****************************************************************************** -* Various declarations / definitions GNU argp needs to do its work +* Command line handling *****************************************************************************/ - -/* command parser for GNU argp - see GNU docs for more info */ -error_t cmd_parser (int key,char *arg,struct argp_state *state) -{ -settings_t *setup = (settings_t *)state->input; - -switch ( key ) +const char *program_version ="xenbaked v1.4" ; +const char *program_bug_address ="<[email protected]>" ; + +#define xstr (x) str(x) +#define str (x) #x + +void usage (void ) +{ +#define USAGE_STR \ +"Usage: xenbaked [OPTION...]\n" \ +"Tool to capture and partially process Xen trace buffer data\n" \ +"\n" \ +" -m, --ms_per_sample=MS Specify the number of milliseconds per sample\n" \ +" (default " xstr(MS_PER_SAMPLE) ").\n" \ +" -s, --poll-sleep=p Set sleep time, p, in milliseconds between\n" \ +" polling the trace buffer for new data\n" \ +" (default " xstr(POLL_SLEEP_MILLIS) ").\n" \ +" -t, --log-thresh=l Set number, l, of new records required to\n" \ +" trigger a write to output (default " \ + xstr(NEW_DATA_THRESH) ").\n" \ +" -?, --help Show this message\n" \ +" -V, --version Print program version\n" \ +"\n" \ +"This tool is used to capture trace buffer data from Xen. The data is\n" \ +"saved in a shared memory structure to be further processed by xenmon.\n" + +printf (USAGE_STR ); +printf ("\nReport bugs to %s\n" , program_bug_address); + +exit (EXIT_FAILURE ); +} + +/* convert the argument string pointed to by arg to a long int representation */ +long argtol (const char *restrict arg,int base) +{ +char *endp; +long val; + + errno =0 ; + val =strtol (arg, &endp, base); + +if (errno !=0 ) { +fprintf (stderr,"Invalid option argument: %s\n" , arg); +fprintf (stderr,"Error: %s\n\n" ,strerror (errno)); +usage (); + }else if (endp == arg || *endp !='\0' ) { +fprintf (stderr,"Invalid option argument: %s\n\n" , arg); +usage (); + } + +return val; +} + +/* parse command line arguments */ +void parse_args (int argc,char **argv) +{ +int option; +static struct option long_options[] = { + {"log-thresh" , required_argument,0 ,'t' }, + {"poll-sleep" , required_argument,0 ,'s' }, + {"ms_per_sample" , required_argument,0 ,'m' }, + {"help" , no_argument,0 ,'?' }, + {"version" , no_argument,0 ,'V' }, + {0 ,0 ,0 ,0 } + }; + +while ( (option =getopt_long (argc, argv,"m:s:t:?V" , + long_options,NULL )) !=-1 ) { -case 't' :/* set new records threshold for logging */ - { -char *inval; - setup->new_data_thresh =strtol (arg, &inval,0 ); -if ( inval == arg ) -argp_usage (state); - } -break ; - -case 's' :/* set sleep time (given in milliseconds) */ - { -char *inval; - setup->poll_sleep =millis_to_timespec (strtol (arg, &inval,0 )); -if ( inval == arg ) -argp_usage (state); - } -break ; - -case 'm' :/* set ms_per_sample */ - { -char *inval; - setup->ms_per_sample =strtol (arg, &inval,0 ); -if ( inval == arg ) -argp_usage (state); - } -break ; - -case ARGP_KEY_ARG : - { -if ( state->arg_num ==0 ) - setup->outfile = arg; -else -argp_usage (state); - } -break ; - -default : -return ARGP_ERR_UNKNOWN ; - } - -return 0 ; +switch ( option ) + { +case 't' :/* set new records threshold for logging */ + opts.new_data_thresh =argtol (optarg,0 ); +break ; + +case 's' :/* set sleep time (given in milliseconds) */ + opts.poll_sleep =millis_to_timespec (argtol (optarg,0 )); +break ; + +case 'm' :/* set ms_per_sample */ + opts.ms_per_sample =argtol (optarg,0 ); +break ; + +case 'V' :/* print program version */ +printf ("%s\n" , program_version); +exit (EXIT_SUCCESS ); +break ; + +default : +usage (); + } + } + +/* all arguments should have been processed */ +if (optind != argc) { +usage (); + } }#define SHARED_MEM_FILE "/var/run/xenq-shm"
@@ -637,59 +683,18 @@ void alloc_qos_data(int ncpu) } -#define xstr (x) str(x) -#define str (x) #x - -const struct argp_option cmd_opts[] = -{ - { .name ="log-thresh" , .key='t' , .arg="l" , - .doc = - "Set number, l, of new records required to trigger a write to output " - "(default " xstr(NEW_DATA_THRESH) ")." }, - - { .name ="poll-sleep" , .key='s' , .arg="p" , - .doc = - "Set sleep time, p, in milliseconds between polling the trace buffer " - "for new data (default " xstr(POLL_SLEEP_MILLIS) ")." }, - - { .name ="ms_per_sample" , .key='m' , .arg="MS" , - .doc = - "Specify the number of milliseconds per sample " - " (default " xstr(MS_PER_SAMPLE) ")." }, - - {0 } -}; - -const struct argp parser_def = -{ - .options = cmd_opts, - .parser = cmd_parser, -// .args_doc = "[output file]", - .doc = -"Tool to capture and partially process Xen trace buffer data" -"\v" -"This tool is used to capture trace buffer data from Xen. The data is " -"saved in a shared memory structure to be further processed by xenmon." -}; - - -const char *argp_program_version ="xenbaked v1.4" ; -const char *argp_program_bug_address ="<[email protected]>" ; - -int main (int argc,char **argv) {int ret;struct sigaction act;time (&start_time); - opts.outfile =0 ; opts.poll_sleep =millis_to_timespec (POLL_SLEEP_MILLIS ); opts.new_data_thresh =NEW_DATA_THRESH ; opts.ms_per_sample =MS_PER_SAMPLE ; opts.cpu_freq =CPU_FREQ ; -argp_parse (&parser_def, argc, argv,0 ,0 , &opts); +parse_args (argc, argv);fprintf (stderr,"ms_per_sample = %ld\n" , opts.ms_per_sample);
tools/xentrace/xenctx.c +8 -3
@@ -18,7 +18,6 @@#include <fcntl.h> #include <unistd.h> #include <errno.h> -#include <argp.h> #include <signal.h> #include <string.h> #include <inttypes.h>
@@ -32,10 +31,15 @@ int stack_trace = 0;int stack_trace =0 ;#if defined (__i386__) +#if defined (__OpenBSD__) +#define FMT_SIZE_T "%08lx" +#define INSTR_POINTER (regs) (unsigned long)(regs->eip) +#else #define FMT_SIZE_T "%08x" +#define INSTR_POINTER (regs) (regs->eip) +#endif #define STACK_POINTER (regs) (regs->esp)#define FRAME_POINTER (regs) (regs->ebp) -#define INSTR_POINTER (regs) (regs->eip)#define STACK_ROWS 4#define STACK_COLS 8#elif defined (__x86_64__)
@@ -622,7 +626,8 @@ void print_stack(vcpu_guest_context_t *cprintf ("Stack Trace:\n" ); else printf("Call Trace:\n"); -printf ("%c [<" FMT_SIZE_T ">] " , stack_trace ?'*' :' ' ,INSTR_POINTER (regs)); +printf ("%c [<" FMT_SIZE_T ">] " , + stack_trace ?'*' :' ' ,INSTR_POINTER (regs));print_symbol (INSTR_POINTER (regs));printf (" <--\n" );
tools/xentrace/xentrace.c +138 -150
329 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel