Skip to content

Instantly share code, notes, and snippets.

Last active January 16, 2022 16:05
What would you like to do?
macOS Perf Approaches

Remember to compile with debug.

Use DTrace - onCPU

  1. Clone

  2. Trace command sudo dtrace -c '<command>' -o out.stacks -n 'profile-997 /execname == "<command name>"/ { @[ustack(100)] = count(); }' > /dev/null

  3. Create Graph FlameGraph/ out.stacks | FlameGraph/ > graph1.svg

Cons, won't tell you what took the longest, just what used the most CPU time. - elapsed time

Doesn't care whether it's IO, CPU etc, will show you where your time slow downs are. Resulting output is can be selectivley collapsed/expanded to zoom in to affected parts.

In-code for Rust


It's programmable for more specific investigations. Only onCPU for now.

Simple example:

let guard = pprof::ProfilerGuard::new(100).unwrap();

<do some stuff>

if let Ok(report) = {
  let file = File::create("flamegraph.svg").unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment