timebudget
timebudget copied to clipboard
Moving averages for reports using cycle-time / percent_of
Currently the averages in the report are counted from the beginning of the program, without exception. This can be a problem if you're watching a process whose behavior is changing. Instead, the report could calculate the average over recent data only, and thus reflect changes in behavior much more quickly by only summarizing recent behavior.
Two common ways to do this would be an exponential moving average (EMA) algorithm, or a sliding window (SW). EMA is computationally simple, and thus would be my choice, but it's harder to explain and understand. SW literally just averages over the last N events instead of back to the beginning of the program. SW is much easier to understand, but requires a lot more computational overhead. SW also has some undesirable "ringing" properties in how it responds to periodically changing behavior whereas EMA does a better job of averaging those out.
The simplest (for the user) thing I can think of would be to switch to EMA after some number of cycles. Default to 100 say, but configurable like timebugdet.ema_after = 10
if you want to see behavior changes reflected more quickly.
Another option would maybe be to reset the timer whenever timebudget.report(reset=True)
is called? And simply report the sliding window in-between calls?
Edit: sorry, I only saw #5 opened only after I commented.
I like the suggestion of including reset
as an option to report
. This is very simple to understand.
I took the suggestion from @floringogianu in 38752f378d6d6973215068af6b422d2422ebd4b1 and added a reset
option to report
.