...
1
2
3
4
5 package main
6
7
8
9
10
11
12
13
14
15
16
17 import "C"
18
19 import (
20 "bytes"
21 "fmt"
22 "runtime/pprof"
23 "time"
24 )
25
26 func init() {
27 register("CgoCCodeSIGPROF", CgoCCodeSIGPROF)
28 }
29
30
31 func GoNop() {}
32
33 func CgoCCodeSIGPROF() {
34 c := make(chan bool)
35 go func() {
36 <-c
37 start := time.Now()
38 for i := 0; i < 1e7; i++ {
39 if i%1000 == 0 {
40 if time.Since(start) > time.Second {
41 break
42 }
43 }
44 C.CallGoNop()
45 }
46 c <- true
47 }()
48
49 var buf bytes.Buffer
50 pprof.StartCPUProfile(&buf)
51 c <- true
52 <-c
53 pprof.StopCPUProfile()
54
55 fmt.Println("OK")
56 }
57
View as plain text