1
2
3
4
5
6
7
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
24 preExistingRegion := trace.StartRegion(bgctx, "pre-existing region")
25
26
27 if err := trace.Start(os.Stdout); err != nil {
28 log.Fatalf("failed to start tracing: %v", err)
29 }
30
31
32 var wg sync.WaitGroup
33 ctx, task := trace.NewTask(bgctx, "task0")
34 trace.StartRegion(ctx, "task0 region")
35
36 wg.Add(1)
37 go func() {
38 defer wg.Done()
39 defer task.End()
40
41 trace.StartRegion(ctx, "unended region")
42
43 trace.WithRegion(ctx, "region0", func() {
44
45 trace.WithRegion(ctx, "region1", func() {
46 trace.Log(ctx, "key0", "0123456789abcdef")
47 })
48
49 })
50 }()
51 wg.Wait()
52
53 preExistingRegion.End()
54 postExistingRegion := trace.StartRegion(bgctx, "post-existing region")
55
56
57 trace.Stop()
58
59 postExistingRegion.End()
60 }
61
View as plain text