簡體   English   中英

使用perf探針監視特定功能期間的性能統計

[英]Using perf probe to monitor performance stats during a particular function

我正在嘗試使用linux perf工具監視特定功能期間的性能統計數據。

我按照https://perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes上的說明進行操作

我試着獲得一個簡單的C程序的指令數。 (如下所示)

1)我簡單的C代碼

#include<stdio.h>

int sum=0;
int i=0;

void func(void)
{
   for(i=0;i<100;i++)
   {
     sum=sum+i;
   }
}

int main(void)
{
   func();
   return 0;
}

2)編譯和添加探針

root@sunimal-laptop:/home/sunimal/temp# gcc -o ex source.c 
root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex entry=func
Added new event:
  probe_ex:entry       (on 0x4ed)

You can now use it in all perf tools, such as:

        perf record -e probe_ex:entry -aR sleep 1

root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex exit=func%return
Added new event:
  probe_ex:exit        (on 0x4ed%return)

You can now use it in all perf tools, such as:

        perf record -e probe_ex:exit -aR sleep 1

3)嘗試使用perf stat來測量func()函數中的指令計數。 這會導致錯誤。

root@sunimal-laptop:/home/sunimal/temp# perf stat -e instructions:u,probe_ex:entry/on=instructions/,probe_ex:exit/off=instructions/ ./ex
invalid or unsupported event: 'instructions:u,probe_ex:entry/on=instructions/,probe_ex:exit/off=instructions/'
Run 'perf list' for a list of valid events

有人能指出我做錯的地方嗎?

[我正在使用linux內核3.11.0-12-generic]

我認為您所遵循的說明尚未包含在主線Linux內核中。 因此,perf告訴您不支持事件:perf不知道此頁面上提到的“切換”機制。

我可以看到兩個解決方法:

  1. 如果您可以訪問要分析的源代碼,則可以直接使用源代碼中的perf_event_open系統調用來啟動和停止計算函數的進入和退出。
  2. 克隆jolsa存儲庫git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/jolsa/perf切換core_toggle分支git co remotes/origin/perf/core_toggle ,然后使用此編譯並運行內核支持。

關於2,我對內核版本和開發並不熟悉,我認為這個解決方案的使用和維護可能很復雜。 也許您應該在perf用戶郵件列表上詢問是否有任何計划將切換功能集成到主線內核中。

暫無
暫無

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

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