Skip to content

Instantly share code, notes, and snippets.

@gz
Last active October 21, 2023 06:21
Show Gist options
  • Save gz/57d3c4be7c5ae18635f3ded1e7a2deb6 to your computer and use it in GitHub Desktop.
Save gz/57d3c4be7c5ae18635f3ded1e7a2deb6 to your computer and use it in GitHub Desktop.
On using perf

Setup

Avoid annoying security settings:

sudo sh -c 'echo 0 >> /proc/sys/kernel/kptr_restrict'
sudo sh -c 'echo 0 > /proc/sys/kernel/nmi_watchdog'
sudo sh -c 'echo -1 > /proc/sys/kernel/perf_event_paranoid'
echo 1 | sudo tee /proc/sys/kernel/sched_schedstats

Invoke

  • RUSTFLAGS=-g perf record --call-graph dwarf cargo bench ...
  • perf record -p <PID>

CPU utilization is lower than expected?

  • sudo perf record -e sched:sched_stat_sleep -e sched:sched_switch -e sched:sched_process_exit -g -o ~/perf.data.raw ./a.out

Analyze

  • Use Hotspot for correct/fast symbol demangling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment