The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| Measure one command | perf stat -- sleep 10 | View examples |
| Measure one process | sudo perf stat --pid 1234 -- sleep 10 | View examples |
| List available perf events | perf list | View examples |
| List dynamic probes | sudo perf probe --list | View examples |
| Record process call graphs | sudo perf record --call-graph dwarf --pid 1234 -- sleep \
30 | View examples |
| Open a perf report | perf report --stdio --input perf.data | View examples |
| Profile one process live | sudo perf top --pid 1234 | View examples |
| Trace one process syscalls | sudo timeout 10 perf trace --pid 1234 | View examples |
| Locate tracefs | findmnt -t tracefs -o TARGET,SOURCE,OPTIONS | View examples |
| List ftrace tracers | sudo cat /sys/kernel/tracing/available_tracers | View examples |
| List tracepoints | sudo cat /sys/kernel/tracing/available_events | View examples |
| Stream ftrace output | sudo cat /sys/kernel/tracing/trace_pipe | View examples |
| Clear the trace buffer | sudo sh -c ': > /sys/kernel/tracing/trace' | View examples |
| Disable global tracing | sudo sh -c 'echo 0 > /sys/kernel/tracing/tracing_on' | View examples |
| Probe BPF support | sudo bpftool feature probe kernel | View examples |
| List loaded BPF programs | sudo bpftool prog show | View examples |
| List BPF maps | sudo bpftool map show | View examples |
| List matching probes | sudo bpftrace --list 'tracepoint:sched:sched_process_*' | View examples |
| Count process executions | sudo timeout 30 bpftrace -e \
'tracepoint:sched:sched_process_exec { @[comm] = count(); }' | View examples |
| Show bpftrace environment | bpftrace --info | View examples |
| Check kernel lockdown | cat /sys/kernel/security/lockdown | View examples |
| Read perf restrictions | sysctl kernel.perf_event_paranoid kernel.kptr_restrict | View examples |
| Inspect profile artifact | stat --format='%a %U:%G %s %n' perf.data | View examples |
Kernel observability tools can reveal why a system is slow, but they also consume CPU and memory, expose arguments and stack data, and can destabilize production when probes are broad or recursive. Start with counters, scope by PID, cgroup, CPU, event, and duration, estimate cardinality, and arrange automatic cleanup. Kernel version, configuration, lockdown, BTF, symbols, privileges, and container boundaries determine what is available.
Step by step
Detailed examples
Begin with low-overhead counters
perf stat answers whether a workload is CPU-bound, stalled, switching, faulting, or migrating before sampling stacks. Scope to a command, PID, cgroup, or CPU and choose a short interval. Multiplexing occurs when requested events exceed hardware counters, reducing precision; review time-enabled and time-running data.
perf stat -- sleep 10
# Attach only with workload-owner approval:
# sudo perf stat --pid 1234 -- sleep 10
# Record the perf and kernel versions with results:
perf --version
uname -r Discover events on the target kernel
PMU events vary by CPU, tracepoints vary by kernel and modules, and probe symbols depend on debugging information and optimization. Never assume a copied event exists or means the same thing. Dynamic probes are shared kernel state; inventory existing probes before adding or deleting any.
perf list
sudo cat /sys/kernel/tracing/available_events
sudo perf probe --list
bpftrace --info Bound sample frequency, call graphs, scope, and duration
High-frequency sampling and DWARF stack unwinding can materially slow workloads and generate large perf.data files. Start at a modest rate, one PID or cgroup, short duration, and a storage quota. Frame pointers are cheaper when binaries preserve them; DWARF can recover more user stacks at higher cost.
# Confirm disk headroom and approval first.
# sudo perf record --frequency 99 --call-graph dwarf --pid 1234 -- sleep 30
# perf report --stdio --input perf.data
df -h .
ulimit -a Use private trace instances instead of global controls
The top-level tracefs controls and buffer are shared, so changing current_tracer, events, filters, or tracing_on can disrupt another investigation. Trace instances provide separation where supported. Set filters before enabling, use bounded readers, and understand that trace_pipe consumes records while trace is a snapshot.
findmnt -t tracefs -o TARGET,SOURCE,OPTIONS
sudo cat /sys/kernel/tracing/current_tracer
sudo cat /sys/kernel/tracing/tracing_on
sudo cat /sys/kernel/tracing/available_tracers
sudo ls /sys/kernel/tracing/instances Inventory kernel, BTF, programs, maps, and pins
Loaded BPF objects can be owned by networking, security, observability, and orchestration agents. Do not detach or delete by ID merely because an object is unfamiliar. BTF and helper availability affect portability; map memory and pinned objects can outlive the launching process depending on references.
bpftrace --info
sudo bpftool feature probe kernel
sudo bpftool prog show
sudo bpftool map show
sudo bpftool link show
sudo find /sys/fs/bpf -maxdepth 3 -print Control probe fan-out and map cardinality
A one-liner can attach to thousands of probes or create a map key per PID, stack, path, address, or user, consuming unbounded memory. List matches first, constrain predicates, aggregate low-cardinality fields, attach for a fixed duration, and handle SIGTERM cleanup. Reading string arguments may fail or expose secrets.
sudo bpftrace --list 'tracepoint:sched:sched_process_exec'
# Approved 30-second aggregate:
# sudo timeout 30 bpftrace -e 'tracepoint:sched:sched_process_exec { @[comm] = count(); }' Do not weaken host-wide security controls for convenience
perf_event_paranoid, kptr_restrict, lockdown, LSM policy, CAP_PERFMON, CAP_BPF, and CAP_SYS_ADMIN influence access. Lowering sysctls or granting broad capabilities expands observation or kernel attack surface for every affected process. Prefer a tightly controlled tracing service or short privileged session and restore policy afterward.
sysctl kernel.perf_event_paranoid kernel.kptr_restrict
cat /sys/kernel/security/lockdown 2>/dev/null
grep -E '^Cap(Eff|Bnd|Amb):' /proc/self/status
mount | grep -E 'tracefs|bpf' Plan cleanup before attaching probes
Interrupted tools usually detach temporary probes, but crashes, pinned objects, dynamic probes, trace instances, or manually enabled events can remain. Record the pre-change state and object owner, use a timeout, and remove only artifacts created by the session. Clearing global buffers destroys other operators' evidence.
sudo perf probe --list
sudo bpftool prog show
sudo bpftool link show
sudo find /sys/fs/bpf -maxdepth 3 -print
sudo cat /sys/kernel/tracing/tracing_on
sudo cat /sys/kernel/tracing/set_event Protect symbols, stacks, paths, and trace records
Profiles can reveal proprietary symbol names, code layout, command names, filenames, user identifiers, network endpoints, and arguments. perf.data and map dumps are production data. Restrict file permissions, minimize captured fields, use approved retention, and share redacted reports rather than raw traces.
stat perf.data 2>/dev/null
perf buildid-list --input perf.data 2>/dev/null
# Store raw profiles in an access-controlled incident directory.
# Generate a filtered report for wider sharing. Sources and further reading
References
Authoritative documentation used to verify and expand this cheat sheet.
- Linux Kernel Projectperf: Linux Profiling with Performance Countersperf.wiki.kernel.org
- Linux Kernel Projectperf-stat(1) Manual Pageman7.org
- Linux Kernel Projectftrace: Function Tracerkernel.org
- Linux Kernel ProjectBPF Documentationkernel.org
- Linux Kernel Projectbpftool Documentationkernel.org
- bpftrace Projectbpftrace Reference Guidebpftrace.org
Help us improve
Found a typo or missing example?
Tell us what would make this cheat sheet clearer, more complete, or more useful.



