perf evsel: Support printing callchains with arrows
authorNamhyung Kim <namhyung@kernel.org>
Wed, 16 Nov 2016 06:06:28 +0000 (15:06 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 23 Nov 2016 13:44:07 +0000 (10:44 -0300)
The EVSEL__PRINT_CALLCHAIN_ARROW options can be used to print callchains
with arrows for readability.  It will be used 'sched timehist' command
like below:

    __schedule <- schedule <- schedule_timeout <- rcu_gp_kthread <- kthread <- ret_from_fork
    __schedule <- schedule <- schedule_timeout <- rcu_gp_kthread <- kthread <- ret_from_fork
    __schedule <- schedule <- worker_thread <- kthread <- ret_from_fork

Suggested-and-Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20161116060634.28477-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.h
tools/perf/util/evsel_fprintf.c

index 8cd7cd2274836f9b2725d1b54e80feb78d12f863..27fa3a3435779da75dd15f07ce07e49ccfdd3947 100644 (file)
@@ -391,6 +391,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,
 #define EVSEL__PRINT_ONELINE           (1<<4)
 #define EVSEL__PRINT_SRCLINE           (1<<5)
 #define EVSEL__PRINT_UNKNOWN_AS_ADDR   (1<<6)
+#define EVSEL__PRINT_CALLCHAIN_ARROW   (1<<7)
 
 struct callchain_cursor;
 
index ccb602397b60b043572c02f8b21c5919999257f2..53bb614feafb0a4d27b135abbca5e721d23ee4d5 100644 (file)
@@ -108,7 +108,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
        int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
        int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
        int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
+       int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
        char s = print_oneline ? ' ' : '\t';
+       bool first = true;
 
        if (sample->callchain) {
                struct addr_location node_al;
@@ -124,6 +126,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
 
                        printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
 
+                       if (print_arrow && !first)
+                               printed += fprintf(fp, " <-");
+
                        if (print_ip)
                                printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
 
@@ -158,6 +163,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
                                printed += fprintf(fp, "\n");
 
                        callchain_cursor_advance(cursor);
+                       first = false;
                }
        }