performance - 系统调用硬件性能计数器 ubuntu

标签 performance ubuntu operating-system system-calls perf

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

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

谢谢您的帮助。

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 使用的一样(你引用了它的输出)。

您可以设置硬件事件计数(启用内核计数 - easyperf 中的 PERFMON_EVENTSEL_OS 标志),然后读取计数器的当前值 perf_read_all在包装器中,然后运行要分析的函数(系统调用),然后读取新的计数器值。新旧值之间的差异是目标函数成本的估计。检查这个测试,目标函数是foo :

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

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

关于performance - 系统调用硬件性能计数器 ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149000/

相关文章:

java - 在java中创建新的Json对象与使用redis中的JSON对象

java.awt.container.add(comp) 瓶颈

c# - 区分本质上是Int32的多种类型

ubuntu - golang build -i -a 失败(权限被拒绝)

linux - 如何在没有系统调用的情况下在堆上分配内存?

PHP、Linux、 Apache : naming file based on user input

python - 使用 PyInstaller 创建的应用程序启动缓慢

ubuntu - 将 Ubuntu 上的 puppet 升级到 puppet 5

ubuntu - 解决 IBus 问题 - 1.5.11 之前的 IBus 可能会导致输入问题

python - 使用 Python os 模块获取 unix 文件类型