怎麼分析和理解golang的pprof
golang 有runtime/pprof
,net/http/pprof
包
是 go 程式的分析利器,然而當我研究的時候卻是一頭霧水,網上找了資料,profiling-go-programs,也百度了一下,看到不少部落格,但從沒一個系統和具體的介紹到底那些引數代表什麼? 如我開啟了,net/http/pprof
開啟瀏覽器可以看到這些:
/debug/pprof/
profiles: 0 block 12 goroutine 1 heap 10 threadcreate
full goroutine stack dump
可以知道: block 應該代表鎖(但不知是什麼鎖,讀寫鎖?) goroutine go 程資訊 heap 堆資訊 threadcreate 執行緒資訊
又比如點選 heap,會詳細顯示堆的資訊,如:
heap profile: 1: 262144 [1: 262144] @ heap/1048576
1: 262144 [1: 262144] @ 0xf938a 0xf961f 0xf84bc 0xf7c47 0xf9953 0x2a81 0x2fb44 0x5fd01
# 0xf9389 vendor/sewise.com/glog.(*syncBuffer).rotateFile+0x619 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/glog/glog.go:858
# 0xf961e vendor/sewise.com/glog.(*loggingT).createFiles+0xfe /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/glog/glog.go:887
# 0xf84bb vendor/sewise.com/glog.(*loggingT).output+0x4eb /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/glog/glog.go:706
# 0xf7c46 vendor/sewise.com/glog.(*loggingT).println+0xe6 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/glog/glog.go:650
# 0xf9952 vendor/sewise.com/glog.Infoln+0x52 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/glog/glog.go:1084
# 0x2a80 main.main+0x560 /Users/bao/program/go/sewise_iot/src/sewise_iot_broker/main.go:132
# 0x2fb43 runtime.main+0x1f3 /usr/local/go/src/runtime/proc.go:183
0: 0 [0: 0] @ 0x1fe82f 0xa0157 0xa3de3 0x5fd01
# 0x1fe82e context.WithCancel+0x3e /usr/local/go/src/context/context.go:230
# 0xa0156 net/http.(*conn).readRequest+0x496 /usr/local/go/src/net/http/server.go:804
# 0xa3de2 net/http.(*conn).serve+0x3d2 /usr/local/go/src/net/http/server.go:1532
0: 0 [0: 0] @ 0x102011 0x10d3bc 0x10c945 0x10eee3 0x5fd01
# 0x102010 vendor/sewise.com/sewisemq/service.newBuffer+0x1e0 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/sewisemq/service/buffer.go:98
# 0x10d3bb vendor/sewise.com/sewisemq/service.(*service).start+0x3b /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/sewisemq/service/service.go:138
# 0x10c944 vendor/sewise.com/sewisemq/service.(*Server).handleConnection+0x884 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/sewisemq/service/server.go:332
# 0x10eee2 vendor/sewise.com/sewisemq/service.(*Server).ListenAndServe.func1+0x62 /Users/bao/program/go/sewise_iot/src/vendor/sewise.com/sewisemq/service/server.go:162
# runtime.MemStats
# Alloc = 3090232
# TotalAlloc = 3090232
# Sys = 8296696
# Lookups = 169
# Mallocs = 15201
# Frees = 1757
# HeapAlloc = 3090232
# HeapSys = 4587520
# HeapIdle = 753664
# HeapInuse = 3833856
# HeapReleased = 0
# HeapObjects = 13444
# Stack = 655360 / 655360
# MSpan = 37120 / 49152
# MCache = 4800 / 16384
# BuckHashSys = 1443221
# NextGC = 4194304
# PauseNs = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# NumGC = 0
# DebugGC = false
看文章介紹可以用 go tool pprof,我也試了這個命令:
go tool pprof http://localhost:6060/debug/pprof/heap
檢視了一下 help,敲下tree
(pprof) tree
650.62kB of 650.62kB total ( 100%)
Dropped 4 nodes (cum <= 3.25kB)
----------------------------------------------------------+-------------
flat flat% sum% cum cum% calls calls% + context
----------------------------------------------------------+-------------
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).createFiles
650.62kB 100% 100% 650.62kB 100% | vendor/sewise.com/glog.(*syncBuffer).rotateFile
----------------------------------------------------------+-------------
650.62kB 100% | runtime.main
0 0% 100% 650.62kB 100% | main.main
650.62kB 100% | vendor/sewise.com/glog.Infoln
----------------------------------------------------------+-------------
0 0% 100% 650.62kB 100% | runtime.goexit
650.62kB 100% | runtime.main
----------------------------------------------------------+-------------
650.62kB 100% | runtime.goexit
0 0% 100% 650.62kB 100% | runtime.main
650.62kB 100% | main.main
----------------------------------------------------------+-------------
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).output
0 0% 100% 650.62kB 100% | vendor/sewise.com/glog.(*loggingT).createFiles
650.62kB 100% | vendor/sewise.com/glog.(*syncBuffer).rotateFile
----------------------------------------------------------+-------------
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).println
0 0% 100% 650.62kB 100% | vendor/sewise.com/glog.(*loggingT).output
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).createFiles
----------------------------------------------------------+-------------
650.62kB 100% | vendor/sewise.com/glog.Infoln
0 0% 100% 650.62kB 100% | vendor/sewise.com/glog.(*loggingT).println
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).output
----------------------------------------------------------+-------------
650.62kB 100% | main.main
0 0% 100% 650.62kB 100% | vendor/sewise.com/glog.Infoln
650.62kB 100% | vendor/sewise.com/glog.(*loggingT).println
----------------------------------------------------------+-------------
用來分析 heap,但依然一頭霧水。。。 flat 不懂 sum% 不懂 cum 不懂 cum% 不懂 calls calls% + context 上下文
更多原創文章乾貨分享,請關注公眾號
- 加微信實戰群請加微信(註明:實戰群):gocnio
相關文章
- golang 使用pprof和go-torch做效能分析Golang
- golang pprofGolang
- golang 效能調優分析工具 pprof (上)Golang
- golang 效能調優分析工具 pprof(下)Golang
- golang 效能優化分析:benchmark 結合 pprofGolang優化
- 使用 pprof 和 Flame-Graph 除錯 Golang 應用除錯Golang
- 萬字長文講解Golang pprof 的使用Golang
- 效能分析工具 - pprof
- pprof - 在現網場景怎麼用
- 用pprof分析map和slice的記憶體呼叫記憶體
- Golang 大殺器之效能剖析 PProfGolang
- 使用pprof進行效能分析
- golang pprof監控系列(2) —— memory,block,mutex 使用GolangBloCMutex
- Golang pprof 結果使用 graphviz 圖片化顯示Golang
- Golang pprof 效能調優實戰,效能提升 3 倍!Golang
- Golang的反射reflect深入理解和示例Golang反射
- golang pprof 監控系列(3) —— memory,block,mutex 統計原理GolangBloCMutex
- golang pprof 監控系列(4) —— goroutine thread 統計原理Golangthread
- 深入理解Golang之interface和reflectGolang
- pprof 分析mysqld 記憶體呼叫(筆記)MySql記憶體筆記
- Golang中閉包的理解Golang
- 深入理解golang 的棧Golang
- 理解Golang的Time結構Golang
- 怎麼理解Condition
- Sp效率分析和理解
- 怎麼理解php的中介軟體PHP
- 怎麼通俗易懂的理解OSPF?
- golang 必會之 pprof 監控系列(5) —— cpu 佔用率 統計原理Golang
- golang在goroutine裡的錯誤怎麼傳遞?Golang
- golang寫的web application 怎麼優雅的更新?GolangWebAPP
- 防火牆是什麼?怎麼理解?防火牆
- 負載均衡是什麼?怎麼理解負載均衡的部署方式和工作原理負載
- 怎麼理解docker的本質是程式Docker
- go tool pprofGo
- go pprof命令Go
- 怎麼理解獨立伺服器和虛擬機器伺服器虛擬機
- 理解Golang多重賦值Golang賦值
- 徹底理解Golang MapGolang