Skip to content

Instantly share code, notes, and snippets.

@aroben
Created March 6, 2017 21:20
Show Gist options
  • Save aroben/65d67a3eb8942b4d1ec033e72437ac13 to your computer and use it in GitHub Desktop.
Save aroben/65d67a3eb8942b4d1ec033e72437ac13 to your computer and use it in GitHub Desktop.
Script to generate flamegraphs from Ruby stackprof profiles
#!/bin/sh
# First generate a profile using https://github.com/tmm1/stackprof
# StackProf.run(raw: true, out: "tmp/stackprof.dump) { something_expensive }
# Then run this script
# $ stackprof-to-flamegraph tmp/stackprof.dump
set -e
if [ "$STACKCOLLAPSE" = "1" ]; then
template="/tmp/stackprof-$$"
stackcollapse="$template-stackcollapse.txt"
flamegraph="$template-flamegraph.svg"
width=4800
stackprof --stackcollapse "$1" > "$stackcollapse"
stackprof-flamegraph.pl --hash --width $width --title "$1" "$stackcollapse" > "$flamegraph"
open -a Safari "$flamegraph"
else
stackprof --flamegraph "$1" > "$1.flamegraph"
stackprof --flamegraph-viewer "$1.flamegraph" | sed -e 's/^open //' | pbcopy
echo "URL copied to clipboard"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment