go pprof操作

概述

记录一下 go pprof 的常用操作

获取对应的pprof文件

1
2
3
4
5
6
7
8
9
## 获取应用当前的内存情况
curl '127.0.0.1:4869/debug/pprof/heap' -H 'Host: xx.yy' -o mem.prof

## 采集应用60s内的cpu使用情况
curl '127.0.0.1:4869/debug/pprof/profile?seconds=60' -H 'Host: xx.yy' -o cpu.prof

## 采集应用10s内的goroutine调度与执行情况
curl '127.0.0.1:4869/debug/pprof/trace?seconds=10' -H 'Host: xx.yy' -o r.trace

使用go tool pprof工具进行分析

1
go tool pprof -http :6666 ./mem.prof

针对trace内容可以使用需要使用trace工具:

1
go tool trace -http :7777 ./r.trace

这里文件越大, 解析起来就越慢. 有关trace的分析使用可以参考这篇文章