gpt4 book ai didi

linux - 使用 perf probe 监控特定功能期间的性能统计信息

转载 作者:IT王子 更新时间:2023-10-29 01:26:51 25 4
gpt4 key购买 nike

我正在尝试使用 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 users mailing list是否有计划将切换功能集成到主线内核中。

关于linux - 使用 perf probe 监控特定功能期间的性能统计信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22398824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com