linux perf

perf是一个性能分析的tool. 类似ftrace都是/proc/等接口来获取内核的信息。

常用命令:

perf list   #列出所有能够触发perf采样点的事件

$ perf list 

List of pre-defined events (to be used in -e):  

cpu-cycles OR cycles [Hardware event] instructions [Hardware event] … 

cpu-clock [Software event] task-clock [Software event] context-switches OR cs [Software event] … 

ext4:ext4_allocate_inode [Tracepoint event] kmem:kmalloc [Tracepoint event] module:module_load [Tracepoint event] workqueue:workqueue_execution [Tracepoint event] sched:sched_{wakeup,switch} [Tracepoint event] syscalls:sys_{enter,exit}_epoll_wait [Tracepoint event] …


perf stat #用于统计一个命令执行过程中事件信息

perf stat [<options>] [<command>]

options:

-e, --event <event>

-p, --pid <n>

...

$perf stat ./t1 
 Performance counter stats for './t1': 

 262.738415 task-clock-msecs # 0.991 CPUs 
 2 context-switches # 0.000 M/sec 
 1 CPU-migrations # 0.000 M/sec 
 81 page-faults # 0.000 M/sec 
 9478851 cycles # 36.077 M/sec (scaled from 98.24%) 
 6771 instructions # 0.001 IPC (scaled from 98.99%) 
 111114049 branches # 422.908 M/sec (scaled from 99.37%) 
 8495 branch-misses # 0.008 % (scaled from 95.91%) 
 12152161 cache-references # 46.252 M/sec (scaled from 96.16%) 
 7245338 cache-misses # 27.576 M/sec (scaled from 95.49%) 

  0.265238069 seconds time elapsed 



perf top #用于观察整个系统当前的状态


perf record #用于细粒度的统计信息,会生成一个perf.data统计文件,可用perf report输出信息

usage: perf record [<options>] [<command>]
    or: perf record [<options>] -- <command> [<options>]

options:

-e, --event <event>

-p, --pid <n> record events on existing process id

-g, --call-graph      do call-graph (stack chain/backtrace) recording

...

图 2. perf report 示例


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值