Debian Codegraph @

trace/testdata/generators/go122-confuse-seq-across-generations.go

raw symbols SCIP
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Code generated by "gen.bash" from internal/trace; DO NOT EDIT.
6
7 //go:build go1.23
8
9 // Regression test for an issue found in development.
10 //
11 // The core of the issue is that if generation counters
12 // aren't considered as part of sequence numbers, then
13 // it's possible to accidentally advance without a
14 // GoStatus event.
15 //
16 // The situation is one in which it just so happens that
17 // an event on the frontier for a following generation
18 // has a sequence number exactly one higher than the last
19 // sequence number for e.g. a goroutine in the previous
20 // generation. The parser should wait to find a GoStatus
21 // event before advancing into the next generation at all.
22 // It turns out this situation is pretty rare; the GoStatus
23 // event almost always shows up first in practice. But it
24 // can and did happen.
25
26 package main
27
28 import (
29 "golang.org/x/exp/trace"
30 "golang.org/x/exp/trace/internal/testgen"
31 "golang.org/x/exp/trace/internal/tracev2"
32 "golang.org/x/exp/trace/internal/version"
33 )
34
35 func main() {
36 testgen.Main(version.Go122, gen)
37 }
38
39 func gen(t *testgen.Trace) {
40 g1 := t.Generation(1)
41
42 // A running goroutine blocks.
43 b10 := g1.Batch(trace.ThreadID(0), 0)
44 b10.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
45 b10.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunning)
46 b10.Event("GoStop", "whatever", testgen.NoStack)
47
48 // The running goroutine gets unblocked.
49 b11 := g1.Batch(trace.ThreadID(1), 0)
50 b11.Event("ProcStatus", trace.ProcID(1), tracev2.ProcRunning)
51 b11.Event("GoStart", trace.GoID(1), testgen.Seq(1))
52 b11.Event("GoStop", "whatever", testgen.NoStack)
53
54 g2 := t.Generation(2)
55
56 // Start running the goroutine, but later.
57 b21 := g2.Batch(trace.ThreadID(1), 3)
58 b21.Event("ProcStatus", trace.ProcID(1), tracev2.ProcRunning)
59 b21.Event("GoStart", trace.GoID(1), testgen.Seq(2))
60
61 // The goroutine starts running, then stops, then starts again.
62 b20 := g2.Batch(trace.ThreadID(0), 5)
63 b20.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
64 b20.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunnable)
65 b20.Event("GoStart", trace.GoID(1), testgen.Seq(1))
66 b20.Event("GoStop", "whatever", testgen.NoStack)
67 }