[go] internal/trace: make Reader output deterministic

1 view
Skip to first unread message

Rhys Hiltner (Gerrit)

unread,
Jul 2, 2024, 6:37:44 PM (yesterday) Jul 2
to goph...@pubsubhelper.golang.org, Rhys Hiltner, golang-co...@googlegroups.com

Rhys Hiltner has uploaded the change for review

Commit message

internal/trace: make Reader output deterministic

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

Change diff

diff --git a/src/internal/trace/generation.go b/src/internal/trace/generation.go
index 098d1d4..98bbf43 100644
--- a/src/internal/trace/generation.go
+++ b/src/internal/trace/generation.go
@@ -25,6 +25,7 @@
type generation struct {
gen uint64
batches map[ThreadID][]batch
+ batchMs []ThreadID
cpuSamples []cpuSample
*evTable
}
@@ -169,6 +170,9 @@
return err
}
default:
+ if _, ok := g.batches[b.m]; !ok {
+ g.batchMs = append(g.batchMs, b.m)
+ }
g.batches[b.m] = append(g.batches[b.m], b)
}
return nil
diff --git a/src/internal/trace/reader.go b/src/internal/trace/reader.go
index c05d5b5..8115729 100644
--- a/src/internal/trace/reader.go
+++ b/src/internal/trace/reader.go
@@ -142,7 +142,8 @@
r.cpuSamples = r.gen.cpuSamples

// Reset frontier.
- for m, batches := range r.gen.batches {
+ for _, m := range r.gen.batchMs {
+ batches := r.gen.batches[m]
bc := &batchCursor{m: m}
ok, err := bc.nextEvent(batches, r.gen.freq)
if err != nil {
diff --git a/src/internal/trace/trace_test.go b/src/internal/trace/trace_test.go
index 7dc5cbb..1929069 100644
--- a/src/internal/trace/trace_test.go
+++ b/src/internal/trace/trace_test.go
@@ -507,7 +507,7 @@
case "js", "wasip1":
t.Skip("no os.Pipe on " + runtime.GOOS)
}
- testTraceProg(t, "stress.go", nil)
+ testTraceProg(t, "stress.go", checkReaderDeterminism)
}

func TestTraceStressStartStop(t *testing.T) {
@@ -535,6 +535,43 @@
testTraceProg(t, "iter-pull.go", nil)
}

+func checkReaderDeterminism(t *testing.T, tb, _ []byte, _ bool) {
+ events := func() []trace.Event {
+ var evs []trace.Event
+
+ r, err := trace.NewReader(bytes.NewReader(tb))
+ if err != nil {
+ t.Error(err)
+ }
+ for {
+ ev, err := r.ReadEvent()
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ evs = append(evs, ev)
+ }
+
+ return evs
+ }
+
+ evs1 := events()
+ evs2 := events()
+
+ if l1, l2 := len(evs1), len(evs2); l1 != l2 {
+ t.Fatalf("re-reading trace gives different event count (%d != %d)", l1, l2)
+ }
+ for i, ev1 := range evs1 {
+ ev2 := evs2[i]
+ if s1, s2 := ev1.String(), ev2.String(); s1 != s2 {
+ t.Errorf("re-reading trace gives different event %d:\n%s\n%s\n", i, s1, s2)
+ break
+ }
+ }
+}
+
func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace, stderr []byte, stress bool)) {
testenv.MustHaveGoRun(t)

Change information

Files:
  • M src/internal/trace/generation.go
  • M src/internal/trace/reader.go
  • M src/internal/trace/trace_test.go
Change size: S
Delta: 3 files changed, 44 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4
Gerrit-Change-Number: 596355
Gerrit-PatchSet: 1
Gerrit-Owner: Rhys Hiltner <rhys.h...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Rhys Hiltner (Gerrit)

unread,
Jul 2, 2024, 6:39:36 PM (yesterday) Jul 2
to Rhys Hiltner, goph...@pubsubhelper.golang.org, Michael Knyszek, Carlos Amedee, Michael Pratt, golang-co...@googlegroups.com
Attention needed from Michael Knyszek

Rhys Hiltner voted

Auto-Submit+1
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Michael Knyszek
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4
Gerrit-Change-Number: 596355
Gerrit-PatchSet: 1
Gerrit-Owner: Rhys Hiltner <rhys.h...@gmail.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: Rhys Hiltner <rhys.h...@gmail.com>
Gerrit-CC: Carlos Amedee <car...@golang.org>
Gerrit-CC: Michael Pratt <mpr...@google.com>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
Gerrit-Comment-Date: Tue, 02 Jul 2024 22:39:21 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Than McIntosh (Gerrit)

unread,
8:45 AM (13 hours ago) 8:45 AM
to Rhys Hiltner, goph...@pubsubhelper.golang.org, Than McIntosh, Go LUCI, Michael Knyszek, Carlos Amedee, Michael Pratt, golang-co...@googlegroups.com
Attention needed from Michael Knyszek and Rhys Hiltner

Than McIntosh voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Michael Knyszek
  • Rhys Hiltner
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4
    Gerrit-Change-Number: 596355
    Gerrit-PatchSet: 1
    Gerrit-Owner: Rhys Hiltner <rhys.h...@gmail.com>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Reviewer: Rhys Hiltner <rhys.h...@gmail.com>
    Gerrit-Reviewer: Than McIntosh <th...@google.com>
    Gerrit-CC: Carlos Amedee <car...@golang.org>
    Gerrit-CC: Michael Pratt <mpr...@google.com>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Rhys Hiltner <rhys.h...@gmail.com>
    Gerrit-Comment-Date: Wed, 03 Jul 2024 12:45:49 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Michael Pratt (Gerrit)

    unread,
    10:35 AM (11 hours ago) 10:35 AM
    to Rhys Hiltner, goph...@pubsubhelper.golang.org, Michael Pratt, Than McIntosh, Go LUCI, Michael Knyszek, Carlos Amedee, golang-co...@googlegroups.com
    Attention needed from Michael Knyszek and Rhys Hiltner

    Michael Pratt voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Michael Knyszek
    • Rhys Hiltner
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4
      Gerrit-Change-Number: 596355
      Gerrit-PatchSet: 1
      Gerrit-Owner: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
      Gerrit-Reviewer: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Reviewer: Than McIntosh <th...@google.com>
      Gerrit-CC: Carlos Amedee <car...@golang.org>
      Gerrit-Attention: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Comment-Date: Wed, 03 Jul 2024 14:35:38 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Carlos Amedee (Gerrit)

      unread,
      3:17 PM (6 hours ago) 3:17 PM
      to Rhys Hiltner, goph...@pubsubhelper.golang.org, Michael Pratt, Than McIntosh, Go LUCI, Michael Knyszek, golang-co...@googlegroups.com
      Attention needed from Michael Knyszek and Rhys Hiltner

      Carlos Amedee voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Michael Knyszek
      • Rhys Hiltner
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I4a1f70c1669ce1c9b52d09e2bc99acbc831ef9a4
      Gerrit-Change-Number: 596355
      Gerrit-PatchSet: 1
      Gerrit-Owner: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
      Gerrit-Reviewer: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Reviewer: Than McIntosh <th...@google.com>
      Gerrit-Attention: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Rhys Hiltner <rhys.h...@gmail.com>
      Gerrit-Comment-Date: Wed, 03 Jul 2024 19:17:29 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages