- perf top:查看当前全部进程及其性能消耗
- sudo perf record:收集性能数据记录到文件,默认为perf.data,也会保留上一次的记录文件perf.data.old
- sudo perf report:对记录文件进行分析,选中指定函数enter可看到调用栈,到最低层调用栈再enter可进入机器码查看对应行数的性能消耗,都采用-g则可找到耗时的对应行。
- -i 指定分析的.data文件
- sudo perf script:保存裸trace数据,直接观察采样点的数据分析
sudo perf annotate:在gcc编译时加入-g,在record后进行annotate,则可看到对应代码行和相关机器码,以及他们的性能消耗
-p 指明检测进程的pid,不指明则检测整个系统
- -t 指明线程pid
- -F 设置采样频率,默认频率为1000。但一般推荐设置为-F 99或-F 999,因为要避免引起lockstep采样:
- 锁步采样是指分析样本以与应用程序中的循环相同的频率出现。 这样做的结果是样本经常出现在循环中的同一位置,因此它会认为操作是最常见的操作,并且可能是瓶颈。
- -a 显示在所有CPU上的性能统计信息
- -c 显示在指定CPU上的性能统计信息
- -g 开启调用栈分析,记录函数间的调用关系
- sleep 等待指定时间后停止,常用于record
- -e
对指定的性能事件event进行分析,事件表见下,默认事件为cpu-cycles。
如:分析pid为123456的cpu-clock情况,延时5秒,并查看函数调用
sudo perf record -p 123456 -g -e cpu-clock sleep 5 (生成perf.data)
sudo perf report -g (进入分析界面)
如:分析可执行文件test
sudo perf record ./test
sudo perf report全部参数:
root@ubuntu:~# perf -h
usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]
The most commonly used perf commands are:
annotate Read perf.data (created by perf record) and display annotated code
archive Create archive with object files with build-ids found in perf.data file
bench General framework for benchmark suites
buildid-cache Manage build-id cache.
buildid-list List the buildids in a perf.data file
c2c Shared Data C2C/HITM Analyzer.
config Get and set variables in a configuration file.
data Data file related processing
diff Read perf.data files and display the differential profile
evlist List the event names in a perf.data file
ftrace simple wrapper for kernel's ftrace functionality
inject Filter to augment the events stream with additional information
kallsyms Searches running kernel for symbols
kmem Tool to trace/measure kernel memory properties
kvm Tool to trace/measure kvm guest os
list List all symbolic event types
lock Analyze lock events
mem Profile memory accesses
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the profile
sched Tool to trace/measure scheduler properties (latencies)
script Read perf.data (created by perf record) and display trace output
stat Run a command and gather performance counter statistics
test Runs sanity tests.
timechart Tool to visualize total system behavior during a workload
top System profiling tool.
version display the version of perf binary
probe Define new dynamic tracepoints
trace strace inspired tool
See 'perf help COMMAND' for more information on a specific command.
annotate | perf annotate用于解析由perf record记录的数据文件perf.data并将代码注解显示。如果源代码开启了debug符号,则源码和汇编一起解析。如果源码未开启debug,则解析汇编代码 |
---|---|
archive | 根据数据文件记录的build-id,将所有被采样到的elf文件打包。利用此压缩包,可以再任何机器上分析数据文件中记录的采样数据。 |
bench | perf中内置的benchmark。子系统:调度器和IPC机制、内存管理、NUMA调度、futex压力基准、epoll压力基准等 |
buildid-cache | 管理perf的buildid缓存,每个elf文件都有一个独一无二的buildid。buildid被perf用来关联性能数据与elf文件。 |
buildid-list | 列出perf.data文件中的buildid |
c2c | 用于调试cache to cache的false sharing问题,用于Shared Data C2C/HITM分析,可以追踪cacheline竞争问题 |
config | perf config用于读取和配置 .perfconfig配置文件 |
diff | 对比两个数据文件的差异。能够给出每个符号(函数)在热点分析上的具体差异。 |
evlist | 列出数据文件perf.data中所有性能事件 |
ftrace | 是内核ftrace功能的简化封装,可以跟踪指定进程的内核函数调用栈 |
inject | 该工具读取perf record工具记录的事件流,并将其定向到标准输出 |
kallsyms | 查找运行中的内核符号 |
kmem | 针对内核内存(slab)子系统进行追踪测量的工具 |
kvm | 用于测试kvm客户机的性能参数 |
list | 列出event事件 |
lock | 分析内核锁统计信息 |
mem | 测试内存存取性能数据 |
record | 运行一个命令,并将其数据保存到perf.data中。随后,可以使用perf report进行分析 |
report | 显示perf数据 |
sched | 分析调度器性能 |
script | 执行测试脚本 |
stat | perf stat能完整统计应用整个生命周期的信息 |
test | 用于sanity test |
timechart | 生成图标 |
top | 类似linux的top命令,查看整体性能 |
version | 查看版本信息 |
probe | 动态监测点 |
trace | 跟踪系统调用 |
更详细的参考资料:
原文链接:https://blog.csdn.net/qq_23662505/article/details/114669615