植入:
在main包中 import _ "net/http/pprof"
在main函數中添加
go func() {
log.Println(http.ListenAndServe("0.0.0.0:6060", nil))
}()
就這樣兩步就完成了pprof植入
分析:
go tool pprof http://localhost:6060/debug/pprof/heap 查看堆棧

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 http://localhost:6060/debug/pprof/profile 查看30秒內CPU的情況
常用命名跟上面一樣, top10、web
想了解更多可以查閱官網
https://golang.org/pkg/net/http/pprof/
