Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Last active February 28, 2024 04:05
Show Gist options
  • Save bgadrian/a6c164b37318e1101885cf2f9bc6a86e to your computer and use it in GitHub Desktop.
Save bgadrian/a6c164b37318e1101885cf2f9bc6a86e 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