Instantly share code, notes, and snippets.

Embed
What would you like to do?
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