Debian Codegraph @

trace/testdata/generators/go122-task-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 issue is that EvUserTaskEnd events don't carry the
12 // task type with them, so the parser needs to track that
13 // information. But if the parser just tracks the string ID
14 // and not the string itself, that string ID may not be valid
15 // for use in future generations.
16
17 package main
18
19 import (
20 "golang.org/x/exp/trace"
21 "golang.org/x/exp/trace/internal/testgen"
22 "golang.org/x/exp/trace/internal/tracev2"
23 "golang.org/x/exp/trace/internal/version"
24 )
25
26 func main() {
27 testgen.Main(version.Go122, gen)
28 }
29
30 func gen(t *testgen.Trace) {
31 g1 := t.Generation(1)
32
33 // A running goroutine emits a task begin.
34 b1 := g1.Batch(trace.ThreadID(0), 0)
35 b1.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
36 b1.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunning)
37 b1.Event("UserTaskBegin", trace.TaskID(2), trace.TaskID(0) /* 0 means no parent, not background */, "my task", testgen.NoStack)
38
39 g2 := t.Generation(2)
40
41 // That same goroutine emits a task end in the following generation.
42 b2 := g2.Batch(trace.ThreadID(0), 5)
43 b2.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
44 b2.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunning)
45 b2.Event("UserTaskEnd", trace.TaskID(2), testgen.NoStack)
46 }