Skip to content

Instantly share code, notes, and snippets.

@EmperorEarth
Forked from bgadrian/GolangCPUProfiles.sh
Created March 4, 2019 11:20
Show Gist options
  • Save EmperorEarth/4afad59557504d3514c279c658f19b63 to your computer and use it in GitHub Desktop.
Save EmperorEarth/4afad59557504d3514c279c658f19b63 to your computer and use it in GitHub Desktop.
Golang Flame graph profiles
#install FlameGraph library
cd /opt/
sudo git clone https://github.com/brendangregg/FlameGraph.git
#make it accesible from any folder
vim ~/.bashrc
##add these lines anywhere and exit vim (if you can)
export FLAMEPATH=/opt/FlameGraph
PATH=$PATH:$FLAMEPATH
#Golang - go-torch pprof alternative for flame graphs profiles
#see https://github.com/uber/go-torch
go get github.com/uber/go-torch
#install Graphviz (for go tool pprof export)
go get github.com/awalterschulze/gographviz
sudo apt-get install graphviz #works in ubuntu, for others see http://www.graphviz.org/
#GENERATE a FLAMEGRAPH from a GOLANG BENCHMARK
#if your benchmark is called: BenchmarkProcessThreadPool50()
#your package name (current folder) is called "AlfaGo"
#the followign command will generate 2 files: "AlfaGo.test" and "Thread50.gz"
go test -bench=ProcessThreadPool50 -cpuprofile=Thread50.gz
#rename the binary for posterity
mv AlfaGo.test Thread50.test
#generate a flamegraph svg
go-torch -f "Thread50Flame.svg" Thread50.test Thread50.gz
#generate a pprof svg graph
go tool pprof -svg -output "Thread50Graph.svg" hread50.test Thread50.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment