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

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

问题描述

我正在尝试使用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

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

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

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

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-通用]

[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.

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

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