Linuxlab

perf in Linux: performance profiling

Updated July 3, 2026

perf shows where processor time goes: which functions in a program or the kernel run most often.

Syntax

perf SUBCOMMAND [options]

Common cases

perf stat ./app            # a summary: cycles, cache misses, branches
perf top                   # a live top of hot functions on the system
perf record ./app          # record a profile into perf.data
perf report                # break the recording down by function
perf record -g ./app       # -g capture call stacks

How it works: sampling, not counting every step

perf does not count every instruction - that would be far too expensive. It works by sampling: many times a second it interrupts the processor and records which function is running at that moment. The more often a function shows up, the more time it eats. From these samples a profile is built: where it is 'hot'. perf relies on the processor's own performance counters, so it sees cache misses and branches too. From its recordings with stacks (-g) people build readable flame graphs. Access to the counters needs privileges the sandbox does not have.

In the book

This topic is covered in full in the chapter Deep performance analysis.

See also

The vmstat command, Load average, Tracing: strace.