Sitemap
Eljay

Eljay

Musician, solopreneur & creator of collideborate.me

Linux Perf (perf_events) Cheat sheet

2 min readOct 28, 2022
Press enter or click to view image in full size
Photo by mostafa meraji on Unsplash

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 sharing
perf 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 statistics
perf script Custom perf tooling
perf 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 analysis
perf lock Lock analysis
perf mem Profile memory access.
perf kmem Kernel memory allocation analysis
perf 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 script
perf script — header -F comm,pid,tid,cpu,time,event,ip,sym,dso,trace

Example for -F option in perf record command
perf record -F 99 -a -g — sleep 30

[To be continued]

--

--

Eljay
Eljay

Written by Eljay

Musician, solopreneur & creator of collideborate.me