Message ID | 20210210175118.19709-8-dwagner@suse.de |
---|---|
State | New |
Headers | show |
Series | Generate machine-readable output | expand |
On Wed, 10 Feb 2021, Daniel Wagner wrote: > Write the test results as JSON output to a file. This allows to > simplifies any parsing later on. > > Signed-off-by: Daniel Wagner <dwagner@suse.de> > --- > src/pmqtest/pmqtest.c | 137 +++++++++++++++++++++++++++++++++++------- > 1 file changed, 114 insertions(+), 23 deletions(-) > > diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c > index 349b47741003..e1f59836ea07 100644 > --- a/src/pmqtest/pmqtest.c > +++ b/src/pmqtest/pmqtest.c > @@ -22,6 +22,7 @@ > #include <utmpx.h> > #include <mqueue.h> > #include <pthread.h> > +#include <inttypes.h> > > #include "rt-utils.h" > #include "rt-get_cpu.h" > @@ -231,6 +232,7 @@ static void display_help(int error) > "-h --help print this help message\n" > "-i INTV --interval=INTV base interval of thread in us default=1000\n" > "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" > + " --output=FILENAME write final results into FILENAME, JSON formatted\n" > "-p PRIO --prio=PRIO priority\n" > "-q --quiet print a summary only on exit\n" > "-S --smp SMP testing: options -a -t and same priority\n" > @@ -258,6 +260,14 @@ static int sameprio; > static int timeout; > static int forcetimeout; > static int quiet; > +static char outfile[MAX_PATH]; > + > +enum option_value { > + OPT_AFFINITY=1, OPT_BREAKTRACE, OPT_DISTANCE, OPT_DURATION, > + OPT_FORCETIMEOUT, OPT_HELP, OPT_INTERVAL, OPT_LOOPS, > + OPT_OUTPUT, OPT_PRIORITY, OPT_QUIET, OPT_SMP, OPT_THREADS, > + OPT_TIMEOUT > +}; > > static void process_options(int argc, char *argv[]) > { > @@ -268,19 +278,20 @@ static void process_options(int argc, char *argv[]) > int option_index = 0; > /** Options for getopt */ > static struct option long_options[] = { > - {"affinity", optional_argument, NULL, 'a'}, > - {"breaktrace", required_argument, NULL, 'b'}, > - {"distance", required_argument, NULL, 'd'}, > - {"duration", required_argument, NULL, 'D'}, > - {"forcetimeout", required_argument, NULL, 'f'}, > - {"help", no_argument, NULL, 'h'}, > - {"interval", required_argument, NULL, 'i'}, > - {"loops", required_argument, NULL, 'l'}, > - {"priority", required_argument, NULL, 'p'}, > - {"quiet", no_argument, NULL, 'q'}, > - {"smp", no_argument, NULL, 'S'}, > - {"threads", optional_argument, NULL, 't'}, > - {"timeout", required_argument, NULL, 'T'}, > + {"affinity", optional_argument, NULL, OPT_AFFINITY}, > + {"breaktrace", required_argument, NULL, OPT_BREAKTRACE}, > + {"distance", required_argument, NULL, OPT_DISTANCE}, > + {"duration", required_argument, NULL, OPT_DURATION}, > + {"forcetimeout",required_argument, NULL, OPT_FORCETIMEOUT}, > + {"help", no_argument, NULL, OPT_HELP}, > + {"interval", required_argument, NULL, OPT_INTERVAL}, > + {"loops", required_argument, NULL, OPT_LOOPS}, > + {"output", required_argument, NULL, OPT_OUTPUT }, > + {"priority", required_argument, NULL, OPT_PRIORITY}, > + {"quiet", no_argument, NULL, OPT_QUIET}, > + {"smp", no_argument, NULL, OPT_SMP}, > + {"threads", optional_argument, NULL, OPT_THREADS}, > + {"timeout", required_argument, NULL, OPT_TIMEOUT}, > {NULL, 0, NULL, 0} > }; > int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:qSt::T:", > @@ -288,6 +299,7 @@ static void process_options(int argc, char *argv[]) > if (c == -1) > break; > switch (c) { > + case OPT_AFFINITY: > case 'a': > if (smp) { > warn("-a ignored due to --smp\n"); > @@ -303,21 +315,53 @@ static void process_options(int argc, char *argv[]) > setaffinity = AFFINITY_USEALL; > } > break; > - case 'b': tracelimit = atoi(optarg); break; > - case 'd': distance = atoi(optarg); break; > - case 'D': duration = parse_time_string(optarg); break; > - case 'f': forcetimeout = atoi(optarg); break; > + case OPT_BREAKTRACE: > + case 'b': > + tracelimit = atoi(optarg); > + break; > + case OPT_DISTANCE: > + case 'd': > + distance = atoi(optarg); > + break; > + case OPT_DURATION: > + case 'D': > + duration = parse_time_string(optarg); > + break; > + case OPT_FORCETIMEOUT: > + case 'f': > + forcetimeout = atoi(optarg); > + break; > + case OPT_HELP: > case '?': > - case 'h': display_help(0); break; > - case 'i': interval = atoi(optarg); break; > - case 'l': max_cycles = atoi(optarg); break; > - case 'p': priority = atoi(optarg); break; > - case 'q': quiet = 1; break; > + case 'h': > + display_help(0); > + break; > + case OPT_INTERVAL: > + case 'i': > + interval = atoi(optarg); > + break; > + case OPT_LOOPS: > + case 'l': > + max_cycles = atoi(optarg); > + break; > + case OPT_OUTPUT: > + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); > + break; > + case OPT_PRIORITY: > + case 'p': > + priority = atoi(optarg); > + break; > + case OPT_QUIET: > + case 'q': > + quiet = 1; > + break; > + case OPT_SMP: > case 'S': > smp = 1; > num_threads = max_cpus; > setaffinity = AFFINITY_USEALL; > break; > + case OPT_THREADS: > case 't': > if (smp) { > warn("-t ignored due to --smp\n"); > @@ -330,7 +374,10 @@ static void process_options(int argc, char *argv[]) > else > num_threads = max_cpus; > break; > - case 'T': timeout = atoi(optarg); break; > + case OPT_TIMEOUT: > + case 'T': > + timeout = atoi(optarg); > + break; > default: > display_help(1); > break; > @@ -401,6 +448,42 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender, > } > } > > +struct params_stats { > + struct params *receiver; > + struct params *sender; > +}; > + > +static void write_stats(FILE *f, void *data) > +{ > + struct params_stats *ps = data; > + struct params *s, *r; > + unsigned int i; > + > + fprintf(f, " \"num_threads\": %d,\n", num_threads); > + fprintf(f, " \"thread\": {\n"); > + for (i = 0; i < num_threads; i++) { > + s = &ps->sender[i]; > + r = &ps->receiver[i]; > + fprintf(f, " \"%u\": {\n", i); > + fprintf(f, " \"sender\": {\n"); > + fprintf(f, " \"cpu\": %d,\n", s->cpu); > + fprintf(f, " \"priority\": %d,\n", s->priority); > + fprintf(f, " \"samples\": %d,\n", s->samples); > + fprintf(f, " \"interval\": %ld\n", r->delay.tv_nsec/1000); > + fprintf(f, " },\n"); > + fprintf(f, " \"receiver\": {\n"); > + fprintf(f, " \"cpu\": %d,\n", r->cpu); > + fprintf(f, " \"priority\": %d,\n", r->priority); > + fprintf(f, " \"timeoutcount\": %d,\n", r->timeoutcount); > + fprintf(f, " \"min\": %d,\n", r->mindiff); > + fprintf(f, " \"avg\": %.2f,\n", r->sumdiff/r->samples); > + fprintf(f, " \"max\": %d\n", r->maxdiff); > + fprintf(f, " }\n"); > + fprintf(f, " }%s\n", i == num_threads - 1 ? "" : ","); > + } > + fprintf(f, " }\n"); > +} > + > int main(int argc, char *argv[]) > { > int i; > @@ -562,6 +645,14 @@ int main(int argc, char *argv[]) > mq_unlink(mqname); > } > > + if (strlen(outfile) != 0) { > + struct params_stats ps = { > + .receiver = receiver, > + .sender = sender, > + }; > + rt_write_json(outfile, argc, argv, write_stats, &ps); > + } > + > nomem: > > return 0; > -- > 2.30.0 > > Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c index 349b47741003..e1f59836ea07 100644 --- a/src/pmqtest/pmqtest.c +++ b/src/pmqtest/pmqtest.c @@ -22,6 +22,7 @@ #include <utmpx.h> #include <mqueue.h> #include <pthread.h> +#include <inttypes.h> #include "rt-utils.h" #include "rt-get_cpu.h" @@ -231,6 +232,7 @@ static void display_help(int error) "-h --help print this help message\n" "-i INTV --interval=INTV base interval of thread in us default=1000\n" "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" + " --output=FILENAME write final results into FILENAME, JSON formatted\n" "-p PRIO --prio=PRIO priority\n" "-q --quiet print a summary only on exit\n" "-S --smp SMP testing: options -a -t and same priority\n" @@ -258,6 +260,14 @@ static int sameprio; static int timeout; static int forcetimeout; static int quiet; +static char outfile[MAX_PATH]; + +enum option_value { + OPT_AFFINITY=1, OPT_BREAKTRACE, OPT_DISTANCE, OPT_DURATION, + OPT_FORCETIMEOUT, OPT_HELP, OPT_INTERVAL, OPT_LOOPS, + OPT_OUTPUT, OPT_PRIORITY, OPT_QUIET, OPT_SMP, OPT_THREADS, + OPT_TIMEOUT +}; static void process_options(int argc, char *argv[]) { @@ -268,19 +278,20 @@ static void process_options(int argc, char *argv[]) int option_index = 0; /** Options for getopt */ static struct option long_options[] = { - {"affinity", optional_argument, NULL, 'a'}, - {"breaktrace", required_argument, NULL, 'b'}, - {"distance", required_argument, NULL, 'd'}, - {"duration", required_argument, NULL, 'D'}, - {"forcetimeout", required_argument, NULL, 'f'}, - {"help", no_argument, NULL, 'h'}, - {"interval", required_argument, NULL, 'i'}, - {"loops", required_argument, NULL, 'l'}, - {"priority", required_argument, NULL, 'p'}, - {"quiet", no_argument, NULL, 'q'}, - {"smp", no_argument, NULL, 'S'}, - {"threads", optional_argument, NULL, 't'}, - {"timeout", required_argument, NULL, 'T'}, + {"affinity", optional_argument, NULL, OPT_AFFINITY}, + {"breaktrace", required_argument, NULL, OPT_BREAKTRACE}, + {"distance", required_argument, NULL, OPT_DISTANCE}, + {"duration", required_argument, NULL, OPT_DURATION}, + {"forcetimeout",required_argument, NULL, OPT_FORCETIMEOUT}, + {"help", no_argument, NULL, OPT_HELP}, + {"interval", required_argument, NULL, OPT_INTERVAL}, + {"loops", required_argument, NULL, OPT_LOOPS}, + {"output", required_argument, NULL, OPT_OUTPUT }, + {"priority", required_argument, NULL, OPT_PRIORITY}, + {"quiet", no_argument, NULL, OPT_QUIET}, + {"smp", no_argument, NULL, OPT_SMP}, + {"threads", optional_argument, NULL, OPT_THREADS}, + {"timeout", required_argument, NULL, OPT_TIMEOUT}, {NULL, 0, NULL, 0} }; int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:qSt::T:", @@ -288,6 +299,7 @@ static void process_options(int argc, char *argv[]) if (c == -1) break; switch (c) { + case OPT_AFFINITY: case 'a': if (smp) { warn("-a ignored due to --smp\n"); @@ -303,21 +315,53 @@ static void process_options(int argc, char *argv[]) setaffinity = AFFINITY_USEALL; } break; - case 'b': tracelimit = atoi(optarg); break; - case 'd': distance = atoi(optarg); break; - case 'D': duration = parse_time_string(optarg); break; - case 'f': forcetimeout = atoi(optarg); break; + case OPT_BREAKTRACE: + case 'b': + tracelimit = atoi(optarg); + break; + case OPT_DISTANCE: + case 'd': + distance = atoi(optarg); + break; + case OPT_DURATION: + case 'D': + duration = parse_time_string(optarg); + break; + case OPT_FORCETIMEOUT: + case 'f': + forcetimeout = atoi(optarg); + break; + case OPT_HELP: case '?': - case 'h': display_help(0); break; - case 'i': interval = atoi(optarg); break; - case 'l': max_cycles = atoi(optarg); break; - case 'p': priority = atoi(optarg); break; - case 'q': quiet = 1; break; + case 'h': + display_help(0); + break; + case OPT_INTERVAL: + case 'i': + interval = atoi(optarg); + break; + case OPT_LOOPS: + case 'l': + max_cycles = atoi(optarg); + break; + case OPT_OUTPUT: + strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1)); + break; + case OPT_PRIORITY: + case 'p': + priority = atoi(optarg); + break; + case OPT_QUIET: + case 'q': + quiet = 1; + break; + case OPT_SMP: case 'S': smp = 1; num_threads = max_cpus; setaffinity = AFFINITY_USEALL; break; + case OPT_THREADS: case 't': if (smp) { warn("-t ignored due to --smp\n"); @@ -330,7 +374,10 @@ static void process_options(int argc, char *argv[]) else num_threads = max_cpus; break; - case 'T': timeout = atoi(optarg); break; + case OPT_TIMEOUT: + case 'T': + timeout = atoi(optarg); + break; default: display_help(1); break; @@ -401,6 +448,42 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender, } } +struct params_stats { + struct params *receiver; + struct params *sender; +}; + +static void write_stats(FILE *f, void *data) +{ + struct params_stats *ps = data; + struct params *s, *r; + unsigned int i; + + fprintf(f, " \"num_threads\": %d,\n", num_threads); + fprintf(f, " \"thread\": {\n"); + for (i = 0; i < num_threads; i++) { + s = &ps->sender[i]; + r = &ps->receiver[i]; + fprintf(f, " \"%u\": {\n", i); + fprintf(f, " \"sender\": {\n"); + fprintf(f, " \"cpu\": %d,\n", s->cpu); + fprintf(f, " \"priority\": %d,\n", s->priority); + fprintf(f, " \"samples\": %d,\n", s->samples); + fprintf(f, " \"interval\": %ld\n", r->delay.tv_nsec/1000); + fprintf(f, " },\n"); + fprintf(f, " \"receiver\": {\n"); + fprintf(f, " \"cpu\": %d,\n", r->cpu); + fprintf(f, " \"priority\": %d,\n", r->priority); + fprintf(f, " \"timeoutcount\": %d,\n", r->timeoutcount); + fprintf(f, " \"min\": %d,\n", r->mindiff); + fprintf(f, " \"avg\": %.2f,\n", r->sumdiff/r->samples); + fprintf(f, " \"max\": %d\n", r->maxdiff); + fprintf(f, " }\n"); + fprintf(f, " }%s\n", i == num_threads - 1 ? "" : ","); + } + fprintf(f, " }\n"); +} + int main(int argc, char *argv[]) { int i; @@ -562,6 +645,14 @@ int main(int argc, char *argv[]) mq_unlink(mqname); } + if (strlen(outfile) != 0) { + struct params_stats ps = { + .receiver = receiver, + .sender = sender, + }; + rt_write_json(outfile, argc, argv, write_stats, &ps); + } + nomem: return 0;
Write the test results as JSON output to a file. This allows to simplifies any parsing later on. Signed-off-by: Daniel Wagner <dwagner@suse.de> --- src/pmqtest/pmqtest.c | 137 +++++++++++++++++++++++++++++++++++------- 1 file changed, 114 insertions(+), 23 deletions(-)