Perf详解编程语言
Perf 是内置于Linux 内核源码树中的性能剖析(profiling)工具
基于事件采样原理,以性能事件为基础,支持针对处理器相关性能指标与操作系统相关性能指标的性能剖析
可用于性能瓶颈的查找与热点代码的定位
ubuntu 16.04安装perf
1. perf stat
perf stat通过概括精简的方式提供被调试程序运行的整体情况和汇总数据
t1.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(); }
编译
gcc -o t1 -g t1.c
perf stat针对t1
perf stat ./t1
Performance counter stats for ./t1 :
230.236550 task-clock (msec) # 0.998 CPUs utilized
10 context-switches # 0.043 K/sec
0 cpu-migrations # 0.000 K/sec
39 page-faults # 0.169 K/sec
not supported cycles
not supported stalled-cycles-frontend
not supported stalled-cycles-backend
not supported instructions
not supported branches
not supported branch-misses
0.230743761 seconds time elapsed
说明:
task-clock (msec):用于执行程序的CPU时间
context-switches:程序在运行过程中发生的上下文切换次数
cpu-migrations:程序在运行过程中发生的CPU迁移次数,即被调度器从一个CPU转移到另外一个CPU上运行
page-faults:缺页
cycles:CPU时钟周期
instructions:该进程在这段时间内完成的CPU指令
branches:这段时间内发生分支预测的次数
branches-misses:这段时间内分支预测失败的次数
perf record可以记录系统或软件一段时间内的事件统计情况,再通过perf report进行文本界面的展示
用perf record -F count 来指定采样频率
sudo perf record -F 50000 -e cpu-clock ./t1
[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.029 MB perf.data (525 samples) ]
perf report
2.perf top
perf top 用于实时显示当前系统的性能统计信息
t2.c
int main(){ int i; while(1) i++; }
编译
gcc -o t2 -g t2.c
运行
./t2
另起一个窗口
sudo perf top
Samples: 71K of event cpu-clock , Event count (approx.): 7612723453
Overhead Shared Object Symbol
99.56% t2 [.] main
0.18% [kernel] [k] e1000_alloc_rx_buffers
0.07% [kernel] [k] __do_softirq
0.02% [kernel] [k] e1000_xmit_frame
0.02% [kernel] [k] e1000_watchdog
0.02% [kernel] [k] 0x00007fff81854c95
0.01% [kernel] [k] vsnprintf
……
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20331.html
cjavalinux相关文章
- python多线程模块threading使用范例代码详解编程语言
- 基于jQuery的圆环进度条函数封装详解编程语言
- 倒计时的一段JS脚本详解编程语言
- HTML5页面点击和左右滑动页面滚动详解编程语言
- MD5Util、SHA1Util、HmacMD5Util、HmacSHAUtil详解编程语言
- SpringBoot(L)详解编程语言
- 观察者模式详解编程语言
- python3开发进阶-Django框架的ORM常用字段和参数详解编程语言
- python与MySQL详解编程语言
- spring 的OpenSessionInViewFilter简介详解编程语言
- Spring Aop 源码实现原理分析详解编程语言
- android and webview详解编程语言
- libsvm中java.lang.NoSuchFieldException: rand详解编程语言
- 使用前必须注意的几个Linux 命令详解编程语言
- 中国传统色彩十六进制颜色码图片大全详解编程语言
- JDK提供的四种线程池详解编程语言
- Java Base64加密解密详解编程语言
- 读取配置文件参数详解编程语言
- Java导出Excel表(poi)名中文乱码问题处理详解编程语言
- Java多个PDF合并详解编程语言
- Struts2笔记–文件上传详解编程语言
- thymeleaf 传参到js的onclick事件中详解编程语言
- 程序中条用其他程序中已经存在的PERFORM详解编程语言
- BINARY SEARCH in read table statement详解编程语言
- PHP写接口需要注意的问题详解编程语言
- abap中,选择屏幕的折叠按钮详解编程语言
- xadmin系列之单实例模式详解编程语言
- collections系列之OrderedDict【有序字典】与DefaultDict【默认字典】详解编程语言