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

Timer.ObserveDuration should returned the observed duration #509

Closed
eklitzke opened this issue Nov 25, 2018 · 1 comment
Closed

Timer.ObserveDuration should returned the observed duration #509

eklitzke opened this issue Nov 25, 2018 · 1 comment

Comments

@eklitzke
Copy link

The following usage example is given in the docs:

func TimeMe() {
    timer := NewTimer(myHistogram)
    defer timer.ObserveDuration()
    // Do actual work.
}

I find that I typically want to also emit durations in log statements. Therefore it would be useful if ObserveDuration() returned the observed duration (probably as a time.Duration, but I could see a case being made for the value as a float64), which would allow code like the following:

func TimeMe() {
    timer := NewTimer(myHistogram)
    defer func() { log.Printf("finished in %f seconds", timer.ObserveDuration().Seconds()) }()
    // Do actual work.
}
@beorn7
Copy link
Member

beorn7 commented Nov 26, 2018

Sounds like a convenient and reasonable thing to do. And easy to implement. :o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants