-
Notifications
You must be signed in to change notification settings - Fork 305
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
Context managed statsd.timed
#25
Comments
clokep
added a commit
to percipient/datadogpy
that referenced
this issue
Jun 30, 2015
This enables a context manager in statsd so you can easily time a set of code without saving the start time, etc. manually: ```python with statsd.timed_context('user.query.time', sample_rate=0.5): # Do what you need to ... pass start = time.time() try: get_user(user_id) finally: statsd.timing('user.query.time', time.time() - start) ``` Two tests are also added for this code. Fixes DataDog#25
clokep
added a commit
to percipient/datadogpy
that referenced
this issue
Jun 30, 2015
This enables a context manager in statsd so you can easily time a set of code without saving the start time, etc. manually: ```python with statsd.timed_context('user.query.time', sample_rate=0.5): # Do what you need to ... pass # Is equivalent to ... start = time.time() try: get_user(user_id) finally: statsd.timing('user.query.time', time.time() - start) ``` Two tests are also added for this code. Fixes DataDog#25
:yay: thanks!! |
You're welcome! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now you can use
statsd.timed
, that would be cool when you want to measure the runtime of some random code to be able to do:The text was updated successfully, but these errors were encountered: