安装pprof
package main
import (
_ "net/http/pprof"
)
func main() {
if err := http.ListenAndServe(":6060", nil); err != nil {
log.Fatal(err)
}
}
采集分析数据
# 浏览器访问 http://127.0.0.1:6060/debug/pprof
采样分析
# cpu占用情况的采样信息
go tool pprof http://127.0.0.1:6060/debug/pprof/profile
# allocs信息
go tool pprof http://127.0.0.1:6060/debug/pprof/allocs
# heap信息
go tool pprof http://127.0.0.1:6060/debug/pprof/heap
# 命令
top -> list -> web
跟踪分析
# trace
wget -o trace.out http://127.0.0.1:6060/debug/pprof/trace && go tool trace trace.out