perf 工具介绍2
2015-11-06 21:40
183 查看
[root@localhost ~]# cat test1.c void longa() { int i,j; for(i = 0; i < 1000000; i++) j=i; //am I silly or crazy? I feel boring and desperate. } void foo2() { int i; for(i=0 ; i < 10; i++) longa(); } void foo1() { int i; for(i = 0; i< 100; i++) longa(); } int main(void) { foo1(); foo2(); }
[root@localhost ~]# gcc -g -o t1 test1.c
[root@localhost ~]# perf stat ./t1 Performance counter stats for './t1': 288.130025 task-clock-msecs # 0.980 CPUs 0 context-switches # 0.000 M/sec 0 CPU-migrations # 0.000 M/sec 85 page-faults # 0.000 M/sec 0 cycles # 0.000 M/sec 0 instructions # 0.000 IPC 0 cache-references # 0.000 M/sec 0 cache-misses # 0.000 M/sec 0.294152404 seconds time elapsed
程序 t1 是一个 CPU bound 型,因为 task-clock-msecs 接近 1。
对 t1 进行调优应该要找到热点 ( 即最耗时的代码片段 ),再看看是否能够提高热点代码的效率。
缺省情况下,除了 task-clock-msecs 之外,perf stat 还给出了其他几个最常用的统计信息:
Task-clock-msecs:CPU 利用率,该值高,说明程序的多数时间花费在 CPU 计算上而非 IO。
Context-switches:进程切换次数,记录了程序运行过程中发生了多少次进程切换,频繁的进程切换是应该避免的。
Cache-misses: 程序运行过程中总体的 cache 利用情况,如果该值过高,说明程序的 cache 利用不好
CPU-migrations : 表示进程 t1 运行过程中发生了多少次 CPU 迁移,即被调度器从一个 CPU 转移到另外一个 CPU 上运行。
Cycles: 处理器时钟,一条机器指令可能需要多个 cycles,
Instructions: 机器指令数目。
IPC:是 Instructions/Cycles 的比值,该值越大越好,说明程序充分利用了处理器的特性。
Cache-references: cache 命中的次数
Cache-misses: cache 失效的次数。
通过指定 -e 选项,您可以改变 perf stat 的缺省事件,查看您所感兴趣的特殊的事件
相关文章推荐
- On Hat Puzzle 2.1: From Dr. Todd Ebert's thesis
- hdu 4665 Unshuffle(暴力)
- android4.3-android4.4.2触摸唤醒
- 计算机原理之c语言实现链表
- LeetCode16:3Sum Closest
- Android中的webview详细使用
- 大端小端的判断
- 去掉 WordPress 3.1+版本顶部的admin bar管理工具
- Linux时间函数
- 为什么有logistics函数
- Matlab “Out of memory”解决办法
- Libev源码分析06:异步信号同步化--sigwait、sigwaitinfo、sigtimedwait和signalfd
- hdu 4664 Triangulation(博弈)
- 地理位置查询附近商家
- adb常用命令
- ecshop中smarty最常用的6大基本语法
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- 操作系统与网络实现 之七
- c++虚函数
- 指针、数组