如何描述goroutines的数量

tom*_*les 3 profiling go pprof

基本上我想找到我的程序是否随着时间的推移泄漏goroutines.所以我想看看有多少goroutines正在运行.有没有办法做到这一点pprof

我已经做了go tool pprof http://localhost:8888/debug/pprof/block.

这让我花了多长时间被阻止但没有运行多少例程.

use*_*317 8

在浏览器中打开http:// localhost:8888/debug/pprof /.你会看到两个相关的链接:"goroutine"(http:// localhost:8888/debug/pprof/goroutine?debug = 1)和"full goroutine stack dump"(http:// localhost:8888/debug/pprof/goroutine?debug = 2).

第一个将显示与一个条目共享相同代码的所有goroutine,其名称前面有此类goroutines的数量.例如:

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
Run Code Online (Sandbox Code Playgroud)

这两个goroutines中都有一个,这就是@之前的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
Run Code Online (Sandbox Code Playgroud)

  • 当debug = 1时,@表示后的地址是什么? - ("0x42f223 0x42f2e4 0x40542f 0x404f4b 0x4a0586 0x4600a1") (2认同)