PerfTimer seems like yet another code execution timer-- but wait! The package also includes TrioPerfTimer, which is aware of the Trio scheduler and able to deduct periods when a task is blocked. So you can measure the CPU time of any section of code including async calls.
If you’re not looking for a fancy context-manager timer thing, the package also has a trio_perf_counter() primitive, which follows the semantics of the stdlib time perf counters but in the context of a Trio task. Use it to build your own instrumentation stuff!
percentile tracking is available PerfTimer(..., observer=HistogramObserver), which can report arbitrary percentile latencies
overhead of the various observer and timer types has been benchmarked. On an old laptop, the default PerfTimer takes < 2 µs per observation, and TrioPerfTimer takes < 5 µs.
example output
default (avg ± stddev, max):
timer "process thumbnail": avg 73.1 µs ± 18.0 µs, max 320.5 µs in 292 runs