/
pprof.go
58 lines (49 loc) · 1.35 KB
/
pprof.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
56
57
58
package debugger
/*
* go pprof.
* author: CC
* email : 151503324@qq.com
* date : 2021.08.06
*/
import (
"os"
"runtime/pprof"
"sync"
)
/************************************************************************/
// constants, variables, structs, interfaces.
/************************************************************************/
type Pprof struct {
sync.Mutex
profile *string
fp *os.File
}
/************************************************************************/
// export functions.
/************************************************************************/
// open pprof.
func (this *Pprof) Open(fname string) {
// this.profile = flag.String("cpuprofile", "", "write cpu profile")
// flag.Parse()
// f, err := os.Create(*this.profile)
f, err := os.Create(fname)
if err != nil {
LogError("os.Create:", err)
return
}
this.fp = f
pprof.StartCPUProfile(this.fp)
}
// close pprof.
func (this *Pprof) Close() {
// defer os.Exit(1)
pprof.StopCPUProfile()
this.fp.Close()
LogInfo("pprof.go - Closed")
}
/************************************************************************/
// moudule functions.
/************************************************************************/
/************************************************************************/
// unit tests.
/************************************************************************/