A repository provides access to goroutine's ID, state and otehr information by parsing message invoking runtime.Stack
go get -u github.com/liangyaopei/goroutineinfo
func TestGetInfoSingle(t *testing.T) {
stacks := goroutineinfo.GetInfo(false)
for _, stack := range stacks {
t.Logf("id:[%d],state:[%s]", stack.ID(), stack.State())
}
}
func BenchmarkGetInfoSingle(b *testing.B) {
_ = goroutineinfo.GetInfo(false)
}
testing
go test ./... -bench=BenchmarkGetInfoSingle -benchmem -run=^$ -count=10
time cost is 0.000034 ns/op average.