Reputation: 53
I can get the value through this
"runtime.NumGoroutine()"
..
Can I know the number of goroutines in an external program?
Upvotes: 0
Views: 1341
Reputation: 31664
Maybe you can use delve
.
go get github.com/derekparker/delve/cmd/dlv
$pid
of your main applicaitondlv attach $pid
, then type goroutines
to see all go routines like follows:C:\work\gowork>dlv attach 5696 Type 'help' for list of commands. (dlv) goroutines [5 goroutines] Goroutine 1 - User: C:/devsoft/Go/src/runtime/time.go:102 time.Sleep (0x440c3b) Goroutine 2 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f) Goroutine 3 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f) Goroutine 17 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f) * Goroutine 19 - User: :0 ??? (0x7fffef855427) (thread 15260) (dlv)
Then, what your program needs to do is to control the command dlv
using something like expect
to control the debug tool to input goroutines
command.
Seems it has a xml-rpc like api for client to get more infomation, you may can have a look, I did not use the api before.
Just a thought, FYI.
Upvotes: 4