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

编程入门 行业动态 更新时间:2024-10-11 05:31:10
本文介绍了在特定功能期间使用性能探针监视性能统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用linux perf工具监视特定功能期间的性能统计信息.

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

我正在按照 https:/中给出的说明进行操作/perf.wiki.kernel/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:

  • 如果您有权访问要配置的源代码,则可以使用 perf_event_open 直接从您的源代码进行系统调用以开始和停止依靠函数的进入和退出.
  • 克隆jolsa存储库git clone kernel.googlesource/pub/scm/linux/kernel/git/jolsa/perf切换core_toggle分支git co remotes/origin/perf/core_toggle,然后在此支持下编译并运行内核.
  • 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.
  • Clone jolsa repository git clone kernel.googlesource/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.

    更多推荐

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

    本文发布于:2023-11-24 11:48:00,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1625080.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:性能   探针   统计信息   功能   在特定

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!