perf Cheatsheet

CPU profiling.

Overview

perf is the Linux kernel's profiling and tracing tool, kernel-resident and present on every modern distribution. Five primitives carry most operational use under load: CPU profiling, hardware-event counters, kernel and userspace tracepoints, flame-graph visualisation, live perf top for in-the-moment investigation. Fluency turns "the system is slow" into a specific function name within minutes.

The approach

Live first, recorded sample second, flame graph for the report. Five idioms cover most operational use of perf and they are worth committing to muscle memory before the box is on fire.

Why this compounds

Each profile teaches the team's performance model. Hot code paths become legible, optimisation targets become specific, microarchitecture concerns (cache behaviour, branch prediction) move from theoretical to measurable. By year two, perf is the first tool reached for any "is the box ok" investigation.