Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Fix CSV mode column output for non-cgroup events

When using the -x option, perf stat prints CSV-style output with one
event per line. For each event, it prints the count, the unit, the
event name, the cgroup, and a bunch of other event specific fields (such
as insn per cycles).

When you use CSV-style mode, you expect a normalized output where each
event is printed with the same number of fields regardless of what it is
so it can easily be imported into a spreadsheet or parsed.

For instance, if an event does not have a unit, then print an empty
field for it.

Although this approach was implemented for the unit, it was not for the
cgroup.

When mixing cgroup and non-cgroup events, then non-cgroup events would
not show an empty field, instead the next field was printed, make
columns not line up correctly.

This patch fixes the cgroup output issues by forcing an empty field
for non-cgroup events as soon as one event has cgroup.

Before:

<not counted> @ @cycles @foo @ 0 @100.00@@
2531614 @ @cycles @6420922@100.00@ @

foo cgroup lines up with time_running!

After:

<not counted> @ @cycles @foo @0 @100.00@@
2594834 @ @cycles @ @5287372 @100.00@@

Fields line up.

Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1541587845-9150-1-git-send-email-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Stephane Eranian and committed by
Arnaldo Carvalho de Melo
bc4da38a 57ddf091

+11 -5
+11 -5
tools/perf/util/stat-display.c
··· 59 59 print_noise_pct(config, stddev_stats(&ps->res_stats[0]), avg); 60 60 } 61 61 62 + static void print_cgroup(struct perf_stat_config *config, struct perf_evsel *evsel) 63 + { 64 + if (nr_cgroups) { 65 + const char *cgrp_name = evsel->cgrp ? evsel->cgrp->name : ""; 66 + fprintf(config->output, "%s%s", config->csv_sep, cgrp_name); 67 + } 68 + } 69 + 70 + 62 71 static void aggr_printout(struct perf_stat_config *config, 63 72 struct perf_evsel *evsel, int id, int nr) 64 73 { ··· 345 336 346 337 fprintf(output, "%-*s", config->csv_output ? 0 : 25, perf_evsel__name(evsel)); 347 338 348 - if (evsel->cgrp) 349 - fprintf(output, "%s%s", config->csv_sep, evsel->cgrp->name); 339 + print_cgroup(config, evsel); 350 340 } 351 341 352 342 static bool is_mixed_hw_group(struct perf_evsel *counter) ··· 439 431 config->csv_output ? 0 : -25, 440 432 perf_evsel__name(counter)); 441 433 442 - if (counter->cgrp) 443 - fprintf(config->output, "%s%s", 444 - config->csv_sep, counter->cgrp->name); 434 + print_cgroup(config, counter); 445 435 446 436 if (!config->csv_output) 447 437 pm(config, &os, NULL, NULL, "", 0);