-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshell.go
55 lines (50 loc) · 1.17 KB
/
shell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cmd
import (
"log"
"os"
"strconv"
"github.com/funny/pprof"
)
func (cmd *CMD) initShell(name string) {
cmd.Register(
"help",
"Print this screen",
func() {
cmd.Help(os.Stderr)
},
)
cmd.Register(
"cpuprof (start|stop)",
"Start or stop cpu profile. The profile will saved to "+name+".cpu.prof.",
func(args []string) {
switch args[1] {
case "start":
pprof.StartCPUProfile(name + ".cpu.prof")
case "stop":
pprof.StopCPUProfile()
}
},
)
cmd.Register(
"lookup (block|gc|goroutine|heap|threadcreate) ([0-9]{0,4})",
"Dump pprof data",
func(args []string) {
switch args[1] {
case "block":
debug, _ := strconv.Atoi(args[2])
pprof.SaveProfile("block", name+".block.prof", debug)
case "gc":
log.Printf("lookup gc: %s", pprof.GCSummary())
case "goroutine":
debug, _ := strconv.Atoi(args[2])
pprof.SaveProfile("goroutine", name+".goroutine.prof", debug)
case "heap":
debug, _ := strconv.Atoi(args[2])
pprof.SaveProfile("heap", name+".heap.prof", debug)
case "threadcreate":
debug, _ := strconv.Atoi(args[2])
pprof.SaveProfile("threadcreate", name+".threadcreate.prof", debug)
}
},
)
}