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 5counters for a command
$ sudo perf stat -p 1210 -- sleep 5counters for a running process for 5 s
$ sudo perf record -F 99 -g -p PID -- sleep 10sample a process's stacks for 10 s
$ sudo perf report --stdio --no-childrenhot functions by self time
$ sudo perf script > out.perfsamples as text, for a flame graph
Gotchas
- <not supported> for cycles or instructions = no PMU events (a VM): use software events.
- Permission errors print the current perf_event_paranoid value: on Ubuntu run perf with sudo.
- perf.data is owned by whoever ran perf record; perf report as another user refuses a file it does not own (use -f to force).
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.