-
Notifications
You must be signed in to change notification settings - Fork 182
/
execution_exchain.go
64 lines (54 loc) · 1.21 KB
/
execution_exchain.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
59
60
61
62
63
64
package state
import (
"log"
"os"
"path"
"runtime"
"runtime/pprof"
"strconv"
"time"
)
const (
FlagApplyBlockPprofTime = "applyblock-pprof-time"
)
var (
IgnoreSmbCheck bool = false
ApplyBlockPprofTime = -1
HomeDir = ""
tmpPprofName = "tmp.cpu.pprof"
)
func SetIgnoreSmbCheck(check bool) {
IgnoreSmbCheck = check
}
func PprofStart() (*os.File, time.Time) {
startTime := time.Now()
p := getFilePath("")
if _, err := os.Stat(p); os.IsNotExist(err) {
err := os.MkdirAll(p, 0755)
if err != nil {
log.Fatal(err)
}
}
f, err := os.OpenFile(path.Join(p, tmpPprofName), os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatal(err)
}
runtime.SetCPUProfileRate(300)
pprof.StartCPUProfile(f)
return f, startTime
}
func PprofEnd(height int, f *os.File, startTime time.Time) {
pprof.StopCPUProfile()
f.Close()
sec := time.Since(startTime).Milliseconds()
if int(sec) >= ApplyBlockPprofTime {
pprofName := "pprof." + strconv.Itoa(height) + "-" + strconv.Itoa(int(sec)) + "ms.bin"
newDir := getFilePath(pprofName)
os.Rename(getFilePath(tmpPprofName), newDir)
} else {
os.Remove(getFilePath(tmpPprofName))
}
}
func getFilePath(fileName string) string {
return path.Join(HomeDir, "pprof", fileName)
}