From c5bafc828126c8fa057e1accaa448583c7ec145f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 6 Jan 2016 21:16:01 -0500 Subject: runtime: make NumGoroutine and Stack agree not to include system goroutines Before, NumGoroutine counted system goroutines and Stack (usually) didn't show them, which was inconsistent and confusing. To resolve which way they should be consistent, it seems like package main import "runtime" func main() { println(runtime.NumGoroutine()) } should print 1 regardless of internal runtime details. Make it so. Fixes #11706. Change-Id: I6bfe26a901de517728192cfb26a5568c4ef4fe47 Reviewed-on: https://go-review.googlesource.com/18343 Reviewed-by: Austin Clements --- src/runtime/mprof.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/runtime/mprof.go') diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go index 684ab0b055..eb7231aec2 100644 --- a/src/runtime/mprof.go +++ b/src/runtime/mprof.go @@ -576,12 +576,17 @@ func Stack(buf []byte, all bool) int { pc := getcallerpc(unsafe.Pointer(&buf)) systemstack(func() { g0 := getg() + // Force traceback=1 to override GOTRACEBACK setting, + // so that Stack's results are consistent. + // GOTRACEBACK is only about crash dumps. + g0.m.traceback = 1 g0.writebuf = buf[0:0:len(buf)] goroutineheader(gp) traceback(pc, sp, 0, gp) if all { tracebackothers(gp) } + g0.m.traceback = 0 n = len(g0.writebuf) g0.writebuf = nil }) -- cgit v1.3