File size: 1,403 Bytes
13c2bf6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Tests user tasks, regions, and logging.
//go:build ignore
package main
import (
"context"
"log"
"os"
"runtime/trace"
"sync"
)
func main() {
bgctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create a pre-existing region. This won't end up in the trace.
preExistingRegion := trace.StartRegion(bgctx, "pre-existing region")
// Start tracing.
if err := trace.Start(os.Stdout); err != nil {
log.Fatalf("failed to start tracing: %v", err)
}
// Beginning of traced execution.
var wg sync.WaitGroup
ctx, task := trace.NewTask(bgctx, "task0") // EvUserTaskCreate("task0")
trace.StartRegion(ctx, "task0 region")
wg.Add(1)
go func() {
defer wg.Done()
defer task.End() // EvUserTaskEnd("task0")
trace.StartRegion(ctx, "unended region")
trace.WithRegion(ctx, "region0", func() {
// EvUserRegionBegin("region0", start)
trace.WithRegion(ctx, "region1", func() {
trace.Log(ctx, "key0", "0123456789abcdef") // EvUserLog("task0", "key0", "0....f")
})
// EvUserRegionEnd("region0", end)
})
}()
wg.Wait()
preExistingRegion.End()
postExistingRegion := trace.StartRegion(bgctx, "post-existing region")
// End of traced execution.
trace.Stop()
postExistingRegion.End()
}
|