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 simply starting and stopping tracing multiple times.
6//
7// This is useful for finding bugs in trace state reset.
8
9//go:build ignore
10
11package main
12
13import (
14	"bytes"
15	"log"
16	"os"
17	"runtime"
18	"runtime/trace"
19)
20
21func main() {
22	// Trace a few times.
23	for i := 0; i < 10; i++ {
24		var buf bytes.Buffer
25		if err := trace.Start(&buf); err != nil {
26			log.Fatalf("failed to start tracing: %v", err)
27		}
28		runtime.GC()
29		trace.Stop()
30	}
31
32	// Start tracing again, this time writing out the result.
33	if err := trace.Start(os.Stdout); err != nil {
34		log.Fatalf("failed to start tracing: %v", err)
35	}
36	runtime.GC()
37	trace.Stop()
38}
39