Skip to content

Commit

Permalink
Merge pull request #510 from prometheus/beorn7/timer
Browse files Browse the repository at this point in the history
Return observed duration from Timer.ObserveDuration
  • Loading branch information
beorn7 committed Dec 4, 2018
2 parents 32b1bb4 + 48d3ae7 commit 2df5ba3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions prometheus/timer.go
Expand Up @@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer {

// ObserveDuration records the duration passed since the Timer was created with
// NewTimer. It calls the Observe method of the Observer provided during
// construction with the duration in seconds as an argument. ObserveDuration is
// usually called with a defer statement.
// construction with the duration in seconds as an argument. The observed
// duration is also returned. ObserveDuration is usually called with a defer
// statement.
//
// Note that this method is only guaranteed to never observe negative durations
// if used with Go1.9+.
func (t *Timer) ObserveDuration() {
func (t *Timer) ObserveDuration() time.Duration {
d := time.Since(t.begin)
if t.observer != nil {
t.observer.Observe(time.Since(t.begin).Seconds())
t.observer.Observe(d.Seconds())
}
return d
}

0 comments on commit 2df5ba3

Please sign in to comment.