使用 pprof 分析 Goroutine 數量
使用 pprof 分析 Goroutine 數量
檢測 Go 程式中潛在的 Goroutine 洩漏需要監控一段時間內活動的 Goroutine 數量。雖然標準 go 工具 pprof 命令提供了對阻塞的深入了解,但它並不直接解決 goroutine 計數問題。: http://localhost:8888/debug/pprof/goroutine?debug=2
1 @ 0x42f223 0x42f2e4 0x40542f 0x404f4b 0x4a0586 0x4600a1 # 0x4a0586 gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers 0x56 /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:164 1 @ 0x42f223 0x43dfd7 0x43d532 0x4a04ed 0x4600a1 # 0x4a04ed gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners 0x45d /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:147連結顯示共享相同程式碼的goroutine條目]
Goroutine
連結顯示共享相同程式碼的goroutine條目及其計數。例如:1 @ 0x42f223 0x42f2e4 0x40542f 0x404f4b 0x4a0586 0x4600a1 # 0x4a0586 gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers 0x56 /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-跑者/命令/multi.go:164 1 @ 0x42f223 0x43dfd7 0x43d532 0x4a04ed 0x4600a1 # 0x4a04ed gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners 0x45d /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi- runner/commands/multi.go:147
@ 之前的數字1 表示每個goroutine 的一個實例。goroutine 49 [chan receive, 2 minutes]: gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers(0xc820103ee0, 0xc820274000, 0xc820274060, 0xc8201d65a0) /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:164 0x56 created by gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).Run /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:294 0x41b goroutine 50 [select]: gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners(0xc820103ee0, 0x0, 0xc820274060, 0xc8201d65a0) /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:147 0x45d created by gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:165 0x96
完整 Goroutine 堆疊轉儲
對於洩漏特別有用檢測。它單獨列出每個 goroutine,包括其堆疊追蹤和活動狀態:goroutine 49 [chan receive, 2 分鐘]: gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).startWorkers(0xc820103ee0、0xc820274000、0xc820274060、0xc8201d65a0) /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:164 0x56 由 gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands 創作。 (*RunCommand).Run /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:294 0x41b Goroutine 50 [選擇]: gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands.(*RunCommand).processRunners(0xc820103ee0, 0x0, 0xc820274060, 0xc8201d65a0) /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:147 0x45d 由 gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands 創作。 (*RunCommand).startWorkers /home/me/go/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/commands/multi.go:165 0x96
利用這些pprof 端點,您可以有效地監控程序中的goroutine 數量,有助於檢測和解決潛在的goroutine 洩漏。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3