...
1
2
3
4
5 package main
6
7
8
9
15 import "C"
16
17 import (
18 "fmt"
19 "io"
20 "runtime"
21 "runtime/pprof"
22 "time"
23 "unsafe"
24 )
25
26 func init() {
27 register("GoroutineProfile", GoroutineProfile)
28 }
29
30 func GoroutineProfile() {
31 runtime.SetCgoTraceback(0, unsafe.Pointer(C.gprofCgoTraceback), unsafe.Pointer(C.gprofCgoContext), nil)
32
33 go C.CallGoSleep()
34 go C.CallGoSleep()
35 go C.CallGoSleep()
36 time.Sleep(1 * time.Second)
37
38 prof := pprof.Lookup("goroutine")
39 prof.WriteTo(io.Discard, 1)
40 fmt.Println("OK")
41 }
42
43
44 func GoSleep() {
45 time.Sleep(time.Hour)
46 }
47
View as plain text