pporf使用
一、下载pporf
端点 | debug=0 | debug=1 | debug=2 |
/debug/pprof/goroutine | 二进制(pprof 分析) | 简要 Goroutine 堆栈 | 完整 Goroutine 堆栈 |
/debug/pprof/heap | 二进制(pprof 分析) | 内存聚合统计 | 详细堆内存对象 |
/debug/pprof/profile | 二进制(pprof 分析) | 文本 CPU 报告 | 无 |
cpu:
export PPROF_TMPDIR=/home/foo; go tool pprof http://127.0.0.1:31777/debug/pprof/profile?second=30
内存:
- 方式1:
export PPROF_TMPDIR=/home/foo; go tool pprof --inuse_space http://127.0.0.1:31777/debug/pprof/heap?second=30
- 方式2:
curl -GET --unix-socket ./debug.sock "http://localhost/debug/pprof/heap?debuge=0&seconds=30" -o heap_30s.pprof
goroutine
- 下载pb.gz文件并命令行分析:
export PPROF_TMPDIR=./; go tool pprof http://localhost:3/debug/pprof/goroutine
- 下载可视化文本文件:
curl http://localhost:3/debug/pprof/goroutine?debug=1 > goroutine.txt
- debug=1: 可视化文本格式
trace
curl -s http://localhost:1777/debug/pprof/trace?seconds=5 > server-trace.pprof
#
二、分析pporf
cpu:go tool pprof --http=0.0.0.0:9998 pprof.xxx.cpu.008.pb.gz
内存:go tool pprof --http=0.0.0.0:9999 pprof.xxxx.008.pb.gz
goroutine: go tool pprof -http=:8080 pprof.xx.goroutine.xxx.pb.gz
trace: go tool trace server-trace.pprof
三、常见问题
pool池化对象,getslow但不newobject
- 需要跨P获取对象
- 解决:在同一个G中Get\Put对象
This post is licensed under CC BY 4.0 by the author.