I'm using perf record -a --call-graph dwarf -p XXX sleep 1
to record some function calls then perf report
to view that data, however it would be very helpful if I could also see source line numbers to know exactly where each function call was made. For example:
- 4.18% testbinary testbinary [.] malloc
- malloc
- 99.57% operator new(unsigned long)
+ 7.28% MyFunction()
I want to know where exactly in MyFunction()
are those new operators
called (without me guessing by looking at the whole function source code)
P.S.: Binary is compiled with -m64 -O2 -ggdb3
Sampling with perf record The report contains 4 columns, which have their own specific meaning: Overhead: the percentage of overall samples collected in the corresponding function. Command: the command to which the samples belong.
A perf record command was used to trace the block:block_rq_issue probe, which fires when a block device I/O request is issued (disk I/O). Options included -a to trace all CPUs, and -g to capture call graphs (stack traces). Trace data is written to a perf. data file, and tracing ended when Ctrl-C was hit.
Description. This command reads the input file and displays the trace recorded. There are several variants of perf script: 'perf script' to see a detailed trace of the workload that was recorded.
I accidentally found it loosely documented in perf script
, but it applies to other commands as well: -F
option accepts srcline
. So you can do -F+srcline
to add the line number to 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With