Go 火焰图分析

go version go1.11.1 darwin/amd64

安装:

1
2
3
$ go get github.com/uber/go-torch
$ cd $GOPATH/src/github.com/uber/go-torch
$ git clone https://github.com/brendangregg/FlameGraph.git

安装测试工具

1
2
3
$ go get github.com/Masterminds/glide
$ cd $GOPATH/src/github.com/uber/go-torch
$ glide install

性能分析工具

glide install如果出现 Update failed for golang.org/x/sys: Cannot detect VCS 这种报错, 可以执行

1
$ glide mirror set https://golang.org/x/sys https://github.com/golang/sys

改变 $HOME/.gilde/mirrors.yaml 的镜像链接即可

运行时完成后输入 web

1
2
3
4
5
6
7
8
9
10
$ go tool pprof --seconds 25 http://localhost:9090/debug/pprof/profile
Fetching profile over HTTP from http://localhost:9090/debug/pprof/profile?seconds=25
Please wait... (25s)
Saved profile in /Users/gpf/pprof/pprof.samples.cpu.002.pb.gz
Type: cpu
Time: Nov 2, 2018 at 11:46am (CST)
Duration: 25s, Total samples = 2.17s ( 8.68%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) web
Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH

出现 Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH 报错, 需要安装 graphviz 在 mac 上就直接 brew install graphviz 即可