From ab422f2749bc21514cb22d444bae460f5fa22376 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Tue, 21 Jun 2022 12:28:48 -0700 Subject: [PATCH] runtime/trace: ignore fallback stacks in test 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 Run-TryBot: Rhys Hiltner TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt --- src/runtime/trace/trace_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/runtime/trace/trace_test.go b/src/runtime/trace/trace_test.go index b1afd2b8bb..19f7dbe775 100644 --- a/src/runtime/trace/trace_test.go +++ b/src/runtime/trace/trace_test.go @@ -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 } }