pprof生成Profile和trace文件及使用
1.在代码中添加pprof功能
2. http://127.0.0.1:9090/debug/pprof/ 点击其中的profile下载profile文件。
3. go tool pprof profile命令打开profile文件
进入pprof模式。
此时可以使用pprof相关命令
安装graphviz-2.38.msi配置D:\Program Files (x86)\Graphviz2.38\bin安装目录到PATH环境变量
在pprof模式下输入web即可看到图形化分析。使用powerShell打开pprof模式。
4. 点击trace下载trace文件
在浏览器可以查阅trace文件
Go tool pprof常用基本调试基本命令(默认30s采集时间,可通过--seconds)
HTTP场景(参数可选:--text):
Heap profile:
go tool pprof --text http://localhost:8080/debug/pprof/heap
CPU profile:
go tool pprof --text http://localhost:8080/debug/pprof/profile
Goroutine blocking profile:
go tool pprof --text http://localhost:8080/debug/pprof/block