Generate machine-readable output
v6 cover Generate machine-readable output
v6:
- signaltest rebased
- sigwaittest rebases
v5:
- add 'realtime' to common header
- add timestamp to common header
- oslat add quiet option
- oslat fix JSON formatting
- rt-migrate fix JSON formatting
v4:
- rebased on top of '[rt-tests v3 00/16] rt-numa.h cleanups' series
- dropped applied patches
- dropped RFC label
v3:
- A number of bug fixes added at the beginning of the series.
- Add --output option to all tests which have a numeric results, not just failed/passed
v2:
- Moved the common JSON parts into rt-util.[ch]
- Add --output option to signaltest
The current output of cyclictest is optimized for humans to read. This is all good when working directly with the tools. But for CI integration it's a bit of pain. Furthermore, not all rt-tests use the same output format.
By using some easy to parse existing machine-readable format we can use standard libraries to parse the data. For example in jitterdebug there is a short Python program[1] to visualize either the histogram[2] or all samples[3].
The implementation for JSON output for this is very simple. The last patch adds a version of jitterdebugs's JSON output, which looks like
{
"file_version": 1,
"version:": "cyclictest V 1.90",
"num_threads": 2,
"resolution_in_ns": 0,
"cmdline:": "./cyclictest --affinity=1-2 --duration=1s --output=dump.json -h 1000 -p 80",
"sysinfo": {
"sysname": "Linux",
"nodename": "beryllium",
"release": "5.9.14-1-default",
"version": "#1 SMP Sat Dec 12 06:57:32 UTC 2020 (c648a46)",
"machine": "x86_64"
},
"thread": {
"0": {
"histogram": {
"0": 16,
"1": 853,
"2": 80,
"3": 50,
"4": 1
},
"cycles": 1000,
"min": 0,
"max": 4,
"avg": 1.17,
"cpu": 1,
"node": 0
},
"1": {
"histogram": {
"0": 14,
"1": 833,
"2": 93,
"3": 56,
"4": 4
},
"cycles": 1000,
"min": 0,
"max": 4,
"avg": 1.20,
"cpu": 2,
"node": 0
} }
}
It's just a rough version. I didn't try to make it generic for the other rt-tests or make it as plugin as John was suggesting. I'd think we could make this feature as compile option, if you want to keep the program small. Obviously, we could also make the terminal output a compile option, to keep it small.
Anyway, what do you think about it?
Thanks,
Daniel
Daniel Wagner (2):
signaltest: Add JSON output feature
sigwaittest: Add JSON output feature
src/signaltest/signaltest.c | 106 ++++++++++++++++++++++++------ src/sigwaittest/sigwaittest.c | 117 ++++++++++++++++++++++++++++------ 2 files changed, 185 insertions(+), 38 deletions(-)
Signature · 1 line
2.30.0
PATCH v6 1/2 signaltest: Add JSON output feature
Write the test results as JSON output to a file. This allows to simplifies any parsing later on.
--- src/signaltest/signaltest.c | 106 +++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 20 deletions(-)
src/signaltest/signaltest.c +86 -20
@@ -22,6 +22,7 @@#include <unistd.h> #include <errno.h> #include <sched.h> +#include <inttypes.h> #include <linux/unistd.h>
@@ -207,6 +208,14 @@ static int lockall;static struct bitmask *affinity_mask =NULL ;static int smp =0 ;static int setaffinity =AFFINITY_UNSPECIFIED ; +static char outfile[MAX_PATH ]; + +enum option_values { +OPT_AFFINITY =1 ,OPT_BREAKTRACE , +OPT_DURATION ,OPT_HELP ,OPT_LOOPS , +OPT_MLOCKALL ,OPT_OUTPUT ,OPT_PRIORITY , +OPT_QUIET ,OPT_SMP ,OPT_THREADS ,OPT_VERBOSE +};/* Process commandline options */ static void process_options (int argc,char *argv[],unsigned int max_cpus)
@@ -219,17 +228,18 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)int option_index =0 ;/** Options for getopt */ static struct option long_options[] = { - {"affinity" , optional_argument,NULL ,'a' }, - {"breaktrace" , required_argument,NULL ,'b' }, - {"duration" , required_argument,NULL ,'D' }, - {"help" , no_argument,NULL ,'h' }, - {"loops" , required_argument,NULL ,'l' }, - {"mlockall" , no_argument,NULL ,'m' }, - {"priority" , required_argument,NULL ,'p' }, - {"quiet" , no_argument,NULL ,'q' }, - {"smp" , no_argument,NULL ,'S' }, - {"threads" , required_argument,NULL ,'t' }, - {"verbose" , no_argument,NULL ,'v' }, + {"affinity" , optional_argument,NULL ,OPT_AFFINITY }, + {"breaktrace" , required_argument,NULL ,OPT_BREAKTRACE }, + {"duration" , required_argument,NULL ,OPT_DURATION }, + {"help" , no_argument,NULL ,OPT_HELP }, + {"loops" , required_argument,NULL ,OPT_LOOPS }, + {"mlockall" , no_argument,NULL ,OPT_MLOCKALL }, + {"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" , required_argument,NULL ,OPT_THREADS }, + {"verbose" , no_argument,NULL ,OPT_VERBOSE }, {NULL ,0 ,NULL ,0 } }; int c = getopt_long(argc, argv, "a::b:D:hl:mp:qSt:v",
@@ -237,6 +247,7 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)if (c ==-1 )break ;switch (c) { +case OPT_AFFINITY :case 'a' : option_affinity =1 ;/* smp sets AFFINITY_USEALL in OPT_SMP */
@@ -262,14 +273,39 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)printf ("Using %u cpus.\n" ,numa_bitmask_weight (affinity_mask));break ; -case 'b' : tracelimit =atoi (optarg);break ; -case 'D' : duration =parse_time_string (optarg);break ; +case OPT_BREAKTRACE : +case 'b' : + tracelimit =atoi (optarg); +break ; +case OPT_DURATION : +case 'D' : + duration =parse_time_string (optarg); +break ; +case OPT_HELP :case '?' : -case 'h' :display_help (0 );break ; -case 'l' : max_cycles =atoi (optarg);break ; -case 'm' : lockall =1 ;break ; -case 'p' : priority =atoi (optarg);break ; -case 'q' : quiet =1 ;break ; +case 'h' : +display_help (0 ); +break ; +case OPT_LOOPS : +case 'l' : + max_cycles =atoi (optarg); +break ; +case OPT_MLOCKALL : +case 'm' : + lockall =1 ; +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' :if (numa)fatal ("numa and smp options are mutually exclusive\n" );
@@ -277,8 +313,13 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus) num_threads =-1 ;/* update after parsing */ setaffinity =AFFINITY_USEALL ;break ; -case 't' : num_threads =atoi (optarg);break ; -case 'v' : verbose =1 ;break ; +case OPT_THREADS : +case 't' : + num_threads =atoi (optarg); +break ; +case OPT_VERBOSE : +case 'v' : verbose =1 ; +break ; } }
@@ -339,6 +380,28 @@ static void print_stat(struct thread_param *par, int index, int verbose) } } +static void write_stats (FILE *f,void *data) +{ +struct thread_param *par = data; +struct thread_stat *s; +unsigned int i; + +fprintf (f," \"num_threads\": %d,\n" , num_threads); +fprintf (f," \"thread\": {\n" ); +for (i =0 ; i < num_threads; i++) { +fprintf (f," \"%u\": {\n" , i); + s = &par->stats[i]; +fprintf (f," \"cycles\": %" PRIu64",\n" , s->cycles); +fprintf (f," \"min\": %" PRIu64",\n" , s->min); +fprintf (f," \"max\": %" PRIu64",\n" , s->max); +fprintf (f," \"avg\": %.2f,\n" , s->avg/s->cycles); +fprintf (f," \"cpu\": %d\n" , par->cpu); +fprintf (f," }%s\n" , i == num_threads -1 ?"" :"," ); + + } +fprintf (f," }\n" ); +} +int main (int argc,char **argv) {sigset_t sigset;
@@ -494,6 +557,9 @@ int main(int argc, char **argv)if (stat[i].values)free (stat[i].values); } +if (strlen (outfile) !=0 ) +rt_write_json (outfile, argc, argv, write_stats, par); +free (stat); outpar:free (par);
Signature · 1 line
2.30.0
Re: [PATCH rt-tests v6 1/2] signaltest: Add JSON output feature
Quoted 179 lines · Daniel Wagner
Write the test results as JSON output to a file. This allows to simplifies any parsing later on.
Signed-off-by Daniel Wagner <[email protected]>--- src/signaltest/signaltest.c | 106 +++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 20 deletions(-)src/signaltest/signaltest.c +86
-20@@ -22,6 +22,7 @@#include <unistd.h> #include <errno.h> #include <sched.h> +#include <inttypes.h> #include <linux/unistd.h> @@ -207,6 +208,14 @@ static int lockall;static struct bitmask *affinity_mask =NULL ;static int smp =0 ;static int setaffinity =AFFINITY_UNSPECIFIED ; +static char outfile[MAX_PATH ]; + +enum option_values { +OPT_AFFINITY =1 ,OPT_BREAKTRACE , +OPT_DURATION ,OPT_HELP ,OPT_LOOPS , +OPT_MLOCKALL ,OPT_OUTPUT ,OPT_PRIORITY , +OPT_QUIET ,OPT_SMP ,OPT_THREADS ,OPT_VERBOSE +};/* Process commandline options */ static void process_options (int argc,char *argv[],unsigned int max_cpus)@@ -219,17 +228,18 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)int option_index =0 ;/** Options for getopt */ static struct option long_options[] = { - {"affinity" , optional_argument,NULL ,'a' }, - {"breaktrace" , required_argument,NULL ,'b' }, - {"duration" , required_argument,NULL ,'D' }, - {"help" , no_argument,NULL ,'h' }, - {"loops" , required_argument,NULL ,'l' }, - {"mlockall" , no_argument,NULL ,'m' }, - {"priority" , required_argument,NULL ,'p' }, - {"quiet" , no_argument,NULL ,'q' }, - {"smp" , no_argument,NULL ,'S' }, - {"threads" , required_argument,NULL ,'t' }, - {"verbose" , no_argument,NULL ,'v' }, + {"affinity" , optional_argument,NULL ,OPT_AFFINITY }, + {"breaktrace" , required_argument,NULL ,OPT_BREAKTRACE }, + {"duration" , required_argument,NULL ,OPT_DURATION }, + {"help" , no_argument,NULL ,OPT_HELP }, + {"loops" , required_argument,NULL ,OPT_LOOPS }, + {"mlockall" , no_argument,NULL ,OPT_MLOCKALL }, + {"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" , required_argument,NULL ,OPT_THREADS }, + {"verbose" , no_argument,NULL ,OPT_VERBOSE }, {NULL ,0 ,NULL ,0 } }; int c = getopt_long(argc, argv, "a::b:D:hl:mp:qSt:v",@@ -237,6 +247,7 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)if (c ==-1 )break ;switch (c) { +case OPT_AFFINITY :case 'a' : option_affinity =1 ;/* smp sets AFFINITY_USEALL in OPT_SMP */ @@ -262,14 +273,39 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)printf ("Using %u cpus.\n" ,numa_bitmask_weight (affinity_mask));break ; -case 'b' : tracelimit =atoi (optarg);break ; -case 'D' : duration =parse_time_string (optarg);break ; +case OPT_BREAKTRACE : +case 'b' : + tracelimit =atoi (optarg); +break ; +case OPT_DURATION : +case 'D' : + duration =parse_time_string (optarg); +break ; +case OPT_HELP :case '?' : -case 'h' :display_help (0 );break ; -case 'l' : max_cycles =atoi (optarg);break ; -case 'm' : lockall =1 ;break ; -case 'p' : priority =atoi (optarg);break ; -case 'q' : quiet =1 ;break ; +case 'h' : +display_help (0 ); +break ; +case OPT_LOOPS : +case 'l' : + max_cycles =atoi (optarg); +break ; +case OPT_MLOCKALL : +case 'm' : + lockall =1 ; +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' :if (numa)fatal ("numa and smp options are mutually exclusive\n" );@@ -277,8 +313,13 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus) num_threads =-1 ;/* update after parsing */ setaffinity =AFFINITY_USEALL ;break ; -case 't' : num_threads =atoi (optarg);break ; -case 'v' : verbose =1 ;break ; +case OPT_THREADS : +case 't' : + num_threads =atoi (optarg); +break ; +case OPT_VERBOSE : +case 'v' : verbose =1 ; +break ; } }@@ -339,6 +380,28 @@ static void print_stat(struct thread_param *par, int index, int verbose) } } +static void write_stats (FILE *f,void *data) +{ +struct thread_param *par = data; +struct thread_stat *s; +unsigned int i; + +fprintf (f," \"num_threads\": %d,\n" , num_threads); +fprintf (f," \"thread\": {\n" ); +for (i =0 ; i < num_threads; i++) { +fprintf (f," \"%u\": {\n" , i); + s = &par->stats[i]; +fprintf (f," \"cycles\": %" PRIu64",\n" , s->cycles); +fprintf (f," \"min\": %" PRIu64",\n" , s->min); +fprintf (f," \"max\": %" PRIu64",\n" , s->max); +fprintf (f," \"avg\": %.2f,\n" , s->avg/s->cycles); +fprintf (f," \"cpu\": %d\n" , par->cpu); +fprintf (f," }%s\n" , i == num_threads -1 ?"" :"," ); + + } +fprintf (f," }\n" ); +} +int main (int argc,char **argv) {sigset_t sigset;@@ -494,6 +557,9 @@ int main(int argc, char **argv)if (stat[i].values)free (stat[i].values); } +if (strlen (outfile) !=0 ) +rt_write_json (outfile, argc, argv, write_stats, par); +free (stat); outpar:free (par);Signature · 1 line
2.30.0
PATCH v6 2/2 sigwaittest: Add JSON output feature
In reply to Daniel WagnerWrite the test results as JSON output to a file. This allows to simplifies any parsing later on.
--- src/sigwaittest/sigwaittest.c | 117 ++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 18 deletions(-)
src/sigwaittest/sigwaittest.c +99 -18
@@ -39,6 +39,7 @@#include <linux/unistd.h> #include <utmpx.h> #include <pthread.h> +#include <inttypes.h> #include "rt-utils.h" #include "rt-get_cpu.h"
@@ -220,6 +221,7 @@ static void display_help(int error)"-f [OPT] --fork[=OPT] fork new processes instead of creating threads\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" "-t --threads one thread per available processor\n"
@@ -240,6 +242,13 @@ static int duration;static int interval =1000 ;static int distance =500 ;static int quiet; +static char outfile[MAX_PATH ]; + +enum option_value { +OPT_AFFINITY =1 ,OPT_BREAKTRACE ,OPT_DISTANCE ,OPT_DURATION , +OPT_FORK ,OPT_HELP ,OPT_INTERVAL ,OPT_LOOPS ,OPT_OUTPUT , +OPT_PRIORITY ,OPT_QUIET ,OPT_THREADS +};static void process_options (int argc,char *argv[]) {
@@ -251,17 +260,18 @@ 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' }, - {"fork" , optional_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' }, - {"threads" , optional_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 }, + {"fork" , optional_argument,NULL ,OPT_FORK }, + {"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 }, + {"threads" , optional_argument,NULL ,OPT_THREADS }, {NULL ,0 ,NULL ,0 } }; int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qt::",
@@ -269,6 +279,7 @@ static void process_options(int argc, char *argv[])if (c ==-1 )break ;switch (c) { +case OPT_AFFINITY :case 'a' :if (optarg !=NULL ) { affinity =atoi (optarg);
@@ -280,9 +291,19 @@ static void process_options(int argc, char *argv[]) setaffinity =AFFINITY_USEALL ; }break ; -case 'b' : thistracelimit =atoi (optarg);break ; -case 'd' : distance =atoi (optarg);break ; -case 'D' : duration =parse_time_string (optarg);break ; +case OPT_BREAKTRACE : +case 'b' : + thistracelimit =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_FORK :case 'f' :if (optarg !=NULL ) { wasforked =1 ;
@@ -294,14 +315,31 @@ static void process_options(int argc, char *argv[]) }else mustfork =1 ;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 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_THREADS :case 't' :if (optarg !=NULL ) num_threads =atoi (optarg);
@@ -388,6 +426,41 @@ 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," \"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, totalsize =0 ;
@@ -627,6 +700,14 @@ int main(int argc, char *argv[]) } } +if (strlen (outfile) !=0 ) { +struct params_stats ps = { + .receiver = receiver, + .sender = sender, + }; +rt_write_json (outfile, argc, argv, write_stats, &ps); + } + nomem:if (mustfork) {munmap (param, totalsize);
Signature · 1 line
2.30.0
Re: [PATCH rt-tests v6 2/2] sigwaittest: Add JSON output feature
Quoted 200 lines · Daniel Wagner
Write the test results as JSON output to a file. This allows to simplifies any parsing later on.
Signed-off-by Daniel Wagner <[email protected]>--- src/sigwaittest/sigwaittest.c | 117 ++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 18 deletions(-)src/sigwaittest/sigwaittest.c +99
-18@@ -39,6 +39,7 @@#include <linux/unistd.h> #include <utmpx.h> #include <pthread.h> +#include <inttypes.h> #include "rt-utils.h" #include "rt-get_cpu.h" @@ -220,6 +221,7 @@ static void display_help(int error)"-f [OPT] --fork[=OPT] fork new processes instead of creating threads\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" "-t --threads one thread per available processor\n" @@ -240,6 +242,13 @@ static int duration;static int interval =1000 ;static int distance =500 ;static int quiet; +static char outfile[MAX_PATH ]; + +enum option_value { +OPT_AFFINITY =1 ,OPT_BREAKTRACE ,OPT_DISTANCE ,OPT_DURATION , +OPT_FORK ,OPT_HELP ,OPT_INTERVAL ,OPT_LOOPS ,OPT_OUTPUT , +OPT_PRIORITY ,OPT_QUIET ,OPT_THREADS +};static void process_options (int argc,char *argv[]) {@@ -251,17 +260,18 @@ 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' }, - {"fork" , optional_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' }, - {"threads" , optional_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 }, + {"fork" , optional_argument,NULL ,OPT_FORK }, + {"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 }, + {"threads" , optional_argument,NULL ,OPT_THREADS }, {NULL ,0 ,NULL ,0 } }; int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qt::",@@ -269,6 +279,7 @@ static void process_options(int argc, char *argv[])if (c ==-1 )break ;switch (c) { +case OPT_AFFINITY :case 'a' :if (optarg !=NULL ) { affinity =atoi (optarg);@@ -280,9 +291,19 @@ static void process_options(int argc, char *argv[]) setaffinity =AFFINITY_USEALL ; }break ; -case 'b' : thistracelimit =atoi (optarg);break ; -case 'd' : distance =atoi (optarg);break ; -case 'D' : duration =parse_time_string (optarg);break ; +case OPT_BREAKTRACE : +case 'b' : + thistracelimit =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_FORK :case 'f' :if (optarg !=NULL ) { wasforked =1 ;@@ -294,14 +315,31 @@ static void process_options(int argc, char *argv[]) }else mustfork =1 ;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 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_THREADS :case 't' :if (optarg !=NULL ) num_threads =atoi (optarg);@@ -388,6 +426,41 @@ 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," \"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, totalsize =0 ;@@ -627,6 +700,14 @@ int main(int argc, char *argv[]) } } +if (strlen (outfile) !=0 ) { +struct params_stats ps = { + .receiver = receiver, + .sender = sender, + }; +rt_write_json (outfile, argc, argv, write_stats, &ps); + } + nomem:if (mustfork) {munmap (param, totalsize);Signature · 1 line
2.30.0