Skip to content

Instantly share code, notes, and snippets.

@jmftrindade
Last active April 5, 2019 15:42
Show Gist options
  • Save jmftrindade/ff3096dd87cf48c7bc86feb317b44a7e to your computer and use it in GitHub Desktop.
Save jmftrindade/ff3096dd87cf48c7bc86feb317b44a7e to your computer and use it in GitHub Desktop.
perf

Useful perf commands

perf holy grail

Example commands

Basic counters with e.g., 10 repetitions:

$ perf stat -r 10 command

Commands below assume

$ pid=`pgrep someprocessofinterest`
$ tts=120  # time to sample

where the execution of someprocessofinterest is appropriately stopped / resumed using the getchar hackish technique.

Cache stats.

$ perf stat -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores,L2-loads,L2-load-misses,L2-stores,LLC-loads,LLC-load-misses,LLC-stores,LLC-prefetches -p $pid sleep ${tts}

For a given process, e.g., BFS app:

$ pid=`pgrep BFS`; perf stat -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores,L2-loads,L2-load-misses,L2-stores,LLC-loads,LLC-load-misses,LLC-stores,LLC-prefetches -p $pid sleep 4

Stack trace.

$ perf record -F 99 -p ${pid} -g -o perf.data --sleep ${tts}

Flame graphs.

Requires downloading Brendan Gregg's FlameGraph scripts. Assuming below is run from directory containing the scripts:

$ data=path/to/perf.data
$ fn=somefunctionofinterest
$ out=/tmp/stack.svg
$ perf script -i ${data} | ./stackcollapse-perf.pl | grep ${fn} | ./flamegraph.pl > ${out}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment