MCPcopy
hub / github.com/prometheus/client_golang / ObserveDuration

Method ObserveDuration

prometheus/timer.go:59–65  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

57// Note that this method is only guaranteed to never observe negative durations
58// if used with Go1.9+.
59func (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

Callers 7

TestTimerObserveFunction · 0.95
TestTimerEmptyFunction · 0.95
TestTimerByOutcomeFunction · 0.95
runFunction · 0.95
ExampleTimerFunction · 0.95
handlerFunction · 0.95

Calls 1

ObserveMethod · 0.65

Tested by 7

TestTimerObserveFunction · 0.76
TestTimerEmptyFunction · 0.76
TestTimerByOutcomeFunction · 0.76
runFunction · 0.76
ExampleTimerFunction · 0.76
handlerFunction · 0.76