linux perf

来源:互联网 发布:5g网络手机的最新消息 编辑:程序博客网 时间:2024/06/05 15:49

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 示例


原创粉丝点击