Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Sample() to Timer, NilTimer, StandardTimer and TimerSnapshot #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Timer interface {
Rate5() float64
Rate15() float64
RateMean() float64
Sample() Sample
Snapshot() Timer
StdDev() float64
Sum() int64
Expand Down Expand Up @@ -106,6 +107,9 @@ func (NilTimer) Rate15() float64 { return 0.0 }
// RateMean is a no-op.
func (NilTimer) RateMean() float64 { return 0.0 }

// Sample is a no-op.
func (NilTimer) Sample() Sample { return NilSample{} }

// Snapshot is a no-op.
func (NilTimer) Snapshot() Timer { return NilTimer{} }

Expand Down Expand Up @@ -186,6 +190,11 @@ func (t *StandardTimer) RateMean() float64 {
return t.meter.RateMean()
}

// Sample returns the Sample underlying the timer.
func (t *StandardTimer) Sample() Sample {
return t.histogram.Sample()
}

// Snapshot returns a read-only copy of the timer.
func (t *StandardTimer) Snapshot() Timer {
t.mutex.Lock()
Expand Down Expand Up @@ -281,6 +290,9 @@ func (t *TimerSnapshot) Rate15() float64 { return t.meter.Rate15() }
// snapshot was taken.
func (t *TimerSnapshot) RateMean() float64 { return t.meter.RateMean() }

// Sample returns the Sample underlying the histogram.
func (t *TimerSnapshot) Sample() Sample { return t.histogram.Sample() }

// Snapshot returns the snapshot.
func (t *TimerSnapshot) Snapshot() Timer { return t }

Expand Down