Remember to compile with debug.
-
Trace command
sudo dtrace -c '<command>' -o out.stacks -n 'profile-997 /execname == "<command name>"/ { @[ustack(100)] = count(); }' > /dev/null
-
Create Graph
FlameGraph/stackcollapse.pl out.stacks | FlameGraph/flamegraph.pl > graph1.svg
Cons, won't tell you what took the longest, just what used the most CPU time.
https://stackoverflow.com/questions/11445619/profiling-c-on-mac-os-x/11445777#11445777
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.
Use https://docs.rs/pprof/latest/pprof/
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) = guard.report().build() {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
};