加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 使用perf探测器监视特定功能期间的性能统计数据

发布时间:2020-12-13 22:55:45 所属栏目:Linux 来源:网络整理
导读:我正在尝试使用 linux perf工具监视特定功能期间的性能统计数据. 我按照https://perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes给出的说明进行操作 我试着获得一个简单的C程序的指令数. (如下所示) 1)我简单
我正在尝试使用 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:exit/off=instructions/'
Run 'perf list' for a list of valid events

有人能指出我做错的地方吗?

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

解决方法

我认为您所遵循的说明尚未包含在主线Linux内核中.因此,perf告诉您不支持事件:perf不知道此页面上提到的“切换”机制.

我可以看到两个解决方法:

>如果您可以访问要分析的源代码,则可以直接使用源代码中的perf_event_open系统调用来启动和停止对函数输入和退出进行计数.
>克隆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上询问是否有任何计划将切换功能集成到主线内核中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读