我使用perf record -a --call-graph dwarf -p XXX sleep 1记录一些函数调用,然后用perf report查看数据,但是,如果我也可以看到源行号来准确地知道每个函数调用的位置,这将是非常有帮助的。例如:
- 4.18% testbinary testbinary [.] malloc
- malloc
- 99.57% operator new(unsigned long)
+ 7.28% MyFunction()我想知道在MyFunction()中调用的new operators到底在哪里(通过查看整个函数的源代码,不用我猜测)
P.S.:二进制文件是用-m64 -O2 -ggdb3编译的
发布于 2019-05-04 01:38:42
我意外地在perf script中发现了它的松散文档,但它也适用于其他命令:-F选项接受srcline。因此,可以执行-F+srcline将行号添加到现有列中。
示例: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 [.] fibhttps://stackoverflow.com/questions/44865551
复制相似问题