使用 perf 探针监视特定功能期间的性能统计信息 [英] Using perf probe to monitor performance stats during a particular function

查看:16
本文介绍了使用 perf 探针监视特定功能期间的性能统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 linux perf 工具在特定功能期间监控性能统计数据.

I'm trying to monitor performance stats during a particular function using linux perf tool.

我按照 https://perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes"/perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes

我试图获取一个简单 C 程序的指令数.(如下图)

I tried to get instruction count of a simple C program. (As shown below)

1) 我的简单 C 代码

1) My simple C code

#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() 函数内的指令数.这会导致错误.

3) Trying to use perf stat to measure the instruction count within the func() function. This leads to an error.

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

有人能指出我哪里做错了吗?

Could someone point me where I did wrong?

[我使用的是 linux 内核 3.11.0-12-generic]

[I'm using linux kernel 3.11.0-12-generic]

推荐答案

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

I think that the instructions you are following are not yet included into the mainline Linux kernel. As a consequence, perf is telling you that the events are not supported: perf doesn't know the "toggle" mechanism mentioned on this page.

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

I can see two workarounds:

  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,然后使用此支持编译和运行内核.
  1. If you have access to the source code you want to profile you can use the perf_event_open system call directly from your source code to start and stop counting on function entry and exit.
  2. Clone jolsa repository git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/jolsa/perf switch the core_toggle branch git co remotes/origin/perf/core_toggle and then compile and run the kernel with this support.

关于 2,我对内核版本和开发完全不熟悉,我认为这个解决方案的使用和维护可能很复杂.也许您应该在 perf 用户邮件列表 上询问是否有任何计划将切换功能集成到主线内核中.

Regarding 2, I am not familiar at all with kernel versions and development and I think that this solution may be quie complex to use and maintain. Maybe you should ask on the perf users mailing list if there are any plans for the toggle feature to be integrated into the mainline kernel.

这篇关于使用 perf 探针监视特定功能期间的性能统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆