1. gin服务增加pprof路由
增加ginpprof;
"github.com/DeanThompson/ginpprof"
ginpprof.WrapGroup(routerGroup)
启动服务;
2. 浏览器访问测试是否服务启动成功
http://localhost:8877/routerGroup/debug/pprof/
3. go tool pprof 重定向分析profile文件
# 执行命令后,会在浏览器打开一个窗口
go tool pprof -http=:1234 http://localhost:8877/**routerGroup**/debug/pprof/profile
# 简单解释
# -http 表示使用交互式web接口查看获取的性能信息,指定可用的端口即可
# debug/pprof/需要查看的指标 (allocs,block,goroutine,heap,profile...)
从执行命令的过程,可以看到pprof工具从http://localhost:8877/routerGroup/debug/pprof/profile获取监控数据,并保存到本地:/home/jerry/pprof/pprof.___go_build_main_go.contentions.delay.005.pb.gz。然后对该文件进行分析,并启动一个Web服务器:http://localhost:1234/ui 一般会自动弹出一个浏览器并显示结果——默认显示的是graph。但是可以从第一行的菜单中切换View,选择Flame Graph即可显示火焰图