forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.go
58 lines (43 loc) · 979 Bytes
/
profiler.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 prof
import "github.com/tal-tech/go-zero/core/utils"
type (
ProfilePoint struct {
*utils.ElapsedTimer
}
Profiler interface {
Start() ProfilePoint
Report(name string, point ProfilePoint)
}
RealProfiler struct{}
NullProfiler struct{}
)
var profiler = newNullProfiler()
func EnableProfiling() {
profiler = newRealProfiler()
}
func Start() ProfilePoint {
return profiler.Start()
}
func Report(name string, point ProfilePoint) {
profiler.Report(name, point)
}
func newRealProfiler() Profiler {
return &RealProfiler{}
}
func (rp *RealProfiler) Start() ProfilePoint {
return ProfilePoint{
ElapsedTimer: utils.NewElapsedTimer(),
}
}
func (rp *RealProfiler) Report(name string, point ProfilePoint) {
duration := point.Duration()
report(name, duration)
}
func newNullProfiler() Profiler {
return &NullProfiler{}
}
func (np *NullProfiler) Start() ProfilePoint {
return ProfilePoint{}
}
func (np *NullProfiler) Report(string, ProfilePoint) {
}