|
| 1 | +#include "mbed_stats.h" |
| 2 | +#include <string.h> |
| 3 | + |
| 4 | +#if MBED_CONF_RTOS_PRESENT |
| 5 | +#include "cmsis_os.h" |
| 6 | +#endif |
| 7 | + |
| 8 | +// note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp |
| 9 | + |
| 10 | +void mbed_stats_stack_get(mbed_stats_stack_t *stats) |
| 11 | +{ |
| 12 | + memset(stats, 0, sizeof(mbed_stats_stack_t)); |
| 13 | + |
| 14 | +#if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
| 15 | + osThreadEnumId enumid = _osThreadsEnumStart(); |
| 16 | + osThreadId threadid; |
| 17 | + |
| 18 | + while ((threadid = _osThreadEnumNext(enumid))) { |
| 19 | + osEvent e; |
| 20 | + |
| 21 | + e = _osThreadGetInfo(threadid, osThreadInfoStackMax); |
| 22 | + if (e.status == osOK) { |
| 23 | + stats->max_size += (uint32_t)e.value.p; |
| 24 | + } |
| 25 | + |
| 26 | + e = _osThreadGetInfo(threadid, osThreadInfoStackSize); |
| 27 | + if (e.status == osOK) { |
| 28 | + stats->reserved_size += (uint32_t)e.value.p; |
| 29 | + } |
| 30 | + |
| 31 | + stats->stack_cnt += 1; |
| 32 | + } |
| 33 | +#endif |
| 34 | +} |
| 35 | + |
| 36 | +size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) |
| 37 | +{ |
| 38 | + memset(stats, 0, count*sizeof(mbed_stats_stack_t)); |
| 39 | + size_t i = 0; |
| 40 | + |
| 41 | +#if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
| 42 | + osThreadEnumId enumid = _osThreadsEnumStart(); |
| 43 | + osThreadId threadid; |
| 44 | + |
| 45 | + while ((threadid = _osThreadEnumNext(enumid)) && i < count) { |
| 46 | + osEvent e; |
| 47 | + |
| 48 | + e = _osThreadGetInfo(threadid, osThreadInfoStackMax); |
| 49 | + if (e.status == osOK) { |
| 50 | + stats[i].max_size = (uint32_t)e.value.p; |
| 51 | + } |
| 52 | + |
| 53 | + e = _osThreadGetInfo(threadid, osThreadInfoStackSize); |
| 54 | + if (e.status == osOK) { |
| 55 | + stats[i].reserved_size = (uint32_t)e.value.p; |
| 56 | + } |
| 57 | + |
| 58 | + stats[i].thread_id = (uint32_t)threadid; |
| 59 | + stats[i].stack_cnt = 1; |
| 60 | + i += 1; |
| 61 | + } |
| 62 | +#endif |
| 63 | + |
| 64 | + return i; |
| 65 | +} |
| 66 | + |
| 67 | +#if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT |
| 68 | +#warning Stack statistics are currently not supported without the rtos. |
| 69 | +#endif |
0 commit comments