public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Daniel Wagner <dwagner@suse.de>
Cc: Clark Williams <williams@redhat.com>, linux-rt-users@vger.kernel.org
Subject: Re: [PATCH rt-tests v5 04/13] cyclictest: Add JSON output feature
Date: Tue, 16 Feb 2021 22:50:48 -0500 (EST)	[thread overview]
Message-ID: <e7e94ada-1e36-d6d-1538-e4e0defeed5b@redhat.com> (raw)
In-Reply-To: <20210210175118.19709-5-dwagner@suse.de>



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/cyclictest/cyclictest.c | 46 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index 7c45732c1553..3d0cf3f84b69 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -11,6 +11,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <stdint.h>
> +#include <inttypes.h>
>  #include <stdarg.h>
>  #include <unistd.h>
>  #include <fcntl.h>
> @@ -217,6 +218,7 @@ static struct timespec globalt;
>  
>  static char fifopath[MAX_PATH];
>  static char histfile[MAX_PATH];
> +static char outfile[MAX_PATH];
>  
>  static struct thread_param **parameters;
>  static struct thread_stat **statistics;
> @@ -838,6 +840,7 @@ static void display_help(int error)
>  	       "			   latency is hit. Useful for low bandwidth.\n"
>  	       "-N       --nsecs           print results in ns instead of us (default us)\n"
>  	       "-o RED   --oscope=RED      oscilloscope mode, reduce verbose output by RED\n"
> +	       "         --output=FILENAME write final results into FILENAME, JSON formatted\n"
>  	       "-p PRIO  --priority=PRIO   priority of highest prio thread\n"
>  	       "	 --policy=NAME     policy of measurement thread, where NAME may be one\n"
>  	       "                           of: other, normal, batch, idle, fifo or rr.\n"
> @@ -945,7 +948,7 @@ enum option_values {
>  	OPT_TRIGGER_NODES, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE,
>  	OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS,
>  	OPT_ALIGNED, OPT_SECALIGNED, OPT_LAPTOP, OPT_SMI,
> -	OPT_TRACEMARK, OPT_POSIX_TIMERS,
> +	OPT_TRACEMARK, OPT_POSIX_TIMERS, OPT_OUTPUT
>  };
>  
>  /* Process commandline options */
> @@ -979,6 +982,7 @@ static void process_options(int argc, char *argv[])
>  			{"refresh_on_max",   no_argument,       NULL, OPT_REFRESH },
>  			{"nsecs",            no_argument,       NULL, OPT_NSECS },
>  			{"oscope",           required_argument, NULL, OPT_OSCOPE },
> +			{"output",           required_argument, NULL, OPT_OUTPUT },
>  			{"priority",         required_argument, NULL, OPT_PRIORITY },
>  			{"quiet",            no_argument,       NULL, OPT_QUIET },
>  			{"priospread",       no_argument,       NULL, OPT_PRIOSPREAD },
> @@ -1073,6 +1077,9 @@ static void process_options(int argc, char *argv[])
>  		case 'o':
>  		case OPT_OSCOPE:
>  			oscope_reduction = atoi(optarg); break;
> +		case OPT_OUTPUT:
> +			strncpy(outfile, optarg, strnlen(optarg, MAX_PATH-1));
> +			break;
>  		case 'p':
>  		case OPT_PRIORITY:
>  			priority = atoi(optarg);
> @@ -1690,6 +1697,40 @@ static void rstat_setup(void)
>  	return;
>  }
>  
> +static void write_stats(FILE *f, void *data)
> +{
> +	struct thread_param **par = parameters;
> +	unsigned int i, j, comma;
> +	struct thread_stat *s;
> +
> +	fprintf(f, "  \"num_threads\": %d,\n", num_threads);
> +	fprintf(f, "  \"resolution_in_ns\": %u,\n", use_nsecs);
> +	fprintf(f, "  \"thread\": {\n");
> +	for (i = 0; i < num_threads; i++) {
> +		fprintf(f, "    \"%u\": {\n", i);
> +
> +		fprintf(f, "      \"histogram\": {");
> +		s = par[i]->stats;
> +		for (j = 0, comma = 0; j < histogram; j++) {
> +			if (s->hist_array[j] == 0)
> +				continue;
> +			fprintf(f, "%s", comma ? ",\n" : "\n");
> +			fprintf(f, "        \"%u\": %" PRIu64,j, s->hist_array[j]);
> +			comma = 1;
> +		}
> +		if (comma)
> +			fprintf(f, "\n");
> +		fprintf(f, "      },\n");
> +		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[i]->cpu);
> +		fprintf(f, "      \"node\": %d\n", par[i]->node);
> +		fprintf(f, "    }%s\n", i == num_threads - 1 ? "" : ",");
> +	}
> +	fprintf(f, "  }\n");
> +}
>  
>  int main(int argc, char **argv)
>  {
> @@ -2035,6 +2076,9 @@ int main(int argc, char **argv)
>  	if (!verbose && !quiet && refresh_on_max)
>  		printf("\033[%dB", num_threads + 2);
>  
> +	if (strlen(outfile) != 0)
> +		rt_write_json(outfile, argc, argv, write_stats, NULL);
> +
>  	if (quiet)
>  		quiet = 2;
>  	for (i = 0; i < num_threads; i++) {
> -- 
> 2.30.0
> 
> 
   - Added a space after a comma in fprintf
    Signed-off-by: John Kacur <jkacur@redhat.com>


  reply	other threads:[~2021-02-17  3:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 17:51 [PATCH rt-tests v5 00/13] Generate machine-readable output Daniel Wagner
2021-02-10 17:51 ` [PATCH rt-tests v5 01/13] cyclictest: Move thread data to struct thread_param Daniel Wagner
2021-02-17  3:52   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 02/13] signaltest: " Daniel Wagner
2021-02-17  3:52   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 03/13] rt-utils: Add JSON common header output helper Daniel Wagner
2021-02-17  3:50   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 04/13] cyclictest: Add JSON output feature Daniel Wagner
2021-02-17  3:50   ` John Kacur [this message]
2021-02-10 17:51 ` [PATCH rt-tests v5 05/13] signaltest: " Daniel Wagner
2021-02-17  3:50   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 06/13] cyclicdeadline: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 07/13] pmqtest: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 08/13] ptsematest: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 09/13] sigwaittest: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 10/13] svsematest: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 11/13] oslat: " Daniel Wagner
2021-02-17  3:51   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 12/13] rt-migrate-test: " Daniel Wagner
2021-02-17  3:52   ` John Kacur
2021-02-10 17:51 ` [PATCH rt-tests v5 13/13] oslat: Add quiet command line option Daniel Wagner
2021-02-17  3:52   ` John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7e94ada-1e36-d6d-1538-e4e0defeed5b@redhat.com \
    --to=jkacur@redhat.com \
    --cc=dwagner@suse.de \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox