]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: deflake TestCgoPprofThread
authorCherry Mui <cherryyz@google.com>
Tue, 17 May 2022 21:52:43 +0000 (17:52 -0400)
committerCherry Mui <cherryyz@google.com>
Tue, 17 May 2022 22:59:31 +0000 (22:59 +0000)
In TestCgoPprofThread, the (fake) cgo traceback function pretends
all C CPU samples are in cpuHogThread. But if a profiling signal
lands in C code but outside of that thread, e.g. before/when the
thread is created, we will get a sample which looks like Go calls
into cpuHogThread. This CL makes the cgo traceback function only
return cpuHogThread PCs when a signal lands on that thread.

May fix #52726.

Change-Id: I21c40f974d1882508626faf3ac45e8347fec31c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/406934
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/runtime/testdata/testprogcgo/threadpprof.go

index ec5e750da9dd27014450eee0ac9aabb93b9bfd07..70717e0099afc308452aeb4c0470e624236511a6 100644 (file)
@@ -17,6 +17,8 @@ package main
 int threadSalt1;
 int threadSalt2;
 
+static pthread_t tid;
+
 void cpuHogThread() {
        int foo = threadSalt1;
        int i;
@@ -42,12 +44,16 @@ struct cgoTracebackArg {
 };
 
 // pprofCgoThreadTraceback is passed to runtime.SetCgoTraceback.
-// For testing purposes it pretends that all CPU hits in C code are in cpuHog.
+// For testing purposes it pretends that all CPU hits on the cpuHog
+// C thread are in cpuHog.
 void pprofCgoThreadTraceback(void* parg) {
        struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg);
-       arg->buf[0] = (uintptr_t)(cpuHogThread) + 0x10;
-       arg->buf[1] = (uintptr_t)(cpuHogThread2) + 0x4;
-       arg->buf[2] = 0;
+       if (pthread_self() == tid) {
+               arg->buf[0] = (uintptr_t)(cpuHogThread) + 0x10;
+               arg->buf[1] = (uintptr_t)(cpuHogThread2) + 0x4;
+               arg->buf[2] = 0;
+       } else
+               arg->buf[0] = 0;
 }
 
 static void* cpuHogDriver(void* arg __attribute__ ((unused))) {
@@ -58,7 +64,6 @@ static void* cpuHogDriver(void* arg __attribute__ ((unused))) {
 }
 
 void runCPUHogThread(void) {
-       pthread_t tid;
        pthread_create(&tid, 0, cpuHogDriver, 0);
 }
 */