
文章插图
有三种方法可以修复这个问题,这里不做展开,这些stack walking techniques后面可以写一篇单独的文章:
- using dwarf data to unwind the stack, 实际上很多profile工具:gperftools, valgrind都是依赖于libunwind,通过dwarf来进行stack trace的
- using last branch record (LBR) if available (a processor feature)
- returning the frame pointers
sub command功能说明
annotate 读取perf.data(由perf record生成)显示注释信息,如果被分析的进程含义debug符号信息,则会显示汇编和对应的源码,否则只显示汇编代码
archive 根据perf.data(由perf record生成)文件中的build-id将相关的目标文件打包,方便在其他机器分析
bench perf提供的基准套件的通用框架,可以对当前系统的调度,IPC,内存访问进行性能评估
buildid-cache 管理build-id,管理对于的bin文件
buildid-list 列出perf.data中的所以buildids
data 把perf.data文件转换成其他格式diff读取多个perf.data文件,并给出差异分析
evlist 列出perf.data中采集的事件列表
kmem 分析内核内存的使用kvm分析
kvm 虚拟机上的guest os
list 列出当前系统支持的所有事件名,可分为三类:硬件事件、软件事件,检查点
lock 分析内核中的锁信息,包括锁的争用情况,等待延迟等
record 对程序运行过程中的事件进行分析和记录,并写入perf.data
report 读取perf.data(由perf record生成) 并显示分析结果
sched 针对调度器子系统的分析工具 。
script 读取perf.data(由perf record生成),生成trace记录,供其他分析工具使用
stat 对程序运行过程中的性能计数器进行统计
test perf对当前软硬件平台进行健全性测试,可用此工具测试当前的软硬件平台是否能支持perf的所有功能 。
timechart 对record结果进行可视化分析输出,record命令需要加上timechart记录
top 对系统的性能进行分析,类型top命令,当然可以对单个进程进行分析
probe 用于定义动态检查点 。
trace 类似于strace,跟踪目标的系统调用,但开销比strace小
perf的使用大体可以有三种方式:
- Counting:统计的方式,统计事件发生的次数,这种方式不生成perf.data文件,例如perf stat, perf top
- Sampling:采样的方式,采样事件,并写入到内核buffer中,并异步写入perf.data文件中,perf.data文件可以被perf report或者perf script 命令读取 。
- bpf programs on events(https://www.ibm.com/developerworks/cn/linux/l-lo-eBPF-history/index.html)
perf list命令可以列出当前perf可用的事件:
cpu-cycles OR cycles [Hardware event]instructions [Hardware event]cache-references [Hardware event]cache-misses [Hardware event]branch-instructions OR branches [Hardware event]branch-misses [Hardware event]bus-cycles [Hardware event]stalled-cycles-frontend OR idle-cycles-frontend [Hardware event]stalled-cycles-backend OR idle-cycles-backend [Hardware event]ref-cycles [Hardware event]alignment-faults [Software event]bpf-output [Software event]context-switches OR cs [Software event]cpu-clock [Software event]cpu-migrations OR migrations [Software event]dummy [Software event]emulation-faults [Software event]major-faults [Software event]minor-faults [Software event]page-faults OR faults [Software event]task-clock [Software event]msr/tsc/ [Kernel PMU event]rNNN [Raw hardware event descriptor]cpu/t1=v1[,t2=v2,t3 ...]/modifier [Raw hardware event descriptor](see 'man perf-list' on how to encode it)mem:<addr>[/len][:access] [Hardware breakpoint]这些事件可以分为三类(在文章开始介绍perf工作原理的时候也说了):Hardware Event, Software event, Tracepoint event.
每个具体事件的含义在perf_event_open的man page中有说明:
- cpu-cycles:统计cpu周期数,cpu周期:指一条指令的操作时间 。
- instructions: 机器指令数目
- cache-references: cache命中次数
- cache-misses: cache失效次数
- branch-instructions: 分支预测成功次数
- branch-misses: 分支预测失败次数
- alignment-faults: 统计内存对齐错误发生的次数,当访问的非对齐的内存地址时,内核会进行处理,已保存不会发生问题,但会降低性能
- context-switches: 上下文切换次数,
- cpu-clock: cpu clock的统计,每个cpu都有一个高精度定时器
- task-clock :cpu clock中有task运行的统计
- cpu-migrations:进程运行过程中从一个cpu迁移到另一cpu的次数
- page-faults: 页错误的统计
推荐阅读
- wireshark网络小故障分析定位
- 笔记本|入门性能可战GTX 1650!用户买不到 Intel Arc显卡本着急了:官方回应
- 详解mysql数据库double write原理、性能影响及相关参数
- centos安装awstats分析apache的日志
- CPU处理器|闲鱼惊现剪角CPU 称502+沙子就能补上 网友:只剩3/4性能了
- 东瀛煮茶利器,日本老铁壶
- 茶叶品牌走高端奢侈品路线分析
- web服务器遭受黑客攻击时的日志分析及排查
- MySQL 多源复制场景分析
- 茶馆的经营模式分析,满足顾客的个性化需求
