简体   繁体   English

perf调用图中的源行号?

[英]Source line numbers in perf call graph?

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. 我正在使用perf record -a --call-graph dwarf -p XXX sleep 1来记录一些函数调用然后perf report来查看该数据,但是如果我还能看到源行号以确切知道哪里会非常有用每个函数调用都已完成。 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) 我想知道MyFunction()调用那些new operators (没有我通过查看整个函数源代码猜测)

PS: Binary is compiled with -m64 -O2 -ggdb3 PS:Binary使用-m64 -O2 -ggdb3编译

Fragments (full lines) of source code are printed by perf in annotate mode ( man page ; relevant part of The Perf Tutorial ). 源代码的片段(实线)由注释模式中的perf打印( 手册页 ; Perf教程的相关部分)。 Use perf annotate -s=MyFunction or in perf report scroll down to the subtree where your MyFunction is root of tree (line where self time is reported; you can use / command to search for it) and then select a button (or Enter then Annotate "MyFunction"). 使用perf annotate -s=MyFunction或在perf report向下滚动到您的MyFunction是树的根的子树(报告自身时间的行;您可以使用/命令搜索它)然后选择一个按钮(或输入然后注释“MyFunction”)。

Source code and its lines should be visible near assembly lines in Annotate mode. 在Annotate模式下,源代码及其行应在装配线附近可见。 http://man7.org/linux/man-pages/man1/perf-annotate.1.html http://man7.org/linux/man-pages/man1/perf-annotate.1.html

This command reads the input file and displays an annotated version of the code. 此命令读取输入文件并显示代码的带注释版本。 If the object file has debug symbols then the source code will be displayed alongside 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 may use srclines in sorting ( --sort= option) but instructions are unclear. Perf报告可能在排序中使用srclines(-- --sort= option),但说明不清楚。 Its man page documents --source option too, but apparently it is used only in Annotate some_function mode: http://man7.org/linux/man-pages/man1/perf-report.1.html 它的手册页文件也是 - --source选项,但显然它只在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. 

I accidentally found it loosely documented in perf script , but it applies to other commands as well: -F option accepts srcline . 我不小心发现它在perf script有松散的文档,但它也适用于其他命令: -F选项接受srcline So you can do -F+srcline to add the line number to existing columns. 因此,您可以执行-F+srcline将行号添加到现有列。

Example: perf report -g fractal -F+period,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                    [.] fib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM