小编Sun*_*ake的帖子

使用 perf 探针监视特定功能期间的性能统计信息

我正在尝试使用 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;
}
Run Code Online (Sandbox Code Playgroud)

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: …
Run Code Online (Sandbox Code Playgroud)

linux linux-kernel perf

5
推荐指数
1
解决办法
1742
查看次数

标签 统计

linux ×1

linux-kernel ×1

perf ×1