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. The observed duration is also returned. ObserveDuration is usually called with a defer statemen
()
| 57 | // Note that this method is only guaranteed to never observe negative durations |
| 58 | // if used with Go1.9+. |
| 59 | func (t *Timer) ObserveDuration() time.Duration { |
| 60 | d := time.Since(t.begin) |
| 61 | if t.observer != nil { |
| 62 | t.observer.Observe(d.Seconds()) |
| 63 | } |
| 64 | return d |
| 65 | } |
| 66 | |
| 67 | // ObserveDurationWithExemplar is like ObserveDuration, but it will also |
| 68 | // observe exemplar with the duration unless exemplar is nil or provided Observer can't |