...
Source file
src/runtime/runtime_unix_test.go
Documentation: runtime
1
2
3
4
5
6
7
8
9
10
11
12 package runtime_test
13
14 import (
15 "runtime"
16 "sync"
17 "sync/atomic"
18 "syscall"
19 "testing"
20 )
21
22 func TestGoroutineProfile(t *testing.T) {
23
24
25
26 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(100))
27
28 var stop uint32
29 defer atomic.StoreUint32(&stop, 1)
30
31 var wg sync.WaitGroup
32 for i := 0; i < 4; i++ {
33 wg.Add(1)
34 go func() {
35 for atomic.LoadUint32(&stop) == 0 {
36 syscall.Close(-1)
37 }
38 wg.Done()
39 }()
40 }
41
42 max := 10000
43 if testing.Short() {
44 max = 100
45 }
46 stk := make([]runtime.StackRecord, 128)
47 for n := 0; n < max; n++ {
48 _, ok := runtime.GoroutineProfile(stk)
49 if !ok {
50 t.Fatalf("GoroutineProfile failed")
51 }
52 }
53
54
55 atomic.StoreUint32(&stop, 1)
56 wg.Wait()
57 }
58
View as plain text