分享
pprof进行golang程序性能分析
gm-201705 · · 1393 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
一、导入包
import _ "net/http/pprof"
二、启动监控routine
go func() {
http.ListenAndServe("0.0.0.0:18080", nil)
}()
三、访问web服务
例:分析CPU占用情况
go tool pprof http://localhost:18080/debug/pprof/profile
(pprof) top10 Total: 2525 samples 298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64 268 10.6% 22.4% 2124 84.1% main.FindLoops 251 9.9% 32.4% 451 17.9% scanblock 178 7.0% 39.4% 351 13.9% hash_insert 131 5.2% 44.6% 158 6.3% sweepspan 119 4.7% 49.3% 350 13.9% main.DFS 96 3.8% 53.1% 98 3.9% flushptrbuf 95 3.8% 56.9% 95 3.8% runtime.aeshash64 95 3.8% 60.6% 101 4.0% runtime.settype_flush 88 3.5% 64.1% 988 39.1% runtime.mallocgc
四、参考
// pprof 命令
https://blog.golang.org/profiling-go-programs
// web 上几项监控指标
https://golang.org/pkg/net/http/pprof/
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1393 次点击
上一篇:Go Channel的实现
下一篇:Go语言的2017年终总结
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
一、导入包
import _ "net/http/pprof"
二、启动监控routine
go func() {
http.ListenAndServe("0.0.0.0:18080", nil)
}()
三、访问web服务
例:分析CPU占用情况
go tool pprof http://localhost:18080/debug/pprof/profile
(pprof) top10 Total: 2525 samples 298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64 268 10.6% 22.4% 2124 84.1% main.FindLoops 251 9.9% 32.4% 451 17.9% scanblock 178 7.0% 39.4% 351 13.9% hash_insert 131 5.2% 44.6% 158 6.3% sweepspan 119 4.7% 49.3% 350 13.9% main.DFS 96 3.8% 53.1% 98 3.9% flushptrbuf 95 3.8% 56.9% 95 3.8% runtime.aeshash64 95 3.8% 60.6% 101 4.0% runtime.settype_flush 88 3.5% 64.1% 988 39.1% runtime.mallocgc
四、参考
// pprof 命令
https://blog.golang.org/profiling-go-programs
// web 上几项监控指标
https://golang.org/pkg/net/http/pprof/