Skip to content

Instantly share code, notes, and snippets.

@adampolar
Last active August 24, 2018 14:23
Show Gist options
  • Save adampolar/a41540e50e0173049b0e8122ee3faf93 to your computer and use it in GitHub Desktop.
Save adampolar/a41540e50e0173049b0e8122ee3faf93 to your computer and use it in GitHub Desktop.
Quick and dirty shell script to get some pngs from the go test tool and pprof
#!/bin/bash
#get file name
number=0
suffix="$( printf -- '-%02d' "$number" )"
while test -e "memprofile$suffix.png" || test -e "cpuprofile$suffix.png" || test -e timeprofile$suffix.txt; do
((++number))
suffix="$( printf -- '-%02d' "$number" )"
done
testregex=${1:-.}
go test -bench=$testregex -memprofile mem.out -cpuprofile cpu.out > timeprofile$suffix.txt
if [ -e cpu.out ]
then
go tool pprof -png cpu.out > cpuprofile$suffix.png
fi
if [ -e mem.out ]
then
go tool pprof -png -alloc_space mem.out > memprofile$suffix.png
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment