aboutsummaryrefslogtreecommitdiff
path: root/src/internal/trace/reader.go
AgeCommit message (Collapse)Author
2025-08-15internal/trace: emit final sync event for generation in Go 1.26+Michael Anthony Knyszek
CL 693398 returned the error from reading a generation immediately, but this is wrong -- a Sync event must be emitted to indicate the end of the trace before reporting the error. This caused TestCrashWhileTracing to fail because that test has a high likelihood of producing a truncated trace, and it expects at least 2 Sync events. The truncated trace error would be reported before the second Sync event, which is incorrect. Fixes #75045. Change-Id: Ia71592c4ec56a544afc85cdb7b575e143f80e048 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/696436 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-15internal/trace: add end-of-generation signal to traceMichael Anthony Knyszek
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 <carlos@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-21runtime,internal/trace: emit clock snapshots at the start of trace generationsFelix Geisendörfer
Replace the per-generation EvEventBatch containing a lone EvFrequency event with a per-generation EvEventBatch containing a EvSync header followed by an EvFrequency and EvClockSnapshot event. The new EvClockSnapshot event contains trace, mono and wall clock snapshots taken in close time proximity. Ignoring minor resolution differences, the trace and mono clock are the same on linux, but not on windows (which still uses a TSC based trace clock). Emit the new sync batch at the very beginning of every new generation rather than the end to be in harmony with the internal/trace reader which emits a sync event at the beginning of every generation as well and guarantees monotonically increasing event timestamps. Bump the version of the trace file format to 1.25 since this change is not backwards compatible. Update the internal/trace reader implementation to decode the new events, but do not expose them to the public reader API yet. This is done in the next CL. For #69869 Change-Id: I5bfedccdd23dc0adaf2401ec0970cbcc32363393 Reviewed-on: https://go-review.googlesource.com/c/go/+/653575 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-02-14internal/trace: emit sync event before deferred spilled errorMichael Anthony Knyszek
CL 648315 and CL 648195 fixed #71615 in the case where we fail to read the next generation by emitting an extra sync event before returning an error. But, it's possible we failed to even read the next spilled batch when we read the first generation, and have been carrying the error from trying to read a spilled batch since the last generation. In this case, we don't emit a final sync event, meaning that there are still some cases where #71615 happens. This change emits the final sync event in this corner case. I believe this is the final corner case. I could previously reproduce the issue by running the test under stress2, but I can no longer reproduce any failures after this change. Fixes #71615, for real this time. Change-Id: I10688a3c0e4b8327a95f31add365338c77c091ab Reviewed-on: https://go-review.googlesource.com/c/go/+/649259 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-11internal/trace: increment sync counter before final Sync on errorMichael Anthony Knyszek
CL 648195 was supposed to have fixed #71615, but it didn't include an update to r.syncs. I can confirm this CL fixes the issue even when running the test many times in a row. Fixes #71615. Change-Id: I97db3d639dc5bc8648a191696f90b0e5087307c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/648315 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
2025-02-10internal/trace: emit a Sync event even if the next generation is brokenMichael Anthony Knyszek
Since CL 644215 each Sync event now represents the coming generation, with a final Sync event emitted even when there's nothing ahead. This change however failed to emit a Sync event at the end of a completely valid generation when the next generation was invalid, causing the runtime test TestCrashWhileTracing to start failing. Fix this by emitting a final Sync event even when the next generation is broken. We hold onto the error in parsing the next generation and emit it after that final Sync event. (Should these "final" Sync events distinguish themselves in some way?) Fixes #71615. Change-Id: I1f8abee5abaa39e1219e6fa05e9f82f1478db4c9 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/648195 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-02-10internal/trace: be stricter about allowed events in v2 trace versionsMichael Anthony Knyszek
Currently all v2 trace versions, Go 1.22 and Go 1.23, share a full set of specs. This is mostly OK, but it means quite a few events will be accepted for 1.22 traces that should be rejected. This change fixes that by limiting which event specs are returned by version.Version.Specs for Go 1.22. While we're here, let's be stricter about event names too, and move tracev2.EventString to be a method on the version, so we can be more precise. An intended consequence of this move is that tracev2 no longer depends on fmt, since we will want the runtime to depend on tracev2 in the near future. Change-Id: If7285460c8ba59ab73da00993b7b12e61cdfe6a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/644219 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-02-10internal/trace: rename go122 to tracev2Michael Anthony Knyszek
This change follows up from the previous one which renamed oldtrace to tracev1, defining everything Go 1.22+ as trace v2. This change also re-maps some packages in preparation for sharing with other parts of the standard library, like the runtime. It also cleans up some other uses of 'go122' that are just a bit misleading. The mappings are as follows: - internal/trace/event -> internal/trace/tracev2/event - internal/trace/event/go122 -> internal/trace/tracev2 - internal/trace/internal/testgen/go122 -> internal/trace/internal/testgen The CL updates all import paths and runs gofmt -w -s on the entire subdirectory. Change-Id: I35476c679a96d4eafad6b94bac5f88aa7b085d2f Reviewed-on: https://go-review.googlesource.com/c/go/+/644218 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-07internal/trace: rename "oldtrace" to trace v1Michael Anthony Knyszek
This is part of a refactoring to better distinguish trace wire format versions. Even though details may change between Go versions and they might be backwards-incompatible, the trace format still broadly has two wire formats: v1 and v2. A follow-up change will rename go122 to v2 to make this more consistent. Change-Id: If4fe1c82d8aeabc8baa05f525e08a9e7d469a5c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/644217 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-02-07internal/trace: refactor how experimental batches are exposedMichael Anthony Knyszek
This change modifies how per-generation experimental batches are exposed. Rather than expose them on the ExperimentalEvent, it exposes it as part of the Sync event, so it's clear to the caller when the information becomes relevant and when it should be parsed. This change also adds a field to each ExperimentalEvent indicating which experiment the event is a part of. Because this information needs to appear *before* a generation is observed, we now ensure there is a sync event both before and after each generation. This means the final sync event is now a special case; previously we would only emit a sync event after each generation. This change is based on feedback from Austin Clements on the experimental events functionality. For #62627. Change-Id: I48b0fe12b22abb7ac8820a9e73447bfed8419856 Reviewed-on: https://go-review.googlesource.com/c/go/+/644215 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-22internal/trace: make Reader output deterministicRhys Hiltner
Multiple Ms can offer Events with identical timestamps. The Reader edits those so the timestamps are strictly increasing, but it needs a way to break the tie. Use something deterministic (such as the order of the batches), rather than map iteration order. Updates #68277 Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/596355 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-05-17internal/trace: move v2 tracer into trace directoryCarlos Amedee
This change moves the v2 tracer into the trace directory. Updates #67367 Change-Id: I3657b4227002cb00fdf29c797434800ea796715e Reviewed-on: https://go-review.googlesource.com/c/go/+/584538 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>