AP_HAL_ChibiOS: when HAL_ENABLE_THREAD_STATISTICS is defined add ChibiOS thread stats to threads.txt

define HAL_ENABLE_THREAD_STATISTICS in hwdef.h
This commit is contained in:
Andy Piper 2020-12-19 22:43:49 +00:00 committed by Andrew Tridgell
parent b6a008c73d
commit 83c8807b39
3 changed files with 22 additions and 2 deletions

View File

@ -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;
}

View File

@ -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
/**

View File

@ -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