1、项目test-pprof中添加代码

import (
   "net/http"
   _ "net/http/pprof"
)
func main() {
        ...
        go func() { 
                http.ListenAndServe("0.0.0.0:6666", nil) 
        }()
        ...
}

2、浏览器访问 http://IP:6666/debug/pprof/

页面显示:

3、点击其中一个链接,比如 profile,等待半分钟左右,有文件profile下载

4、启动一个本地web服务,分析profile文件

go tool pprof -http=0.0.0.0:60000 test-pprof profile

5、浏览器访问 http://IP:60000/ui

6、参考