本文介绍了系统调用硬件性能计数器ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,我想在执行文件之前和之后获取系统调用(例如:read())的性能计数器(缓存,TLB等)值.

I am working on a project and I would like to obtain the performance counters(cache, TLB, etc) values of a system call(eg: read()) before and after the execution of a file.

我尝试在Ubuntu上使用perf进行此操作,但无法获得任何结果.有没有办法使用perf或其他工具来做到这一点?

I tried doing this using perf on Ubuntu but was not able to get any results. Is there a way to do it using perf or maybe some other tool ?

感谢您的帮助.

3.329057 task-clock (msec)         #    0.714 CPUs utilized
16 context-switches                #    0.005 M/sec
0 cpu-migrations                   #    0.000 K/sec
257 page-faults                    #    0.077 M/sec
1,983,212 cycles                   #    0.596 GHz
1,352,902 stalled-cycles-frontend  #   68.22% frontend cycles idle
1,080,180 stalled-cycles-backend   #   54.47% backend  cycles idle
1,336,919 instructions             #    0.67  insns per cycle
                                   #    1.01  stalled cycles per insn
       267,730 branches            #   80.422 M/sec
       <not counted> branch-misses

   0.004663489 seconds time elapsed

推荐答案

有小型包装库 https://github .com/castl/easyperf 在计数模式下用于perf_event_open,就像perf stat所使用的(其输出由您引用).

There is small wrapper library https://github.com/castl/easyperf for perf_event_open in counting mode, just like used by perf stat (its output was quoted by you).

您可以设置硬件事件计数(启用内核计数-easyperf中的PERFMON_EVENTSEL_OS标志),然后在包装器中读取计数器perf_read_all的当前值,然后运行要配置的函数(syscall),然后读取新的计数器值.新旧值之间的差异是目标功能成本的估算.检查此测试,目标功能为foo:

You can setup hw event counting (with in kernel counting enabled - PERFMON_EVENTSEL_OS flag in easyperf), then read current values of counters perf_read_all in the wrapper, then run your function (syscall) you want to profile, and then read new counter values. Difference between old and new values is estimation of target function cost. Check this test, target function is foo:

https://github.com/castl/easyperf/blob/master/test.c

您不能测量太小的调用,因为从perf_event_open读取硬件计数器是通过几个read系统调用完成的.因此,请执行几个类似的syscall(循环为100或1000),或者执行更多工作的syscall,或者尝试测量读取的开销以获取硬件计数器(测量空的'foo'函数以获取开销;然后测量目标short函数,然后比较差异.)

You can't measure too small calls, because reading hw counters from perf_event_open is done via several read syscalls. So, do several similar syscalls (loop of 100 or 1000), or do syscalls which does more work, or try to measure overhead of reads to get hw counters (measure empty 'foo' function to get overhead; then measure your target short function, then compare differences.)

这篇关于系统调用硬件性能计数器ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:02