Skip to content

Instantly share code, notes, and snippets.

@cedricpinson
Created August 2, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedricpinson/9f5f0c11630212d1377ff396a6b41f8b to your computer and use it in GitHub Desktop.
Save cedricpinson/9f5f0c11630212d1377ff396a6b41f8b to your computer and use it in GitHub Desktop.
helper to flamegraph a command
# macos fix to run dtrace
# https://apple.stackexchange.com/questions/208762/now-that-el-capitan-is-rootless-is-there-any-way-to-get-dtrace-working
# https://github.com/brendangregg/FlameGraph
# http://www.brendangregg.com/DTrace/DTrace-cheatsheet.pdf
function flamegraph
if test (count $argv) -eq 0
echo usage: flamegraph command [args]
return 1
end
set stacks /tmp/out.stacks
sudo rm -f $stacks 2>/dev/null
set program (basename "$argv[1]")
set pdtrace 'profile-99 /execname == "'$program'" && arg1/ { @[ustack()] = count(); }'
sudo dtrace -x ustackframes=100 -n "$pdtrace" -o $stacks -c "$argv"
if test $status -eq 0
# git clone https://github.com/brendangregg/FlameGraph in your ~/dev/ or adjust the path
~/dev/FlameGraph/stackcollapse.pl $stacks > /tmp/out.folded
~/dev/FlameGraph/flamegraph.pl /tmp/out.folded > ./flamegraph.svg
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment