From b1aadd034c1feb6ac8409aca5f0efd10ef442950 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Thu, 11 May 2023 21:09:10 +0000 Subject: runtime: emit STW events for all pauses, not just those for the GC Currently STW events are only emitted for GC STWs. There's little reason why the trace can't contain events for every STW: they're rare so don't take up much space in the trace, yet being able to see when the world was stopped is often critical to debugging certain latency issues, especially when they stem from user-level APIs. This change adds new "kinds" to the EvGCSTWStart event, renames the GCSTW events to just "STW," and lets the parser deal with unknown STW kinds for future backwards compatibility. But, this change must break trace compatibility, so it bumps the trace version to Go 1.21. This change also includes a small cleanup in the trace command, which previously checked for STW events when deciding whether user tasks overlapped with a GC. Looking at the source, I don't see a way for STW events to ever enter the stream that that code looks at, so that condition has been deleted. Change-Id: I9a5dc144092c53e92eb6950e9a5504a790ac00cf Reviewed-on: https://go-review.googlesource.com/c/go/+/494495 Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot Run-TryBot: Michael Knyszek --- src/internal/trace/parser_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/internal/trace/parser_test.go') diff --git a/src/internal/trace/parser_test.go b/src/internal/trace/parser_test.go index cdab95a59e..fce660c289 100644 --- a/src/internal/trace/parser_test.go +++ b/src/internal/trace/parser_test.go @@ -52,12 +52,13 @@ func TestParseCanned(t *testing.T) { } // Instead of Parse that requires a proper binary name for old traces, // we use 'parse' that omits symbol lookup if an empty string is given. - _, _, err = parse(bytes.NewReader(data), "") + ver, res, err := parse(bytes.NewReader(data), "") switch { case strings.HasSuffix(f.Name(), "_good"): if err != nil { t.Errorf("failed to parse good trace %v: %v", f.Name(), err) } + checkTrace(t, ver, res) case strings.HasSuffix(f.Name(), "_unordered"): if err != ErrTimeOrder { t.Errorf("unordered trace is not detected %v: %v", f.Name(), err) @@ -68,6 +69,18 @@ func TestParseCanned(t *testing.T) { } } +// checkTrace walks over a good trace and makes a bunch of additional checks +// that may not cause the parser to outright fail. +func checkTrace(t *testing.T, ver int, res ParseResult) { + for _, ev := range res.Events { + if ver >= 1021 { + if ev.Type == EvSTWStart && ev.SArgs[0] == "unknown" { + t.Errorf("found unknown STW event; update stwReasonStrings?") + } + } + } +} + func TestParseVersion(t *testing.T) { tests := map[string]int{ "go 1.5 trace\x00\x00\x00\x00": 1005, -- cgit v1.3-6-g1900