OnCallReadyStart learning

perf: Performance analysis tools for Linux

perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

What it does

perf uses the kernel's perf_events: hardware counters from the PMU (cycles, instructions, cache misses - absent in many VMs), software events (task-clock, context-switches, page-faults, cpu-clock), tracepoints and probes. On Ubuntu 26.04 it is the linux-perf package. kernel.perf_event_paranoid is 4 on Ubuntu, so it needs root.

Options you will use

--version
print the version (perf version 7.0.x on this kernel).
-h, --help
help.

Examples

$ sudo perf stat -- sleep 5

counters for a command

$ sudo perf stat -p 1210 -- sleep 5

counters for a running process for 5 s

$ sudo perf record -F 99 -g -p PID -- sleep 10

sample a process's stacks for 10 s

$ sudo perf report --stdio --no-children

hot functions by self time

$ sudo perf script > out.perf

samples as text, for a flame graph

Gotchas

Taught in

Try perf in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.