How Yappi handles coroutine profiling
masterUnlike deterministic profilers (like cProfile) or statistical profilers (like pyinstrument), Yappi (since v1.2) correctly handles coroutine context switches.
In standard profilers, when a coroutine yields (e.g., during an await), the profiler treats it as a function exit. This leads to two major inaccuracies:
- Incorrect Call Counts: Every
yieldincrements the call count as if the function exited. - Incorrect Wall Time: The time spent while the coroutine is in a
yieldstate is not accumulated into thecumtime(cumulative time).
Yappi differentiates between a yield and a real function exit. When using clock_type='wall', Yappi accumulates the time spent during await states and maintains an accurate call count for the coroutine.