Re: [PATCH 03/15] perf stat: Do not align time prefix in CSV output
From: Ian Rogers
Date: Wed Nov 23 2022 - 18:21:59 EST
On Wed, Nov 23, 2022 at 10:02 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> We don't care about the alignment in the CSV output as it's intended for machine
> processing. Let's get rid of it to make the output more compact.
>
> Before:
> # perf stat -a --summary -I 1 -x, true
> 0.001149309,219.20,msec,cpu-clock,219322251,100.00,219.200,CPUs utilized
> 0.001149309,144,,context-switches,219241902,100.00,656.935,/sec
> 0.001149309,38,,cpu-migrations,219173705,100.00,173.358,/sec
> 0.001149309,61,,page-faults,219093635,100.00,278.285,/sec
> 0.001149309,10679310,,cycles,218746228,100.00,0.049,GHz
> 0.001149309,6288296,,instructions,218589869,100.00,0.59,insn per cycle
> 0.001149309,1386904,,branches,218428851,100.00,6.327,M/sec
> 0.001149309,56863,,branch-misses,218219951,100.00,4.10,of all branches
> summary,219.20,msec,cpu-clock,219322251,100.00,20.025,CPUs utilized
> summary,144,,context-switches,219241902,100.00,656.935,/sec
> summary,38,,cpu-migrations,219173705,100.00,173.358,/sec
> summary,61,,page-faults,219093635,100.00,278.285,/sec
> summary,10679310,,cycles,218746228,100.00,0.049,GHz
> summary,6288296,,instructions,218589869,100.00,0.59,insn per cycle
> summary,1386904,,branches,218428851,100.00,6.327,M/sec
> summary,56863,,branch-misses,218219951,100.00,4.10,of all branches
>
> After:
> 0.001148449,224.75,msec,cpu-clock,224870589,100.00,224.747,CPUs utilized
> 0.001148449,176,,context-switches,224775564,100.00,783.103,/sec
> 0.001148449,38,,cpu-migrations,224707428,100.00,169.079,/sec
> 0.001148449,61,,page-faults,224629326,100.00,271.416,/sec
> 0.001148449,12172071,,cycles,224266368,100.00,0.054,GHz
> 0.001148449,6901907,,instructions,224108764,100.00,0.57,insn per cycle
> 0.001148449,1515655,,branches,223946693,100.00,6.744,M/sec
> 0.001148449,70027,,branch-misses,223735385,100.00,4.62,of all branches
> summary,224.75,msec,cpu-clock,224870589,100.00,21.066,CPUs utilized
> summary,176,,context-switches,224775564,100.00,783.103,/sec
> summary,38,,cpu-migrations,224707428,100.00,169.079,/sec
> summary,61,,page-faults,224629326,100.00,271.416,/sec
> summary,12172071,,cycles,224266368,100.00,0.054,GHz
> summary,6901907,,instructions,224108764,100.00,0.57,insn per cycle
> summary,1515655,,branches,223946693,100.00,6.744,M/sec
> summary,70027,,branch-misses,223735385,100.00,4.62,of all branches
>
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Acked-by: Ian Rogers <irogers@xxxxxxxxxx>
Thanks,
Ian
> ---
> tools/perf/util/stat-display.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index d86f2f8e020d..15c88b9b5aa3 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -828,7 +828,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config,
> fprintf(output, "%s", prefix);
> else if (config->summary && config->csv_output &&
> !config->no_csv_summary && !config->interval)
> - fprintf(output, "%16s%s", "summary", config->csv_sep);
> + fprintf(output, "%s%s", "summary", config->csv_sep);
> }
>
> uval = val * counter->scale;
> @@ -1078,9 +1078,12 @@ static void prepare_interval(struct perf_stat_config *config,
> if (config->iostat_run)
> return;
>
> - if (!config->json_output)
> - sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec,
> + if (config->csv_output)
> + sprintf(prefix, "%lu.%09lu%s", (unsigned long) ts->tv_sec,
> ts->tv_nsec, config->csv_sep);
> + else if (!config->json_output)
> + sprintf(prefix, "%6lu.%09lu ", (unsigned long) ts->tv_sec,
> + ts->tv_nsec);
> else if (!config->metric_only)
> sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
> ts->tv_sec, ts->tv_nsec);
> --
> 2.38.1.584.g0f3c55d4c2-goog
>