Using perf for Linux Performance Analysis, Part 1¶
A starting guide to collecting CPU performance data with perf.
This English edition keeps the original illustrations and reproducible command or configuration examples.




Commands and configuration¶
perf probe [<options>] <probe-point> [<probe-point> ...]
# 例子:添加一个探针,在do_sys_open入口插入一个
perf probe do_sys_open
# 带参数的探针
perf probe 'do_sys_open filename'
# 查看已经添加的探针
perf probe -l
# 删除探针
perf probe -d do_sys_open
# 使用探针进行性能分析
# 例子:在系统运行 10 秒钟内记录 do_sys_open 函数的调用,并生成一份性能报告
perf record -e probe:do_sys_open -aR sleep 10
perf report
Usage: perf stat [<options>] [<command>]
# 命令perf stat -p <pid>可以采集某一个进程的运行信息
perf stat -p 344
# 例子: zero文件读取输入写到空设备中,连续写888888个block:
perf stat -B dd if=/dev/zero of=/dev/null count=888888
perf top [<options>]
# 监控指定进程的性能事件
perf top -p 12345
# 监控指定用户的性能事件
perf top -u john
# 监控特定事件
perf top -e cycles
Practical notes¶
Test each change on a recoverable target, keep logs from the boot or failure path, and record the exact kernel and userspace versions used in the result.