/
profile.go
40 lines (31 loc) · 875 Bytes
/
profile.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
package servitization
import (
"os"
"runtime/pprof"
)
var (
cpuProfFile *os.File
memProfFile *os.File
blockProfFile *os.File
goroutineProfFile *os.File
threadcreateProfFile *os.File
)
func startProfiling() {
cpuProfFile, _ = os.Create("cpu.prof")
memProfFile, _ = os.Create("memory.prof")
blockProfFile, _ = os.Create("block.prof")
goroutineProfFile, _ = os.Create("goroutine.prof")
threadcreateProfFile, _ = os.Create("threadcreate.prof")
pprof.StartCPUProfile(cpuProfFile)
}
func saveProfiling() {
goroutine := pprof.Lookup("goroutine")
goroutine.WriteTo(goroutineProfFile, 1)
heap := pprof.Lookup("heap")
heap.WriteTo(memProfFile, 1)
block := pprof.Lookup("block")
block.WriteTo(blockProfFile, 1)
threadcreate := pprof.Lookup("threadcreate")
threadcreate.WriteTo(threadcreateProfFile, 1)
pprof.StopCPUProfile()
}