Help developers profile their go application
- FlameGraph
github.com/uber/go-torch
pacaur -S graphviz
github.com/google/pprof
Please ensure following handler have been enabled by your application in http server.
imports (
...
"net/http/pprof"
...
)
func someFunction(){
...
http.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
http.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
http.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
http.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
http.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
...
}
git clone https://github.com/brendangregg/FlameGraph.git
cp flamegraph.pl /usr/local/bin
go tool pprof --seconds 25 http://localhost:9090/debug/pprof/profile?seconds=25
go get github.com/google/pprof
pacaur -S graphviz
pprof -http=127.0.0.1:9000 /home/alpha/pprof/pprof.main.samples.cpu.001.pb.gz
from arm32v7/golang
RUN go get github.com/google/pprof
RUN apt update && apt install graphviz -y
ENTRYPOINT ["pprof"]
- run
docker run -it -p 9000:9000 --network="host" -v $(pwd):/tmp go-pprof -http=10.10.8.111:9000 /tmp/pprof.main.samples.cpu.001.pb.gz
git clone https://github.com/brendangregg/FlameGraph.git
cp flamegraph.pl /usr/local/bin
go get -v github.com/uber/go-torch
Step 1
# It will capture incoming call in 25s
go tool pprof --seconds 25 http://localhost:9090/debug/pprof/profile
Step 2
# Use your fav stress test tool e.g. tsenart/vegeta
Step 3
# Use web to output the call map
Fetching profile from http://localhost:9090/debug/pprof/profile?seconds=25
Please wait... (25s)
Saved profile in /Users/lihaoquan/pprof/pprof.localhost:9090.samples.cpu.014.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) web
# It will capture 30s incoming call
# Then generate a torch.svg in your current dir
go-torch -u http://localhost:9090 -t 30
- x-axis means the cpu time
- y-axis means sequence of function call
- Read from bottom to top
- Flame color is meaningless