mcu: Prevent "math domain errors" in stats calculation

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-08-30 13:57:07 -04:00
parent 9335cc4804
commit 1b454c0943
1 changed files with 2 additions and 1 deletions

View File

@ -505,7 +505,8 @@ class MCU:
c = 1.0 / (count * self._mcu_freq) c = 1.0 / (count * self._mcu_freq)
self._mcu_tick_avg = tick_sum * c self._mcu_tick_avg = tick_sum * c
tick_sumsq = params['sumsq'] * self._stats_sumsq_base tick_sumsq = params['sumsq'] * self._stats_sumsq_base
self._mcu_tick_stddev = c * math.sqrt(count*tick_sumsq - tick_sum**2) diff = count*tick_sumsq - tick_sum**2
self._mcu_tick_stddev = c * math.sqrt(max(0., diff))
self._mcu_tick_awake = tick_sum / self._mcu_freq self._mcu_tick_awake = tick_sum / self._mcu_freq
def _handle_shutdown(self, params): def _handle_shutdown(self, params):
if self._is_shutdown: if self._is_shutdown: