|
|
@ -13,7 +13,6 @@ type TimerSnapshot interface { |
|
|
|
// Timer capture the duration and rate of events.
|
|
|
|
// Timer capture the duration and rate of events.
|
|
|
|
type Timer interface { |
|
|
|
type Timer interface { |
|
|
|
Snapshot() TimerSnapshot |
|
|
|
Snapshot() TimerSnapshot |
|
|
|
Stop() |
|
|
|
|
|
|
|
Time(func()) |
|
|
|
Time(func()) |
|
|
|
UpdateSince(time.Time) |
|
|
|
UpdateSince(time.Time) |
|
|
|
Update(time.Duration) |
|
|
|
Update(time.Duration) |
|
|
@ -21,8 +20,6 @@ type Timer interface { |
|
|
|
|
|
|
|
|
|
|
|
// GetOrRegisterTimer returns an existing Timer or constructs and registers a
|
|
|
|
// GetOrRegisterTimer returns an existing Timer or constructs and registers a
|
|
|
|
// new StandardTimer.
|
|
|
|
// new StandardTimer.
|
|
|
|
// Be sure to unregister the meter from the registry once it is of no use to
|
|
|
|
|
|
|
|
// allow for garbage collection.
|
|
|
|
|
|
|
|
func GetOrRegisterTimer(name string, r Registry) Timer { |
|
|
|
func GetOrRegisterTimer(name string, r Registry) Timer { |
|
|
|
if nil == r { |
|
|
|
if nil == r { |
|
|
|
r = DefaultRegistry |
|
|
|
r = DefaultRegistry |
|
|
@ -31,7 +28,6 @@ func GetOrRegisterTimer(name string, r Registry) Timer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewCustomTimer constructs a new StandardTimer from a Histogram and a Meter.
|
|
|
|
// NewCustomTimer constructs a new StandardTimer from a Histogram and a Meter.
|
|
|
|
// Be sure to call Stop() once the timer is of no use to allow for garbage collection.
|
|
|
|
|
|
|
|
func NewCustomTimer(h Histogram, m Meter) Timer { |
|
|
|
func NewCustomTimer(h Histogram, m Meter) Timer { |
|
|
|
if !Enabled { |
|
|
|
if !Enabled { |
|
|
|
return NilTimer{} |
|
|
|
return NilTimer{} |
|
|
@ -43,8 +39,6 @@ func NewCustomTimer(h Histogram, m Meter) Timer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewRegisteredTimer constructs and registers a new StandardTimer.
|
|
|
|
// NewRegisteredTimer constructs and registers a new StandardTimer.
|
|
|
|
// Be sure to unregister the meter from the registry once it is of no use to
|
|
|
|
|
|
|
|
// allow for garbage collection.
|
|
|
|
|
|
|
|
func NewRegisteredTimer(name string, r Registry) Timer { |
|
|
|
func NewRegisteredTimer(name string, r Registry) Timer { |
|
|
|
c := NewTimer() |
|
|
|
c := NewTimer() |
|
|
|
if nil == r { |
|
|
|
if nil == r { |
|
|
@ -56,7 +50,6 @@ func NewRegisteredTimer(name string, r Registry) Timer { |
|
|
|
|
|
|
|
|
|
|
|
// NewTimer constructs a new StandardTimer using an exponentially-decaying
|
|
|
|
// NewTimer constructs a new StandardTimer using an exponentially-decaying
|
|
|
|
// sample with the same reservoir size and alpha as UNIX load averages.
|
|
|
|
// sample with the same reservoir size and alpha as UNIX load averages.
|
|
|
|
// Be sure to call Stop() once the timer is of no use to allow for garbage collection.
|
|
|
|
|
|
|
|
func NewTimer() Timer { |
|
|
|
func NewTimer() Timer { |
|
|
|
if !Enabled { |
|
|
|
if !Enabled { |
|
|
|
return NilTimer{} |
|
|
|
return NilTimer{} |
|
|
@ -71,7 +64,6 @@ func NewTimer() Timer { |
|
|
|
type NilTimer struct{} |
|
|
|
type NilTimer struct{} |
|
|
|
|
|
|
|
|
|
|
|
func (NilTimer) Snapshot() TimerSnapshot { return (*emptySnapshot)(nil) } |
|
|
|
func (NilTimer) Snapshot() TimerSnapshot { return (*emptySnapshot)(nil) } |
|
|
|
func (NilTimer) Stop() {} |
|
|
|
|
|
|
|
func (NilTimer) Time(f func()) { f() } |
|
|
|
func (NilTimer) Time(f func()) { f() } |
|
|
|
func (NilTimer) Update(time.Duration) {} |
|
|
|
func (NilTimer) Update(time.Duration) {} |
|
|
|
func (NilTimer) UpdateSince(time.Time) {} |
|
|
|
func (NilTimer) UpdateSince(time.Time) {} |
|
|
@ -94,11 +86,6 @@ func (t *StandardTimer) Snapshot() TimerSnapshot { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Stop stops the meter.
|
|
|
|
|
|
|
|
func (t *StandardTimer) Stop() { |
|
|
|
|
|
|
|
t.meter.Stop() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Time record the duration of the execution of the given function.
|
|
|
|
// Time record the duration of the execution of the given function.
|
|
|
|
func (t *StandardTimer) Time(f func()) { |
|
|
|
func (t *StandardTimer) Time(f func()) { |
|
|
|
ts := time.Now() |
|
|
|
ts := time.Now() |
|
|
|