File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 17
17
RedisPoolSize int
18
18
Debug bool
19
19
BGPushPoolSize int
20
+ CPUProfile string
20
21
)
21
22
22
23
func init () {
@@ -61,6 +62,10 @@ func init() {
61
62
Description : "Number of goroutines to have processing NOBLOCK Q*PUSH commands" ,
62
63
Default : "128" ,
63
64
})
65
+ l .Add (lever.Param {
66
+ Name : "--cpu-profile" ,
67
+ Description : "Name of a file to write a cpu profile out to. If set the cpu profile will be written until okq is closed" ,
68
+ })
64
69
l .Parse ()
65
70
66
71
ListenAddr , _ = l .ParamStr ("--listen-addr" )
@@ -71,4 +76,5 @@ func init() {
71
76
RedisPoolSize , _ = l .ParamInt ("--redis-pool-size" )
72
77
Debug = l .ParamFlag ("--debug" )
73
78
BGPushPoolSize , _ = l .ParamInt ("--bg-push-pool-size" )
79
+ CPUProfile , _ = l .ParamStr ("--cpu-profile" )
74
80
}
Original file line number Diff line number Diff line change 4
4
"errors"
5
5
"math/rand"
6
6
"net"
7
+ "os"
8
+ "os/signal"
9
+ "runtime/pprof"
7
10
"time"
8
11
9
12
"github.com/mc0/okq/clients"
@@ -27,6 +30,10 @@ func main() {
27
30
28
31
incomingConns := make (chan net.Conn )
29
32
33
+ if config .CPUProfile != "" {
34
+ go cpuProfile (config .CPUProfile )
35
+ }
36
+
30
37
go acceptConns (server , incomingConns )
31
38
32
39
for {
@@ -93,3 +100,19 @@ outer:
93
100
commands .Dispatch (client , command , args )
94
101
}
95
102
}
103
+
104
+ func cpuProfile (filename string ) {
105
+ log .L .Printf ("starting cpu profile, writing to %q" , filename )
106
+ f , err := os .Create (filename )
107
+ if err != nil {
108
+ log .L .Fatalf ("could not open cpu profile %q: %s" , filename , err )
109
+ }
110
+ pprof .StartCPUProfile (f )
111
+
112
+ ch := make (chan os.Signal , 1 )
113
+ signal .Notify (ch , os .Interrupt )
114
+ <- ch
115
+ pprof .StopCPUProfile ()
116
+ signal .Stop (ch )
117
+ log .L .Printf ("stopping cpu profile, ctrl-c again to exit" )
118
+ }
You can’t perform that action at this time.
0 commit comments