-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/trace, x/exp/trace: nondeterministic output, seems related to timestamp tie-breaking #68277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, this appears due to map iteration in https://github.com/golang/go/blob/go1.23rc1/src/internal/trace/reader.go#L145 Forcing a sort (such as with
|
Change https://go.dev/cl/596355 mentions this issue: |
Moving this to the 1.23 milestone, please comment if any issues with that. |
Thanks. Yes, the problem starts in std's internal/trace (not the generated copy in x/exp/trace) so a release milestone is right. Go 1.23 would be great if the door is still open for small fixes like this. Otherwise 1.24. I plan to send a CL for x/exp/trace (with a "Fixes" line) once internal/trace has https://go.dev/cl/596355, independent of the main Go release cycle. |
Thanks for sending a fix! I think whether this fix should go into Go 1.23 depends on whether we would backport it anyway in the Go 1.24 dev cycle. I'm not totally sure that we would, because the issue doesn't actually impact most That being said, I do think this is an important property of the trace parser to maintain, and I don't want any blockers for the public parser API sitting around too long. FWIW, I think golang.org/x/exp/trace could definitely get updated with this patch before it lands on tip. Here's what I propose:
Thoughts? |
Change https://go.dev/cl/597177 mentions this issue: |
That sounds like a fine plan, yes. My own usage depends on x/exp getting the fix, and not at all on it landing in the core repo before the tree opens for Go 1.24. The severity in cmd/trace is pretty low. Some day I'd like to be able to deep-link into the I wonder though if all trace parsers should be able to agree on the full details of all events (including timestamp), and thus if there should be a more principled tie-breaker, rather than forcing the other maintainers ( @dominikh , @felixge , maybe others?) to be bug-compatible with this one. |
I agree, I think that's something that should be documented in a wire format doc (once that exists). |
Generated from CL 596355 at PS 1, "make Reader output deterministic". Updates golang/go#68277 [git-generate] cd ./trace ./gen.bash $GOROOT Change-Id: I8cb802a85933271cc7c5df975f6e772a42ea5f7b Reviewed-on: https://go-review.googlesource.com/c/exp/+/597177 Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
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>
Fixed in x/exp, fixed in internal/trace. |
(This also affects go1.22.4.)
After preparing an execution trace like so ...
... I read it back with
go tool trace -d=1
(and with other tools based on golang.org/x/exp/trace). The results vary each time due to differences in the reported timestamp for some events. The events in question have sequential timestamps, which makes me suspect there's a tie which is getting resolved when reading back the trace, exposing some nondeterminism from map iteration order.I expected the results of
go tool trace -d=1
to be identical each time for a given execution trace. I expected that reading an execution trace with a golang.org/x/exp/trace.Reader and passing each Event to fmt.Print would give identical results on each run. I expected that loading an execution trace twice with golang.org/x/exp/trace.Reader and advancing to a particular timestamp would result in seeing the "same" Event.CC @golang/runtime @mknyszek
Note that the contents of Events 2 and 3 are swapped between the first and second run, with the timestamps remaining monotonic.
With 930k events, several thousand will end up as additional/non-unique lines between two runs of
go tool trace -d=1
.The text was updated successfully, but these errors were encountered: