-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtracers.go
57 lines (46 loc) · 1.17 KB
/
tracers.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
package muxtracer
import (
"log"
"sync/atomic"
"time"
)
func logViolation(id Id, threshold Threshold, actual Actual, now Now, violationType ViolationType) {
var idStr string
if id != nil {
idStr = string(id) + " "
}
log.Printf("%sviolation %s section took %s %d (threshold %s)", idStr, violationType.String(), time.Duration(actual).String(), actual, time.Duration(threshold).String())
}
type Threshold uint64
type Actual uint64
type Now uint64
type TraceLocker interface {
EnableTracer()
DisableTracer()
EnableTracerWithOpts(o Opts)
}
func (m *Mutex) EnableTracer() {
m.EnableTracerWithOpts(obtainGlobalOpts())
}
func (m *Mutex) EnableTracerWithOpts(o Opts) {
if o.Id != "" {
m.id = []byte(o.Id)
}
atomic.StoreUint64(&m.threshold, uint64(o.Threshold.Nanoseconds()))
}
func (m *Mutex) DisableTracer() {
atomic.StoreUint64(&m.threshold, 0)
}
func (m *RWMutex) EnableTracer() {
m.EnableTracerWithOpts(obtainGlobalOpts())
}
func (m *RWMutex) EnableTracerWithOpts(o Opts) {
if o.Id != "" {
m.id = []byte(o.Id)
}
atomic.StoreUint64(&m.threshold, uint64(o.Threshold.Nanoseconds()))
}
func (m *RWMutex) DisableTracer() {
atomic.StoreUint64(&m.threshold, 0)
}
type Id []byte