]> Cypherpunks.ru repositories - gostls13.git/blob - src/internal/trace/v2/testdata/testprog/annotations.go
runtime: add execution tracer v2 behind GOEXPERIMENT=exectracer2
[gostls13.git] / src / internal / trace / v2 / testdata / testprog / annotations.go
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 // Tests user tasks, regions, and logging.
6
7 //go:build ignore
8
9 package main
10
11 import (
12         "context"
13         "log"
14         "os"
15         "runtime/trace"
16         "sync"
17 )
18
19 func main() {
20         bgctx, cancel := context.WithCancel(context.Background())
21         defer cancel()
22
23         // Create a pre-existing region. This won't end up in the trace.
24         preExistingRegion := trace.StartRegion(bgctx, "pre-existing region")
25
26         // Start tracing.
27         if err := trace.Start(os.Stdout); err != nil {
28                 log.Fatalf("failed to start tracing: %v", err)
29         }
30
31         // Beginning of traced execution.
32         var wg sync.WaitGroup
33         ctx, task := trace.NewTask(bgctx, "task0") // EvUserTaskCreate("task0")
34         wg.Add(1)
35         go func() {
36                 defer wg.Done()
37                 defer task.End() // EvUserTaskEnd("task0")
38
39                 trace.WithRegion(ctx, "region0", func() {
40                         // EvUserRegionBegin("region0", start)
41                         trace.WithRegion(ctx, "region1", func() {
42                                 trace.Log(ctx, "key0", "0123456789abcdef") // EvUserLog("task0", "key0", "0....f")
43                         })
44                         // EvUserRegionEnd("region0", end)
45                 })
46         }()
47         wg.Wait()
48
49         preExistingRegion.End()
50         postExistingRegion := trace.StartRegion(bgctx, "post-existing region")
51
52         // End of traced execution.
53         trace.Stop()
54
55         postExistingRegion.End()
56 }