Sample CPU Usage With perf record

Record call graphs, then inspect hotspots with perf report.

LinuxProcessesmonitoringperformanceDiagnosticsLow risk
Run perf record -g -- ./program, then perf report to explore the samples.

01Command

Command
$ perf record -g -- ./my-program

02What it does

perf record samples the stack at intervals and writes a data file that perf report or a flame-graph tool turns into hotspots. It answers where time is actually spent without modifying the program, and it is inherently a script and terminal workflow.

03Risk

RiskLow risk
Requirementssudo apt install linux-perf
!Warning: Sampling can be security-sensitive on shared hosts; restrict access to perf_event_open appropriately.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: System & Settings

06Related solutions