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 a many interesting cases (network, syscalls, a little GC, busy goroutines,
6 // blocked goroutines, LockOSThread, pipes, and GOMAXPROCS).
24 done := make(chan bool)
26 // Create a goroutine blocked before tracing.
33 // Create a goroutine blocked in syscall before tracing.
34 rp, wp, err := os.Pipe()
36 log.Fatalf("failed to create pipe: %v", err)
49 time.Sleep(time.Millisecond) // give the goroutine above time to block
51 if err := trace.Start(os.Stdout); err != nil {
52 log.Fatalf("failed to start tracing: %v", err)
56 procs := runtime.GOMAXPROCS(10)
57 time.Sleep(50 * time.Millisecond) // test proc stop/start events
60 runtime.LockOSThread()
72 // Trigger GC from malloc.
74 for i := 0; i < n; i++ {
75 _ = make([]byte, 1<<20)
78 // Create a bunch of busy goroutines to load all Ps.
79 for p := 0; p < 10; p++ {
82 // Do something useful.
83 tmp := make([]byte, 1<<16)
103 timerDone := make(chan bool)
105 time.Sleep(time.Millisecond)
111 ln, err := net.Listen("tcp", "127.0.0.1:0")
113 log.Fatalf("listen failed: %v", err)
117 c, err := ln.Accept()
121 time.Sleep(time.Millisecond)
126 c, err := net.Dial("tcp", ln.Addr().String())
128 log.Fatalf("dial failed: %v", err)
139 // Unblock helper goroutines and wait them to finish.
145 runtime.GOMAXPROCS(procs)