Linux Perf (perf_events) Cheat sheet
I started my journey using perf when I posted a question “What’s the recommended tool to profile Hacklang?” in Hacklang Slack group and Fred one of Meta’s Engineer responded about perfand that’s what I’m going to share. It’s not a tutorial or lesson, it’s a cheat sheet to get started.
Commands:perf c2c Cache-to-cache and cache line false sharingperf diff Read two perf.data files and display the differential profile.perf record Run a command and record its profile into perf.data.perf report Read perf.data (created by perf record) and display the profile.perf script Read perf.data (created by perf record) and display trace output.perf stat Run a command and gather performance counter statistics.perf sched Kernel scheduler statisticsperf script Custom perf toolingperf trace A live tracer (system calls by default).perf top System profiling tool with real-time screen updates.perf timechart Visualize total system behavior during a workload.perf kvm KVM guest analysisperf lock Lock analysisperf mem Profile memory access.perf kmem Kernel memory allocation analysisperf mem Memory access analysis
Get Eljay’s stories in your inbox
Join Medium for free to get updates from this writer.
Options:-a: Record across all CPUs-A: Show per-CPU counts-e event: Record this event(s)-F field(s)|frequency
— filter filter: Set a Boolean filter expression for an event-g options: Modify call graph (stack trace) display options-G cgroup: Record this cgroup only (used for containers)-n: Include a column for sample counts-o output: Set output file-p PID: Record this PID only-t TID: Record this thread ID only-i file: Input file
-I interval_ms: Print output every interval (milliseconds)-v: Show verbose messages; -vv for more messages
List/display all events (Hardware Events, Software Events, Tracepoints & Probe Events)$ perf list
Example for -F option in perf scriptperf script — header -F comm,pid,tid,cpu,time,event,ip,sym,dso,trace
Example for -F option in perf record commandperf record -F 99 -a -g — sleep 30
[To be continued]





