perf

Linux performance analysis and profiling tool.

low risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

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.

Common flags
FlagMeaning
topReal-time performance counter display
statRun command and print performance statistics
recordRecord performance data to perf.data
reportAnalyze recorded perf.data
scriptFormat perf.data for flame graph generation
Examples
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 →
Pro tip

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.

Related
strace vmstat iotop
Open the full explainer →More in Debugging & Performance

Reference text is hand-written and may be incomplete — check man perf for your version. Test destructive commands on a non-production system first.