From 4a7fde922ff12dce9d4e00f1b1e658fa907e488d Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Tue, 5 Aug 2025 21:37:07 +0000 Subject: internal/trace: add end-of-generation signal to trace This change takes the EvEndOfGeneration event and promotes it to a real event that appears in the trace. This allows the trace parser to unambiguously identify truncated traces vs. broken traces. It also makes a lot of the logic around parsing simpler, because there's no more batch spilling necessary. Fixes #73904. Change-Id: I37c359b32b6b5f894825aafc02921adeaacf2595 Reviewed-on: https://go-review.googlesource.com/c/go/+/693398 Reviewed-by: Carlos Amedee Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI --- src/runtime/trace.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'src/runtime/trace.go') diff --git a/src/runtime/trace.go b/src/runtime/trace.go index 0d71ad445c..2c712469ea 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -754,24 +754,7 @@ func traceRegisterLabelsAndReasons(gen uintptr) { // was on has been returned, ReadTrace returns nil. The caller must copy the // returned data before calling ReadTrace again. // ReadTrace must be called from one goroutine at a time. -func ReadTrace() []byte { - for { - buf := readTrace() - - // Skip over the end-of-generation signal which must not appear - // in the final trace. - if len(buf) == 1 && tracev2.EventType(buf[0]) == tracev2.EvEndOfGeneration { - continue - } - return buf - } -} - -// readTrace is the implementation of ReadTrace, except with an additional -// in-band signal as to when the buffer is for a new generation. -// -//go:linkname readTrace runtime/trace.runtime_readTrace -func readTrace() (buf []byte) { +func ReadTrace() (buf []byte) { top: var park bool systemstack(func() { @@ -842,7 +825,7 @@ func readTrace0() (buf []byte, park bool) { if !trace.headerWritten { trace.headerWritten = true unlock(&trace.lock) - return []byte("go 1.25 trace\x00\x00\x00"), false + return []byte("go 1.26 trace\x00\x00\x00"), false } // Read the next buffer. -- cgit v1.3-5-g9baa