Source line numbers in the primary call schedule?
I use perf record -a --call-graph dwarf -p XXX sleep 1
to record some function calls and then perf report
view this data, however it would be very helpful if I could also see the source line numbers so that I know exactly where each function call was called. For example:
- 4.18% testbinary testbinary [.] malloc
- malloc
- 99.57% operator new(unsigned long)
+ 7.28% MyFunction()
I want to know exactly where MyFunction()
those are in new operators
(without guessing by looking at the entire function source code)
PS: Binary is compiled with -m64 -O2 -ggdb3
source to share
Fragments (complete lines) of the source code are printed by the performance in annotated mode ( man page ; relevant part of the Perf Tutorial ). Use perf annotate -s=MyFunction
or perf report
, scroll down to the subtree where your MyFunction is the root of the tree (the line where the battery life is, you can use the command /to find it) and then select the button a(or Enterthen annotate "MyFunction").
The source code and its lines should be visible next to the conveyor lines in annotation mode. http://man7.org/linux/man-pages/man1/perf-annotate.1.html
This command reads the input file and displays the annotated version of the code. If the object file has debug symbols, then the source code will be displayed next to the assembly code.
-l, --print-line Print matching source lines (may be slow). --source Interleave source code with assembly code. Enabled by default, disable with `--no-source`. -s, --symbol=<symbol> Symbol to annotate.
Perf report can use srclines when sorting ( --sort=
), but the instructions are unclear. Its a doc man page --source
too, but apparently it is only used in Annotate some_function: http://man7.org/linux/man-pages/man1/perf-report.1.html
--source
Interleave source code with assembly code. Enabled by default,
disable with --no-source.
source to share
I accidentally discovered this is poorly documented in perf script
, but this applies to other commands as well: the option -F
takes srcline
. So you can do -F+srcline
to add the row number to the existing columns.
Example: perf report -g fractal -F+period,srcline
Samples: 22K of event 'cycles:u', Event count (approx.): 13031011295
Children Self Period Source:Line Command Shared Object Symbol
+ 99.98% 38.76% 5051224000 test.cpp:7 a a [.] fib
+ 96.42% 0.00% 0 _start+94372992700461 a a [.] _start
+ 96.42% 0.00% 0 __libc_start_main+140304673091826 a libc-2.29.so [.] __libc_start_main
+ 96.42% 0.00% 0 test.cpp:13 a a [.] main
+ 21.47% 21.47% 2797741850 test.cpp:8 a a [.] fib
+ 16.69% 16.69% 2174469736 test.cpp:4 a a [.] fib
+ 16.37% 16.36% 2132462705 test.cpp:6 a a [.] fib
+ 6.69% 6.69% 871128215 test.cpp:5 a a [.] fib
source to share