aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>2021-09-20 16:09:47 +0200
committerMichael Pratt <mpratt@google.com>2021-12-03 16:11:38 +0000
commit9b0de0854d5a5655890ef0b2b9052da2541182a3 (patch)
treed456c70958a04f01aeffbf5fa713724d75e7a0af /src/runtime/proc.go
parenta174638a5cc88eb4fccaaa699990f5626fbb0e30 (diff)
downloadgo-9b0de0854d5a5655890ef0b2b9052da2541182a3.tar.gz
go-9b0de0854d5a5655890ef0b2b9052da2541182a3.zip
runtime: fix missing pprof labels
Use gp.m.curg instead of the gp when recording cpu profiler stack traces. This ensures profiler labels are captured when systemstack or similar is executing on behalf of the current goroutine. After this there are still rare cases of samples containing the labelHog function, so more work might be needed. This patch should fix ~99% of the problem. Also change testCPUProfile interface a little to allow the new test to re-run with a longer duration if it fails during a -short run. Fixes #48577. Change-Id: I3dbc9fd5af3c513544e822acaa43055b2e00dfa9 Reviewed-on: https://go-review.googlesource.com/c/go/+/367200 Trust: Michael Pratt <mpratt@google.com> Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index f375b67981..7509f7632f 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -4726,7 +4726,14 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
}
if prof.hz != 0 {
- cpuprof.add(gp, stk[:n])
+ // Note: it can happen on Windows that we interrupted a system thread
+ // with no g, so gp could nil. The other nil checks are done out of
+ // caution, but not expected to be nil in practice.
+ var tagPtr *unsafe.Pointer
+ if gp != nil && gp.m != nil && gp.m.curg != nil {
+ tagPtr = &gp.m.curg.labels
+ }
+ cpuprof.add(tagPtr, stk[:n])
}
getg().m.mallocing--
}