用 perf stat 统计命令的硬件计数器
查看一次运行的周期、指令、缓存未命中与上下文切换。
运行 perf stat -d ./程序,退出后打印硬件与软件计数器。
01命令
命令
$ perf stat -d ./my-program02作用说明
perf stat 在命令前后读取硬件性能计数器,揭示负载是 CPU 密集、缓存抖动还是停顿。这种底层可见性只有命令行才实用,也是性能剖析留在终端的原因。
03风险
!注意: 部分计数器需放宽 kernel.perf_event_paranoid 或使用 root;结果随系统负载波动。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- perf-stat.1.en.html manual page (Debian bookworm)依据: Documents perf stat and the hardware counters it reports.
最后验证: 2026-10-13 · 分类: 系统与设置