perf script: Improve srcline display for BTS
[firefly-linux-kernel-4.4.55.git] / tools / perf / builtin-script.c
index 9e9c91f5b7fae97de166583b46bd801fc4ccc2f1..333b15ebe72bc0c86d8f85a2afbb4b6e5f672cfa 100644 (file)
@@ -427,15 +427,22 @@ static void print_sample_bts(union perf_event *event,
                             struct addr_location *al)
 {
        struct perf_event_attr *attr = &evsel->attr;
+       bool print_srcline_last = false;
 
        /* print branch_from information */
        if (PRINT_FIELD(IP)) {
-               if (!symbol_conf.use_callchain)
-                       printf(" ");
-               else
+               unsigned int print_opts = output[attr->type].print_ip_opts;
+
+               if (symbol_conf.use_callchain && sample->callchain) {
                        printf("\n");
-               perf_evsel__print_ip(evsel, sample, al,
-                                    output[attr->type].print_ip_opts,
+               } else {
+                       printf(" ");
+                       if (print_opts & PRINT_IP_OPT_SRCLINE) {
+                               print_srcline_last = true;
+                               print_opts &= ~PRINT_IP_OPT_SRCLINE;
+                       }
+               }
+               perf_evsel__print_ip(evsel, sample, al, print_opts,
                                     PERF_MAX_STACK_DEPTH);
        }
 
@@ -447,6 +454,9 @@ static void print_sample_bts(union perf_event *event,
             !output[attr->type].user_set))
                print_sample_addr(event, sample, al->machine, thread, attr);
 
+       if (print_srcline_last)
+               map__fprintf_srcline(al->map, al->addr, "\n  ", stdout);
+
        printf("\n");
 }