植入:
在main包中 import _ "net/http/pprof"在main函数中添加
go func() {
log.Println(http.ListenAndServe("0.0.0.0:6060", nil)) }()就这样两步就完成了pprof植入
分析:
go tool pprof 查看堆栈
top10
自动弹出网页展示svg图,如果 报错:Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in %PATH% 请到http://www.graphviz.org/Download.php下载Graphviz, 并配置到环境变量中 svg图如下
go tool pprof 查看30秒内CPU的情况 常用命名跟上面一样, top10、web 想了解更多可以查阅官网 https://golang.org/pkg/net/http/pprof/