diff --git a/flight/pios/common/pios_instrumentation.c b/flight/pios/common/pios_instrumentation.c index dcd9d0f6f..381e42bfb 100644 --- a/flight/pios/common/pios_instrumentation.c +++ b/flight/pios/common/pios_instrumentation.c @@ -52,8 +52,8 @@ pios_counter_t PIOS_Instrumentation_CreateCounter(uint32_t id) if (!counter_handle) { pios_perf_counter_t *newcounter = &pios_instrumentation_perf_counters[++pios_instrumentation_last_used_counter]; newcounter->id = id; - newcounter->max = INT32_MIN; - newcounter->min = INT32_MAX; + newcounter->max = INT32_MIN + 1; + newcounter->min = INT32_MAX - 1; counter_handle = (pios_counter_t)newcounter; } return counter_handle; diff --git a/flight/pios/inc/pios_instrumentation.h b/flight/pios/inc/pios_instrumentation.h index 8c1667d71..6eeaf683c 100644 --- a/flight/pios/inc/pios_instrumentation.h +++ b/flight/pios/inc/pios_instrumentation.h @@ -53,9 +53,11 @@ inline void PIOS_Instrumentation_updateCounter(pios_counter_t counter_handle, in vPortEnterCritical(); pios_perf_counter_t *counter = (pios_perf_counter_t *)counter_handle; counter->value = newValue; + counter->max--; if (counter->value > counter->max) { counter->max = counter->value; } + counter->min++; if (counter->value < counter->min) { counter->min = counter->value; } @@ -88,9 +90,11 @@ inline void PIOS_Instrumentation_TimeEnd(pios_counter_t counter_handle) pios_perf_counter_t *counter = (pios_perf_counter_t *)counter_handle; counter->value = PIOS_DELAY_DiffuS(counter->lastUpdateTS); + counter->max--; if (counter->value > counter->max) { counter->max = counter->value; } + counter->min++; if (counter->value < counter->min) { counter->min = counter->value; } @@ -110,9 +114,11 @@ inline void PIOS_Instrumentation_TrackPeriod(pios_counter_t counter_handle) vPortEnterCritical(); uint32_t period = PIOS_DELAY_DiffuS(counter->lastUpdateTS); counter->value = (counter->value * 15 + period) / 16; + counter->max--; if ((int32_t)period > counter->max) { counter->max = period; } + counter->min++; if ((int32_t)period < counter->min) { counter->min = period; }