Start starts Go's runtime tracing facility. Traces will be written to the file named by [debug.Debug.Trace]. It also starts a new [*trace.Task] that will be stopped when the cleanup is called.
(base context.Context)
| 13 | // Traces will be written to the file named by [debug.Debug.Trace]. |
| 14 | // It also starts a new [*trace.Task] that will be stopped when the cleanup is called. |
| 15 | func Start(base context.Context) (_ context.Context, cleanup func(), _ error) { |
| 16 | f, err := os.Create(debug.Debug.Trace) |
| 17 | if err != nil { |
| 18 | return base, cleanup, fmt.Errorf("failed to create trace output file: %v", err) |
| 19 | } |
| 20 | |
| 21 | if err := trace.Start(f); err != nil { |
| 22 | return base, cleanup, fmt.Errorf("failed to start trace: %v", err) |
| 23 | } |
| 24 | |
| 25 | ctx, task := trace.NewTask(base, "sqlc") |
| 26 | |
| 27 | return ctx, func() { |
| 28 | defer f.Close() |
| 29 | defer trace.Stop() |
| 30 | defer task.End() |
| 31 | }, nil |
| 32 | } |