go - 找出谁启动了 goroutine (pprof)

标签 go

在检查 pprof 的输出时,我可以看到 goroutine 的堆栈跟踪。但是我想知道是谁开始(产生?)这个 goroutine,这可能吗?

最佳答案

如果您查看端点 /debug/pprof/goroutine?debug=2,您会得到堆栈跟踪的稍微不同的输出:

goroutine 859579 [running]:
runtime/pprof.writeGoroutineStacks(0x176a0e0, 0xc43403a340, 0x178d740, 0x30)
    /usr/local/go/src/runtime/pprof/pprof.go:585 +0x79
runtime/pprof.writeGoroutine(0x176a0e0, 0xc43403a340, 0x2, 0x0, 0xd)
    /usr/local/go/src/runtime/pprof/pprof.go:574 +0x44
runtime/pprof.(*Profile).WriteTo(0x178f9e0, 0x176a0e0, 0xc43403a340, 0x2, 0xc43403a340, 0xc4587b5834)
    /usr/local/go/src/runtime/pprof/pprof.go:298 +0x341
net/http/pprof.handler.ServeHTTP(0xc4587b5841, 0x9, 0x1771320, 0xc43403a340, 0xc49a7093b0)
    /usr/local/go/src/net/http/pprof/pprof.go:209 +0x1a6
net/http/pprof.Index(0x1771320, 0xc43403a340, 0xc49a7093b0)
    /usr/local/go/src/net/http/pprof/pprof.go:221 +0x205
net/http.HandlerFunc.ServeHTTP(0x12664a8, 0x1771320, 0xc43403a340, 0xc49a7093b0)
    /usr/local/go/src/net/http/server.go:1726 +0x44
net/http.(*ServeMux).ServeHTTP(0x179dde0, 0x1771320, 0xc43403a340, 0xc49a7093b0)
    /usr/local/go/src/net/http/server.go:2022 +0x7f
net/http.serverHandler.ServeHTTP(0xc46d06ed80, 0x1771320, 0xc43403a340, 0xc49a7093b0)
    /usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc45dc83180, 0x17734a0, 0xc4942f0600)
    /usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2293 +0x44d

最后包括 created by 行。

关于go - 找出谁启动了 goroutine (pprof),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41489148/

相关文章:

go - 如何从 GCP Golang SDK 检索访问 token ?

go - 如何在不返回的情况下更改函数中的 slice ?

go - 我可以在一台服务器上托管 Angular2 前端和 Golang 后端吗

go - 如何为 gRPC TLS 连接设置 docker-compose 容器?

golang 打印 echo.Context 值

go - 如何使用可变数量的项目转换 []string?

bash - 在 Docker 容器中启动 Golang Web 服务器

debugging - 进入程序运行时错误并打印出所有内容

go - 为什么 f1.Read(buf) 没有读出内容到 buf?

作为结构成员的函数