-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeCheck.go
More file actions
62 lines (51 loc) · 965 Bytes
/
timeCheck.go
File metadata and controls
62 lines (51 loc) · 965 Bytes
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
package zlock_check
import (
"sync"
"time"
)
var timeCheck *TimeCheck
var timeOnce sync.Once
type TimeCheck struct {
chans chan *RespCheck
}
type RespCheck struct {
FuncName string
DiffTime int64
}
func newTimeCheck() *TimeCheck {
timeOnce.Do(func() {
timeCheck = &TimeCheck{
chans: make(chan *RespCheck,1000),
}
})
return timeCheck
}
func GetTimeChan() chan *RespCheck{
return newTimeCheck().chans
}
func (c *TimeCheck)setChan(diff int64,funcName string ) {
select {
case c.chans <- &RespCheck{
FuncName: funcName,
DiffTime: diff,
}:
default:
}
}
func TimeStart() int64 {
return time.Now().UnixNano() / 1000000
}
// 毫秒超过多少毫秒打印
func TimeEnd(startTime int64,funcName string ,overs ...int64) {
lastTime := time.Now().UnixNano() / 1000000
diff := lastTime- startTime
var over int64
if overs != nil {
over = overs[0]
}else{
over = 100
}
if diff > over{
newTimeCheck().setChan(diff,funcName)
}
}