aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorRhys Hiltner <rhys@justin.tv>2021-12-07 13:32:24 -0800
committerMichael Pratt <mpratt@google.com>2021-12-08 15:45:29 +0000
commit46db6aa1573def4ba06dbf5c38e704d85dc303b6 (patch)
tree8b12de1740f6c3a91f70da5fe01edf9be80e95dd /src/runtime/testdata
parent3042ba34db86853c7035046716c4a00b2dbef2ed (diff)
downloadgo-46db6aa1573def4ba06dbf5c38e704d85dc303b6.tar.xz
runtime: fix flake in TestCgoPprofThread
If the test's main goroutine receives a SIGPROF while creating the C-owned thread for the test, that sample will appear in the resulting profile. The root end of that stack will show a set of Go functions. The leaf end will be the C functions returned by the SetCgoTraceback handler, which will confuse the test runner. Add a label to the main goroutine while it calls in to C, so all profile samples that triggered the SetCgoTraceback handler are either correct, or can easily be excluded from the test's analysis. (The labels will not apply to the resulting C-owned thread, which does not use goroutines.) Fixes #43174 Change-Id: Ica3100ca0f191dcf91b30b0084e8541c5a25689f Reviewed-on: https://go-review.googlesource.com/c/go/+/370135 Reviewed-by: Michael Pratt <mpratt@google.com> Trust: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Trust: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testprogcgo/threadpprof.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/runtime/testdata/testprogcgo/threadpprof.go b/src/runtime/testdata/testprogcgo/threadpprof.go
index 4bc84d16d0..e093f67e1e 100644
--- a/src/runtime/testdata/testprogcgo/threadpprof.go
+++ b/src/runtime/testdata/testprogcgo/threadpprof.go
@@ -64,6 +64,7 @@ void runCPUHogThread(void) {
import "C"
import (
+ "context"
"fmt"
"os"
"runtime"
@@ -98,7 +99,14 @@ func pprofThread() {
os.Exit(2)
}
- C.runCPUHogThread()
+ // This goroutine may receive a profiling signal while creating the C-owned
+ // thread. If it does, the SetCgoTraceback handler will make the leaf end of
+ // the stack look almost (but not exactly) like the stacks the test case is
+ // trying to find. Attach a profiler label so the test can filter out those
+ // confusing samples.
+ pprof.Do(context.Background(), pprof.Labels("ignore", "ignore"), func(ctx context.Context) {
+ C.runCPUHogThread()
+ })
time.Sleep(1*time.Second)