sumerc / yappi

Yet Another Python Profiler, but this time multithreading, asyncio and gevent aware.
MIT License
1.45k stars 73 forks source link

Feature request: Incremental stats clearing #42

Open sm-Fifteen opened 4 years ago

sm-Fifteen commented 4 years ago

Yappi is currently poorly suited to long-running applications, since the only way to free a set of profiling stats once they're no longer needed is to clear the all of the profiler's memory, effectively resetting it. In a multi-threaded or async system, this is almost certain to interfere with the other threads, and even if losing profiler data isn't critical, it could lead to some frustration when attempting to isolate some of the longer code paths applications that are meant to run for extended periods of time (such as any kind of server).

There should be an alternative to clear_stats() that allows the user to pass the same kind of filter passed to get_func_stats() to cleanup select parts of the profiler stats. Alternatively, this could be implementad as a method to YFuncStat, which would free all memory related to the function calls contained within.

sumerc commented 4 years ago

Thanks for the explanation.

We have also discussed this before on https://github.com/tiangolo/fastapi/issues/701 and clear_stats() filtering might be worth implementing for using in long running servers/middleware as you proposed.