Created
August 2, 2020 18:13
-
-
Save cedricpinson/9f5f0c11630212d1377ff396a6b41f8b to your computer and use it in GitHub Desktop.
helper to flamegraph a command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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