-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
This issue discusses a possible profiling solution of uasyncio tasks.
see #7399 for the related disussion (specifically #7399 (comment)).
Our main motivation is to measure when and for how long a task is active on a embedded device. This is important to understand complex interactions when several hw interfaces are used. It also helps to understand the overall system load and which tasks are wasting processor power.
Ideally the uasyncio loop would provide a callback for this, which has no performace impact when not used..
We implemented the functionality by tracking the send calls in a wrapper of the coroutine in order to avoid patching the complex loop function. We understand that this adds an overhead on each task when enter/exit:
class TrackedCoro:
def __init__(self, coro):
self._coro = coro
def send(self, value):
signal(ENTER....) # send profiling packet on enter
self._coro.send(value)
signal(EXIT...) # send profiling packet on exit
The wrapper sends a small profiler frame over UART/USB, consisting of a few bytes with a timestamp and some basic information about the coro. An external program can visualize the individual tasks, similar as on a logic analyser.
Here is an example on how it looks:
Overall this has been really useful to obtain insights in the asyncio's taks.
So that's the intention of the request to access the coro. Maybe other approaches exists to implement a similar, more efficent way? Other than that we are building our image with the patch linked above but would of course like to have as little differences to upstream micropython..