Commit-ID: 9cdbc409626b29ab30f06a6393db6763f040f753 Gitweb: http://git.kernel.org/tip/9cdbc409626b29ab30f06a6393db6763f040f753 Author: Jiri Olsa <jolsa@xxxxxxxxxx> AuthorDate: Thu, 7 Jan 2016 10:14:05 +0100 Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> CommitDate: Fri, 8 Jan 2016 12:57:26 -0300 perf script: Align event name properly Adding code to align event names, so we get aligned output in case of multiple events with different names. Before: $ perf script :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010 :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P: 7f5a5f719f00 :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P: 7f5a5f719f00 :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810 :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28 :13757 13757 163918.155264: cpu/mem-snp-hitm/P: 601080 ... After: $ perf script :13757 13757 163918.228831: cpu/mem-snp-none/P: ffffffff81a841c0 :13757 13757 163918.228834: cpu/mem-loads,ldlat=30/P: 7f5a5f719f08 :13757 13757 163918.228837: cpu/mem-loads,ldlat=30/P: 7f5a5f719f08 :13758 13758 163918.228837: cpu/mem-snp-none/P: ffff88085f4ad800 :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28 :13757 13757 163918.155264: cpu/mem-snp-hitm/P: 601080 ... Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> Acked-by: David Ahern <dsahern@xxxxxxxxx> Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx> Cc: Namhyung Kim <namhyung@xxxxxxxxxx> Cc: Noel Grandin <noelgrandin@xxxxxxxxx> Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx> Link: http://lkml.kernel.org/r/1452158050-28061-9-git-send-email-jolsa@xxxxxxxxxx Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> --- tools/perf/builtin-script.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 5e2f9d2..c691214 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -617,9 +617,24 @@ struct perf_script { bool allocated; struct cpu_map *cpus; struct thread_map *threads; + int name_width; }; -static void process_event(struct perf_script *script __maybe_unused, union perf_event *event, +static int perf_evlist__max_name_len(struct perf_evlist *evlist) +{ + struct perf_evsel *evsel; + int max = 0; + + evlist__for_each(evlist, evsel) { + int len = strlen(perf_evsel__name(evsel)); + + max = MAX(len, max); + } + + return max; +} + +static void process_event(struct perf_script *script, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct addr_location *al) { @@ -636,7 +651,12 @@ static void process_event(struct perf_script *script __maybe_unused, union perf_ if (PRINT_FIELD(EVNAME)) { const char *evname = perf_evsel__name(evsel); - printf("%s: ", evname ? evname : "[unknown]"); + + if (!script->name_width) + script->name_width = perf_evlist__max_name_len(script->session->evlist); + + printf("%*s: ", script->name_width, + evname ? evname : "[unknown]"); } if (print_flags) -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
![]() |