Skip to content

Instantly share code, notes, and snippets.

@ttacon
Created November 30, 2016 15:55
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 ttacon/c69ae8d90493132ce63e716ad3be066a to your computer and use it in GitHub Desktop.
Save ttacon/c69ae8d90493132ce63e716ad3be066a to your computer and use it in GitHub Desktop.
perf.sh - Bash template for building flamegraphs of node process on remote instances
#!/bin/bash
#
# See: https://mixmax.com/blog/determining-why-that-server-is-on-fire for usage.
#
###########
echo "installing perf..."
sudo yum install -y perf
echo "fixing file perms..."
sudo chown root /tmp/perf-*.map
DUR=DURATION # this is replaced by profile.sh
PIDS=$(PID_MATCHER) # this is replaced by profile.sh
echo "collecting info for $DUR seconds..."
echo "collecting info on $PIDS..."
sudo perf record -F 99 -o perf.data -p $PIDS -g -- sleep $DUR
echo "running perf..."
sudo perf script -i perf.data > out.nodestacks01
echo "cloning flamegraph..."
git clone --depth 1 http://github.com/brendangregg/FlameGraph
cd FlameGraph
echo "creating flamegraph..."
./stackcollapse-perf.pl < ../out.nodestacks01 | ./flamegraph.pl > ../flame.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment