]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/trace: ignore fallback stacks in test
authorRhys Hiltner <rhys@justin.tv>
Tue, 21 Jun 2022 19:28:48 +0000 (12:28 -0700)
committerRhys Hiltner <rhys@justin.tv>
Tue, 21 Jun 2022 22:05:17 +0000 (22:05 +0000)
When runtime.sigprof encounters a stack that gentraceback is unable to
process, it synthesizes a call stack with a sentinel function (such as
runtime._System) at the leaf.

The test to confirm that runtime/trace and runtime/pprof have similar
views of CPU profile samples has trouble with those stacks. The test
confirms that the samples match by confirming that their symbolized
forms match, and the symbolization procedure is very different for the
two packages.

Skip the samples that the CPU profiler's view symbolizes to include one
of runtime.sigprof's sentinel functions at the leaf. (The test design
expects the CPU profiler to under-report samples relative to the
execution tracer.)

Fixes #53378

Change-Id: I60c27de4c69b454057d28a3b6e12d70369de4c4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/413457
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Rhys Hiltner <rhys@justin.tv>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/trace/trace_test.go

index b1afd2b8bb5fd7b92f71f52268e2c21ba42a93bf..19f7dbe77533eed6922681e3d905d1cbdb207491 100644 (file)
@@ -634,15 +634,29 @@ func TestTraceCPUProfile(t *testing.T) {
        pprofStacks := make(map[string]int)
        for _, s := range prof.Sample {
                if s.Label["tracing"] != nil {
-                       samples := int(s.Value[0])
-                       pprofSamples += samples
                        var fns []string
+                       var leaf string
                        for _, loc := range s.Location {
                                for _, line := range loc.Line {
                                        fns = append(fns, fmt.Sprintf("%s:%d", line.Function.Name, line.Line))
+                                       leaf = line.Function.Name
                                }
                        }
+                       // runtime.sigprof synthesizes call stacks when "normal traceback is
+                       // impossible or has failed", using particular placeholder functions
+                       // to represent common failure cases. Look for those functions in
+                       // the leaf position as a sign that the call stack and its
+                       // symbolization are more complex than this test can handle.
+                       //
+                       // TODO: Make the symbolization done by the execution tracer and CPU
+                       // profiler match up even in these harder cases. See #53378.
+                       switch leaf {
+                       case "runtime._System", "runtime._GC", "runtime._ExternalCode", "runtime._VDSO":
+                               continue
+                       }
                        stack := strings.Join(fns, " ")
+                       samples := int(s.Value[0])
+                       pprofSamples += samples
                        pprofStacks[stack] += samples
                }
        }