在检查 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/