簡體   English   中英

perf調用圖中的源行號?

[英]Source line numbers in perf call graph?

我正在使用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 (沒有我通過查看整個函數源代碼猜測)

PS:Binary使用-m64 -O2 -ggdb3編譯

源代碼的片段(實線)由注釋模式中的perf打印( 手冊頁 ; Perf教程的相關部分)。 使用perf annotate -s=MyFunction或在perf report向下滾動到您的MyFunction是樹的根的子樹(報告自身時間的行;您可以使用/命令搜索它)然后選擇一個按鈕(或輸入然后注釋“MyFunction”)。

在Annotate模式下,源代碼及其行應在裝配線附近可見。 http://man7.org/linux/man-pages/man1/perf-annotate.1.html

此命令讀取輸入文件並顯示代碼的帶注釋版本。 如果目標文件具有調試符號,則源代碼將與匯編代碼一起顯示。

  -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報告可能在排序中使用srclines(-- --sort= option),但說明不清楚。 它的手冊頁文件也是 - --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. 

我不小心發現它在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                    [.] fib

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM