aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-01-07 04:14:05 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-01-08 10:57:26 -0500
commit9cdbc409626b29ab30f06a6393db6763f040f753 (patch)
tree1e4df3eb35ae90c73ddc40facbaad2f9e3accafa /tools/perf/builtin-script.c
parent2d7c03e6b0c604decae33b0ce03e69b79b2a39a1 (diff)
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@kernel.org> Acked-by: David Ahern <dsahern@gmail.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Noel Grandin <noelgrandin@gmail.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1452158050-28061-9-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5e2f9d20a296..c691214d820f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -617,9 +617,24 @@ struct perf_script {
617 bool allocated; 617 bool allocated;
618 struct cpu_map *cpus; 618 struct cpu_map *cpus;
619 struct thread_map *threads; 619 struct thread_map *threads;
620 int name_width;
620}; 621};
621 622
622static void process_event(struct perf_script *script __maybe_unused, union perf_event *event, 623static int perf_evlist__max_name_len(struct perf_evlist *evlist)
624{
625 struct perf_evsel *evsel;
626 int max = 0;
627
628 evlist__for_each(evlist, evsel) {
629 int len = strlen(perf_evsel__name(evsel));
630
631 max = MAX(len, max);
632 }
633
634 return max;
635}
636
637static void process_event(struct perf_script *script, union perf_event *event,
623 struct perf_sample *sample, struct perf_evsel *evsel, 638 struct perf_sample *sample, struct perf_evsel *evsel,
624 struct addr_location *al) 639 struct addr_location *al)
625{ 640{
@@ -636,7 +651,12 @@ static void process_event(struct perf_script *script __maybe_unused, union perf_
636 651
637 if (PRINT_FIELD(EVNAME)) { 652 if (PRINT_FIELD(EVNAME)) {
638 const char *evname = perf_evsel__name(evsel); 653 const char *evname = perf_evsel__name(evsel);
639 printf("%s: ", evname ? evname : "[unknown]"); 654
655 if (!script->name_width)
656 script->name_width = perf_evlist__max_name_len(script->session->evlist);
657
658 printf("%*s: ", script->name_width,
659 evname ? evname : "[unknown]");
640 } 660 }
641 661
642 if (print_flags) 662 if (print_flags)