Skip to content

Instantly share code, notes, and snippets.

@omerkaya1
Created October 29, 2022 10:45
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 omerkaya1/f0dbcdc90f6c1ab4087a4ad0217f132f to your computer and use it in GitHub Desktop.
Save omerkaya1/f0dbcdc90f6c1ab4087a4ad0217f132f to your computer and use it in GitHub Desktop.
Simple script to collect Go app's profile
#!/bin/bash
BRANCH=$(git branch --show-current)
COMMIT_HASH=$(git rev-parse --short HEAD)
for i in {1..5} ; do
printf "Phase %s\n" "$i"
if ! curl -s "localhost:8000/debug/pprof/heap" > mem-"$BRANCH"-"$COMMIT_HASH"-"$(date "+%Y-%m-%d-%H-%M-%S")".pprof
then
echo "failed to get mem profile"
fi
if ! curl -s "localhost:8000/debug/pprof/profile?seconds=5" > cpu-"$BRANCH"-"$COMMIT_HASH"-"$(date "+%Y-%m-%d-%H-%M-%S")".pprof
then
echo "failed to get cpu profile"
fi
# TODO: check the error!
if ! curl -s "localhost:8000/debug/pprof/goroutine?seconds=5" > gr-"$BRANCH"-"$COMMIT_HASH"-"$(date "+%Y-%m-%d-%H-%M-%S")".pprof
then
echo "failed to get goroutine profile"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment