perf in Linux: performance profiling
Updated November 1, 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 stacksSample output
$ perf record -F 999 sha256sum big.bin > /dev/null
[ perf record: Captured and wrote 0.015 MB perf.data (129 samples) ]
$ perf report --stdio
...
# Samples: 129 of event 'task-clock:ppp'
# Event count (approx.): 129129129
#
# Overhead Command Shared Object Symbol
# ........ ......... ................. ..........................
29.46% sha256sum [kernel.kallsyms] [k] __arch_copy_to_user
8.53% sha256sum libcrypto.so.3 [.] 0x000000000025bacc
...How it works: sampling, not counting every step
perfdoes 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'.perfrelies 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.
Common mistakes
perf on Ubuntu is a wrapper script that looks for a binary matching the running kernel. On a kernel that did not come from the distribution (a cloud image, WSL, a virtual machine) it prints WARNING: perf not found for kernel 7.0.11-orbstack, a list of packages that do not exist, and exits 2 having done nothing. Install linux-tools-$(uname -r); when there is no such package, call the binary you already have: /usr/lib/linux-tools-6.8.0-136/perf stat true.
A virtual machine usually has no hardware counters. perf stat then prints the rows but puts <not supported> in place of the numbers for cycles, instructions, branches and branch-misses: the hypervisor did not pass the CPU's PMU to the guest. Software events (task-clock, page-faults, context-switches) still count, so profiling by time works while instructions per cycle does not.
Without debug symbols perf report shows addresses instead of function names: 8.53% sha256sum libcrypto.so.3 [.] 0x000000000025bacc. The library was built stripped and perf has nothing to substitute. The fix is the -dbgsym package for that library; your own program you build with -g -fno-omit-frame-pointer. The line [kernel.kallsyms] [k] __arch_copy_to_user in the same output reads fine: perf takes kernel function names from /proc/kallsyms.
In the book
This topic is covered in full in the chapter Deep performance analysis.