Skip to content

Commit ab422f2

Browse files
committed
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 <[email protected]> Run-TryBot: Rhys Hiltner <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 66685fb commit ab422f2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/runtime/trace/trace_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,29 @@ func TestTraceCPUProfile(t *testing.T) {
634634
pprofStacks := make(map[string]int)
635635
for _, s := range prof.Sample {
636636
if s.Label["tracing"] != nil {
637-
samples := int(s.Value[0])
638-
pprofSamples += samples
639637
var fns []string
638+
var leaf string
640639
for _, loc := range s.Location {
641640
for _, line := range loc.Line {
642641
fns = append(fns, fmt.Sprintf("%s:%d", line.Function.Name, line.Line))
642+
leaf = line.Function.Name
643643
}
644644
}
645+
// runtime.sigprof synthesizes call stacks when "normal traceback is
646+
// impossible or has failed", using particular placeholder functions
647+
// to represent common failure cases. Look for those functions in
648+
// the leaf position as a sign that the call stack and its
649+
// symbolization are more complex than this test can handle.
650+
//
651+
// TODO: Make the symbolization done by the execution tracer and CPU
652+
// profiler match up even in these harder cases. See #53378.
653+
switch leaf {
654+
case "runtime._System", "runtime._GC", "runtime._ExternalCode", "runtime._VDSO":
655+
continue
656+
}
645657
stack := strings.Join(fns, " ")
658+
samples := int(s.Value[0])
659+
pprofSamples += samples
646660
pprofStacks[stack] += samples
647661
}
648662
}

0 commit comments

Comments
 (0)