1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "log"
14 "os"
15 "runtime"
16 "runtime/trace"
17 "time"
18 )
19
20 func main() {
21
22
23
24 go func() {
25 for {
26 runtime.GC()
27 time.Sleep(1 * time.Millisecond)
28 }
29 }()
30
31
32 if err := trace.Start(os.Stdout); err != nil {
33 log.Fatalf("failed to start tracing: %v", err)
34 }
35
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
45 trace.Stop()
46 }
47
View as plain text