首先引用包
import _ "net/http/pprof"
然后,在main中加入
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
启动web程序后,使用curl工具收集一定时间内的数据(假设是20秒)
curl http://localhost:6060/debug/pprof/heap?seconds=20 > heap.out
在此期间,就可以发送请求,最后,对收集到的数据进行分析。
go tool pprof -http=":8081" heap.out