Skip to content

Commit 04f81f4

Browse files
captain5050acmel
authored andcommitted
perf callchain lbr: Make the leaf IP that of the sample
The current IP of a leaf function when reported from a perf record with "--call-graph lbr" is the "to" field of the LBR branch stack record. The sample for the event being recorded may be further into the function and there may be inlining information associated with it. Rather than use the branch stack "to" field in this case switch to the callchain appending the sample->ip and thereby allowing the inline information to show. Before this change: ``` $ perf record --call-graph lbr perf test -w inlineloop ... $ perf script --fields +srcline ... perf-inlineloop 467586 4649.344493: 950905 cpu_core/cycles/P: 55dfda2829c0 parent+0x0 (perf) inlineloop.c:31 55dfda282a96 inlineloop+0x86 (perf) inlineloop.c:47 55dfda236420 run_workload+0x59 (perf) builtin-test.c:715 55dfda236b03 cmd_test+0x413 (perf) builtin-test.c:825 ... ``` After this change: ``` $ perf record --call-graph lbr perf test -w inlineloop ... $ perf script --fields +srcline ... perf-inlineloop 529703 11878.680815: 950905 cpu_core/cycles/P: 555ce86be9e6 leaf+0x26 inlineloop.c:20 (inlined) 555ce86be9e6 middle+0x26 inlineloop.c:27 (inlined) 555ce86be9e6 parent+0x26 (perf) inlineloop.c:32 555ce86bea96 inlineloop+0x86 (perf) inlineloop.c:47 555ce8672420 run_workload+0x59 (perf) builtin-test.c:715 555ce8672b03 cmd_test+0x413 (perf) builtin-test.c:825 ... ``` Reviewed-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Krzysztof Łopatowski <krzysztof.m.lopatowski@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Weilin Wang <weilin.wang@intel.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a724a8f commit 04f81f4

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tools/perf/util/machine.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,8 +2423,14 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
24232423
}
24242424

24252425
if (callee) {
2426-
/* Add LBR ip from first entries.to */
2427-
ip = entries[0].to;
2426+
/*
2427+
* Set the (first) leaf function's IP to sample->ip (the
2428+
* location of the sample) but if not recorded use entries.to
2429+
*/
2430+
if (sample->ip)
2431+
ip = sample->ip;
2432+
else
2433+
ip = entries[0].to;
24282434
flags = &entries[0].flags;
24292435
*branch_from = entries[0].from;
24302436
err = add_callchain_ip(thread, cursor, parent,
@@ -2477,8 +2483,14 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
24772483
}
24782484

24792485
if (lbr_nr > 0) {
2480-
/* Add LBR ip from first entries.to */
2481-
ip = entries[0].to;
2486+
/*
2487+
* Set the (first) leaf function's IP to sample->ip (the
2488+
* location of the sample) but if not recorded use entries.to
2489+
*/
2490+
if (sample->ip)
2491+
ip = sample->ip;
2492+
else
2493+
ip = entries[0].to;
24822494
flags = &entries[0].flags;
24832495
*branch_from = entries[0].from;
24842496
err = add_callchain_ip(thread, cursor, parent,

0 commit comments

Comments
 (0)