go中有pprof包來作代碼的性能監控,在兩個地方有包:web
net/http/pprof瀏覽器
runtime/pprofsvg
其實net/http/pprof中只是使用runtime/pprof包來進行封裝了一下,並在http端口上暴露出來.性能
1.import 增長net/http/pprof包 spa
import( _ net/http/pprof )
2. 打開http 監聽端口命令行
go func() { log.Println(http.ListenAndServe("localhost:10000", nil)) }()
*瀏覽器能夠打開 http://127.0.0.1:10000/debug/pprof/ 能夠查看各類profile索引debug
1.若是安裝過graphviz直接提交過這步驟,不然能夠到 http://www.graphviz.org/download/下載,並把bin加入到環境變量code
2.查看profile :在命令行輸入 blog
go tool pprof http://localhost:10000/debug/pprof/profile
此後的30秒進入收集profile信息的狀態。索引
30秒後進入pprof的交互模式,而後輸入
web
而後瀏覽器自動彈開到網頁展現svg圖
3.查看已經保存的profile文件
go tool pprof profile C:\Users\user\pprof\pprof.samples.cpu.004.pb.gz
而後也是進入pprof的交互模式,而後輸入web
還能夠查看heap和goroutine
go tool pprof http://localhost:10000/debug/pprof/heap go tool pprof http://127.0.0.1:10000/debug/pprof/goroutine