Skip to content

Instantly share code, notes, and snippets.

@mallipeddi
Created January 8, 2015 01:50
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 mallipeddi/24bd367932d6259fedcb to your computer and use it in GitHub Desktop.
Save mallipeddi/24bd367932d6259fedcb to your computer and use it in GitHub Desktop.
go pprof helper script
#!/bin/bash
BINARY=$1
HOST=$2
PORT=$3
DURATION=$4
echo "Forwarding port..."
ssh -t -t -L$PORT:localhost:$PORT $HOST &
SSH_PID=$!
sleep 3
echo "Starting profile..."
curl "http://localhost:$PORT/<INSERT-PATH>/pprof/profile?seconds=$DURATION" > /tmp/profile
echo "Downloading profile..."
scp /tmp/profile default:/tmp/
rm /tmp/profile
echo "Terminating ssh (pid=$SSH_PID)..."
kill -TERM $SSH_PID
echo "Processing profile..."
ssh default -- "go tool pprof --pdf /tmp/$BINARY /tmp/profile > /tmp/profile.pdf"
scp default:/tmp/profile.pdf /tmp/
open /tmp/profile.pdf
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment