golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/testdata/generators/go122-task-across-generations.go (about) 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/v2; DO NOT EDIT. 6 7 //go:build go1.21 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/event/go122" 22 testgen "golang.org/x/exp/trace/internal/testgen/go122" 23 ) 24 25 func main() { 26 testgen.Main(gen) 27 } 28 29 func gen(t *testgen.Trace) { 30 g1 := t.Generation(1) 31 32 // A running goroutine emits a task begin. 33 b1 := g1.Batch(trace.ThreadID(0), 0) 34 b1.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning) 35 b1.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning) 36 b1.Event("UserTaskBegin", trace.TaskID(2), trace.TaskID(0) /* 0 means no parent, not background */, "my task", testgen.NoStack) 37 38 g2 := t.Generation(2) 39 40 // That same goroutine emits a task end in the following generation. 41 b2 := g2.Batch(trace.ThreadID(0), 5) 42 b2.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning) 43 b2.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning) 44 b2.Event("UserTaskEnd", trace.TaskID(2), testgen.NoStack) 45 }