Life is random and unfair!
Fork of mbed-dev by
Embed:
(wiki syntax)
Show/hide line numbers
mbed_stats.c
00001 #include "mbed_stats.h" 00002 #include <string.h> 00003 00004 #if MBED_CONF_RTOS_PRESENT 00005 #include "cmsis_os.h" 00006 #endif 00007 00008 // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp 00009 00010 void mbed_stats_stack_get(mbed_stats_stack_t *stats) 00011 { 00012 memset(stats, 0, sizeof(mbed_stats_stack_t)); 00013 00014 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT 00015 osThreadEnumId enumid = _osThreadsEnumStart(); 00016 osThreadId threadid; 00017 00018 while ((threadid = _osThreadEnumNext(enumid))) { 00019 osEvent e; 00020 00021 e = _osThreadGetInfo(threadid, osThreadInfoStackMax); 00022 if (e.status == osOK) { 00023 stats->max_size += (uint32_t)e.value.p; 00024 } 00025 00026 e = _osThreadGetInfo(threadid, osThreadInfoStackSize); 00027 if (e.status == osOK) { 00028 stats->reserved_size += (uint32_t)e.value.p; 00029 } 00030 00031 stats->stack_cnt += 1; 00032 } 00033 #endif 00034 } 00035 00036 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) 00037 { 00038 memset(stats, 0, count*sizeof(mbed_stats_stack_t)); 00039 size_t i = 0; 00040 00041 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT 00042 osThreadEnumId enumid = _osThreadsEnumStart(); 00043 osThreadId threadid; 00044 00045 while ((threadid = _osThreadEnumNext(enumid)) && i < count) { 00046 osEvent e; 00047 00048 e = _osThreadGetInfo(threadid, osThreadInfoStackMax); 00049 if (e.status == osOK) { 00050 stats[i].max_size = (uint32_t)e.value.p; 00051 } 00052 00053 e = _osThreadGetInfo(threadid, osThreadInfoStackSize); 00054 if (e.status == osOK) { 00055 stats[i].reserved_size = (uint32_t)e.value.p; 00056 } 00057 00058 stats[i].thread_id = (uint32_t)threadid; 00059 stats[i].stack_cnt = 1; 00060 i += 1; 00061 } 00062 #endif 00063 00064 return i; 00065 } 00066 00067 #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT 00068 #warning Stack statistics are currently not supported without the rtos. 00069 #endif
Generated on Tue Jul 12 2022 19:28:24 by 1.7.2