Linux performance analysis and profiling tool.
low risk
perf is the Linux performance profiling tool, using hardware counters and kernel tracepoints. It records CPU samples, tracks cache misses, counts system calls, and generates flame graphs. Essential for diagnosing performance bottlenecks at the CPU/kernel level.
| Flag | Meaning |
|---|---|
top | Real-time performance counter display |
stat | Run command and print performance statistics |
record | Record performance data to perf.data |
report | Analyze recorded perf.data |
script | Format perf.data for flame graph generation |
perf topLive CPU usage by function (like top for CPU functions) · explain & risk-check →perf stat -p 1234Count hardware events for a running process · explain & risk-check →perf record -g -p 1234 sleep 30Record 30 seconds of call stacks for a process · explain & risk-check →perf report --stdioDisplay top CPU-consuming functions from recording · explain & risk-check →perf stat -e cache-misses,cache-references myprogramMeasure cache miss rate · explain & risk-check →Combine `perf record -g` with FlameGraph scripts (`perf script | stackcollapse-perf.pl | flamegraph.pl > flame.svg`) to generate visual CPU flame graphs — the most powerful way to find hot code paths.
Reference text is hand-written and may be incomplete — check man perf for your version. Test destructive commands on a non-production system first.