Frequently Asked Question

What does perf do that other tools don't, and how do I get started?

perf is the kernel's official profiler. It taps into the CPU's hardware performance monitoring counters (PMCs), registers that count cycles, instructions, cache misses, branch mispredictions, TLB misses, and a hundred other low-level events, and samples them at high frequency with very low overhead. Other tools (top, ps, pidstat) measure outcomes; perf measures causes. When you need to know which function in your program is hot, or why the CPU's instructions-per-cycle has dropped, perf is the only tool that can tell you.

Three subcommands cover most needs. sudo perf stat ./myprog gives a summary counter readout: cycles, instructions, branches, branch misses, page faults, context switches, IPC. sudo perf top is a live, per-function CPU profile, top for hot spots. sudo perf record -g -F 99 ./myprog then perf report records a 99 Hz profile with call stacks and gives an interactive flame-graph-style browser. The recorded perf.data also feeds Brendan Gregg's FlameGraph scripts. Install it from linux-tools-common (Debian) or perf (Fedora/RHEL).

Video

Further reading and video