Debian Codegraph @

src/internal/trace/testdata/testprog/gomaxprocs.go

raw
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 increasing and decreasing GOMAXPROCS to try and
6 // catch issues with stale proc state.
7
8 //go:build ignore
9
10 package main
11
12 import (
13 "log"
14 "os"
15 "runtime"
16 "runtime/trace"
17 "time"
18 )
19
20 func main() {
21 // Start a goroutine that calls runtime.GC to try and
22 // introduce some interesting events in between the
23 // GOMAXPROCS calls.
24 go func() {
25 for {
26 runtime.GC()
27 time.Sleep(1 * time.Millisecond)
28 }
29 }()
30
31 // Start tracing.
32 if err := trace.Start(os.Stdout); err != nil {
33 log.Fatalf("failed to start tracing: %v", err)
34 }
35 // Run GOMAXPROCS a bunch of times, up and down.
36 for i := 1; i <= 16; i *= 2 {
37 runtime.GOMAXPROCS(i)
38 time.Sleep(1 * time.Millisecond)
39 }
40 for i := 16; i >= 1; i /= 2 {
41 runtime.GOMAXPROCS(i)
42 time.Sleep(1 * time.Millisecond)
43 }
44 // Stop tracing.
45 trace.Stop()
46 }