๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก Performance & Debugging October 19, 2026 13

Linux Command: perf

Linux kernel performance profiler and analyzer

Terminal โ€” Performance & Debugging
Command
$ sudo perf stat -d ./myapp

The perf command is the official Linux kernel performance analysis tool. It provides access to hardware performance counters (CPU cycles, cache misses, branch mispredictions), software events (page faults, context switches), tracepoints, and dynamic probes for comprehensive system and application profiling. perf is the most powerful performance analysis tool available on Linux, used by kernel developers, application developers, and system administrators to identify bottlenecks, optimize code, and debug performance regressions. It operates with minimal overhead compared to traditional profilers, making it suitable for production system analysis. Key capabilities include CPU profiling (finding which functions consume the most CPU time), memory profiling (cache miss analysis), I/O latency analysis, lock contention detection, and system-wide tracing. perf can profile both user-space applications and kernel code, providing end-to-end visibility. The perf tool suite includes several subcommands: perf stat (event counting), perf record/report (sampling profiler), perf top (live profiling), perf trace (syscall tracer), perf bench (benchmarks), and perf script (for generating FlameGraphs).

Syntax

perf [OPTIONS] COMMAND [ARGS]

Key Options

  • stat โ€” Count events for a command (cycles, instructions, cache misses)
  • record โ€” Sample and record profiling data
  • report โ€” Display profiling report from recorded data
  • top โ€” Live system-wide profiling (like top for CPU functions)
  • trace โ€” Trace system calls (like strace but faster)
  • bench โ€” Run built-in benchmarks (sched, mem, numa)

Examples

Quick performance overview

sudo perf stat -d ./myapp

Profile CPU usage

sudo perf record -g -p $(pgrep myapp) -- sleep 30 && sudo perf report

Live system-wide profiling

sudo perf top -g

Pro Tips

  • For meaningful function names in reports, install debug symbols: apt install linux-tools-$(uname -r) and application-specific -dbg packages.
  • Most perf commands need root. For user access: sysctl kernel.perf_event_paranoid=-1 (security risk) or add user to perf_users group.
  • perf data is best visualized as FlameGraphs. Clone github.com/brendangregg/FlameGraph, then: perf script | stackcollapse-perf.pl | flamegraph.pl > flame.svg

Learn more: Full perf reference โ†’

Share this tip