Add convenience `measure` function to Python TimingDistribution and Timespan metric types
Categories
(Data Platform and Tools :: Glean: SDK, enhancement, P1)
Tracking
(Not tracked)
People
(Reporter: travis_, Assigned: mdroettboom)
Details
(Whiteboard: [telemetry:glean-rs:m13][glean-py])
Attachments
(1 file)
This is to add the same measure convenience method to the Python bindings that's added by this PR
| Reporter | ||
Updated•6 years ago
|
| Assignee | ||
Comment 1•6 years ago
|
||
I feel like the most Pythonic way to expose this would be to implement it as a context manager so it could be used in a with block, e.g.:
with metrics.timing_distribution.measure():
do_the_thing_you_want_to_measure()
This has the advantage that it makes it just as easy to measure parts of functions.
It could also be a decorator, but that would require measuring an entire function:
@metrics.timing_distribution.measure
def a_function_i_want_to_measure():
# ... do the work
Passing a function to measure would also work, but it vaguely feels less Pythonic to me (and would also require measuring an entire function):
metrics.timing_distribution.measure(a_function_i_want_to_measure)
| Reporter | ||
Comment 2•6 years ago
|
||
Passing a function to measure would also work, but it vaguely feels less Pythonic to me (and would also require measuring an entire function):
metrics.timing_distribution.measure(a_function_i_want_to_measure)
I played around with this method (as I didn't know about the other ways to do this due to lack of knowledge about Python), and I couldn't come up with a way to return the value of the function or to pass values into the function that worked for me and was congruent with the Kotlin and Swift implementations. Is that possible? If so I'd be interested in seeing how it's done :)
Comment 3•6 years ago
|
||
(In reply to Michael Droettboom [:mdroettboom] from comment #1)
I feel like the most Pythonic way to expose this would be to implement it as a context manager so it could be used in a
withblock, e.g.:with metrics.timing_distribution.measure(): do_the_thing_you_want_to_measure()This has the advantage that it makes it just as easy to measure parts of functions.
This feels the best option to me as well. We want to make ti easy to measure parts of functions as part of our API, and this approach makes it comparable to what's offered in the Kotlin bindings as well.
Updated•6 years ago
|
Updated•6 years ago
|
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Updated•6 years ago
|
Updated•6 years ago
|
Comment 4•6 years ago
|
||
| Assignee | ||
Updated•6 years ago
|
Description
•