性能分析
PProf 各项指标含义
- heap: 报告内存分配样本;用于监视当前和历史内存使用情况,并检查内存泄漏。
- threadcreate: 报告了导致创建新OS线程的程序部分。
- goroutine: 报告所有当前goroutine的堆栈跟踪。
- block: 显示goroutine在哪里阻塞同步原语(包括计时器通道)的等待。默认情况下未启用,需要手动调用runtime.SetBlockProfileRate启用。
- mutex: 报告锁竞争。默认情况下未启用,需要手动调用runtime.SetMutexProfileFraction启用。
使用方式
方式一
go tool pprof "http://127.0.0.1:5229/debug/pprof/profile"
方式二
curl http://127.0.0.1:5229/debug/pprof/profile > xx.profile
curl http://127.0.0.1:5229/debug/pprof/heap > xx.heap
go tool pprof xx.profile
go tool pprof xx.heap
curl http://127.0.0.1:5227/debug/pprof/profile > xx.profile
curl http://127.0.0.1:5227/debug/pprof/heap > xx.heap
go tool pprof xx.profile
go tool pprof xx.heap
高级
go tool pprof -cum -filefunctions xx.profile
go tool pprof -cum -focus=pprofname xx.profile
参数说明
- flat:当前函数占用CPU的耗时
- flat%::当前函数占用CPU的耗时百分比
- sum%:函数占用CPU的耗时累计百分比
- cum:当前函数加上调用当前函数的函数占用CPU的总耗时
- cum%:当前函数加上调用当前函数的函数占用CPU的总耗时百分比
常用命令
top 30 -cum
list xxx
peek xxx
参考资料
- 《PProf服务性能分析》https://goframe.org/pages/viewpage.action?pageId=1114350
- Google 官方文档https://github.com/google/pprof/blob/main/doc/README.md
- 《Pprof and golang - how to interpret a results?》sum的含义https://stackoverflow.com/a/56882137
- 《golang性能分析工具pprof的8个指标》https://www.bilibili.com/video/BV1MG411A7XU
最新评论