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.
5 // Tests user tasks, regions, and logging.
20 bgctx, cancel := context.WithCancel(context.Background())
23 // Create a pre-existing region. This won't end up in the trace.
24 preExistingRegion := trace.StartRegion(bgctx, "pre-existing region")
27 if err := trace.Start(os.Stdout); err != nil {
28 log.Fatalf("failed to start tracing: %v", err)
31 // Beginning of traced execution.
33 ctx, task := trace.NewTask(bgctx, "task0") // EvUserTaskCreate("task0")
37 defer task.End() // EvUserTaskEnd("task0")
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")
44 // EvUserRegionEnd("region0", end)
49 preExistingRegion.End()
50 postExistingRegion := trace.StartRegion(bgctx, "post-existing region")
52 // End of traced execution.
55 postExistingRegion.End()