diff --git a/libraries/AP_HAL_ChibiOS/Util.cpp b/libraries/AP_HAL_ChibiOS/Util.cpp index 0129c7f13f..5a87b891f7 100644 --- a/libraries/AP_HAL_ChibiOS/Util.cpp +++ b/libraries/AP_HAL_ChibiOS/Util.cpp @@ -325,9 +325,18 @@ size_t Util::thread_info(char *buf, size_t bufsize) total_stack = uint32_t(tp) - uint32_t(tp->wabase); } if (bufsize > 0) { +#if HAL_ENABLE_THREAD_STATISTICS + n = snprintf(buf, bufsize, "%-13.13s PRI=%3u sp=%p STACK=%4u/%4u MIN=%4u AVG=%4u MAX=%4u\n", + tp->name, unsigned(tp->prio), tp->wabase, + stack_free(tp->wabase), total_stack, RTC2US(STM32_HSECLK, tp->stats.best), + RTC2US(STM32_HSECLK, uint32_t(tp->stats.cumulative / uint64_t(tp->stats.n))), + RTC2US(STM32_HSECLK, tp->stats.worst)); + chTMObjectInit(&tp->stats); // reset counters to zero +#else n = snprintf(buf, bufsize, "%-13.13s PRI=%3u sp=%p STACK=%u/%u\n", tp->name, unsigned(tp->prio), tp->wabase, stack_free(tp->wabase), total_stack); +#endif if (n > bufsize) { n = bufsize; } diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h index c7497d1239..1167f9780e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h @@ -55,6 +55,12 @@ #define CH_DBG_ENABLE_STACK_CHECK TRUE #endif +#if HAL_ENABLE_THREAD_STATISTICS +#define CH_DBG_STATISTICS TRUE +#else +#define CH_DBG_STATISTICS FALSE +#endif + /** * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. @@ -509,7 +515,7 @@ * @note The default is @p FALSE. */ #if !defined(CH_DBG_STATISTICS) -#define CH_DBG_STATISTICS TRUE +#define CH_DBG_STATISTICS FALSE #endif /** diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 936dae4a39..ef57aa8866 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -751,6 +751,12 @@ def write_mcu_config(f): f.write('\n// APJ board ID (for bootloaders)\n') f.write('#define APJ_BOARD_ID %s\n' % get_config('APJ_BOARD_ID')) + f.write(''' +#ifndef HAL_ENABLE_THREAD_STATISTICS +#define HAL_ENABLE_THREAD_STATISTICS FALSE +#endif + ''') + lib = get_mcu_lib(mcu_type) build_info = lib.build @@ -797,7 +803,6 @@ def write_mcu_config(f): #define HAL_NO_UARTDRIVER #define HAL_NO_PRINTF #define HAL_NO_CCM -#define CH_DBG_STATISTICS FALSE #define CH_CFG_USE_TM FALSE #define CH_CFG_USE_REGISTRY FALSE #define CH_CFG_USE_WAITEXIT FALSE