...
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "log"
14 "math/rand"
15 "os"
16 "runtime"
17 "runtime/trace"
18 "time"
19 )
20
21 type node struct {
22 children [4]*node
23 data [128]byte
24 }
25
26 func makeTree(depth int) *node {
27 if depth == 0 {
28 return new(node)
29 }
30 return &node{
31 children: [4]*node{
32 makeTree(depth - 1),
33 makeTree(depth - 1),
34 makeTree(depth - 1),
35 makeTree(depth - 1),
36 },
37 }
38 }
39
40 var trees [16]*node
41 var ballast *[16]*[8192]*node
42 var sink []byte
43
44 func main() {
45 for i := range trees {
46 trees[i] = makeTree(6)
47 }
48 ballast = new([16]*[8192]*node)
49 for i := range ballast {
50 ballast[i] = new([8192]*node)
51 for j := range ballast[i] {
52 ballast[i][j] = &node{
53 data: [128]byte{1, 2, 3, 4},
54 }
55 }
56 }
57 for i := 0; i < runtime.GOMAXPROCS(-1); i++ {
58 go func() {
59 for {
60 sink = make([]byte, rand.Intn(32<<10))
61 }
62 }()
63 }
64
65
66 time.Sleep(5 * time.Millisecond)
67
68
69 if err := trace.Start(os.Stdout); err != nil {
70 log.Fatalf("failed to start tracing: %v", err)
71 }
72 defer trace.Stop()
73
74
75 time.Sleep(400 * time.Millisecond)
76 }
77
View as plain text