Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_stats.c
00001 #include "mbed_assert.h" 00002 #include "mbed_stats.h" 00003 #include "mbed_power_mgmt.h" 00004 #include "mbed_version.h" 00005 #include <string.h> 00006 #include <stdlib.h> 00007 00008 #include "device.h" 00009 #ifdef MBED_CONF_RTOS_PRESENT 00010 #include "cmsis_os2.h" 00011 #include "rtos_idle.h" 00012 #elif defined(MBED_STACK_STATS_ENABLED) || defined(MBED_THREAD_STATS_ENABLED) || defined(MBED_CPU_STATS_ENABLED) 00013 #warning Statistics are currently not supported without the rtos. 00014 #endif 00015 00016 #if defined(MBED_CPU_STATS_ENABLED) && (!defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP)) 00017 #warning CPU statistics are not supported without low power timer support. 00018 #endif 00019 00020 void mbed_stats_cpu_get(mbed_stats_cpu_t *stats) 00021 { 00022 MBED_ASSERT(stats != NULL); 00023 memset(stats, 0, sizeof(mbed_stats_cpu_t)); 00024 #if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LPTICKER) && defined(DEVICE_SLEEP) 00025 stats->uptime = mbed_uptime(); 00026 stats->idle_time = mbed_time_idle(); 00027 stats->sleep_time = mbed_time_sleep(); 00028 stats->deep_sleep_time = mbed_time_deepsleep(); 00029 #endif 00030 } 00031 00032 // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp 00033 void mbed_stats_stack_get(mbed_stats_stack_t *stats) 00034 { 00035 MBED_ASSERT(stats != NULL); 00036 memset(stats, 0, sizeof(mbed_stats_stack_t)); 00037 00038 #if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) 00039 uint32_t thread_n = osThreadGetCount(); 00040 unsigned i; 00041 osThreadId_t *threads; 00042 00043 threads = malloc(sizeof(osThreadId_t) * thread_n); 00044 MBED_ASSERT(threads != NULL); 00045 00046 osKernelLock(); 00047 thread_n = osThreadEnumerate(threads, thread_n); 00048 00049 for (i = 0; i < thread_n; i++) { 00050 uint32_t stack_size = osThreadGetStackSize(threads[i]); 00051 stats->max_size += stack_size - osThreadGetStackSpace(threads[i]); 00052 stats->reserved_size += stack_size; 00053 stats->stack_cnt++; 00054 } 00055 osKernelUnlock(); 00056 00057 free(threads); 00058 #endif 00059 } 00060 00061 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) 00062 { 00063 MBED_ASSERT(stats != NULL); 00064 memset(stats, 0, count * sizeof(mbed_stats_stack_t)); 00065 00066 size_t i = 0; 00067 00068 #if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) 00069 osThreadId_t *threads; 00070 00071 threads = malloc(sizeof(osThreadId_t) * count); 00072 MBED_ASSERT(threads != NULL); 00073 00074 osKernelLock(); 00075 count = osThreadEnumerate(threads, count); 00076 00077 for (i = 0; i < count; i++) { 00078 uint32_t stack_size = osThreadGetStackSize(threads[i]); 00079 stats[i].max_size = stack_size - osThreadGetStackSpace(threads[i]); 00080 stats[i].reserved_size = stack_size; 00081 stats[i].thread_id = (uint32_t)threads[i]; 00082 stats[i].stack_cnt = 1; 00083 } 00084 osKernelUnlock(); 00085 00086 free(threads); 00087 #endif 00088 00089 return i; 00090 } 00091 00092 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count) 00093 { 00094 MBED_ASSERT(stats != NULL); 00095 memset(stats, 0, count * sizeof(mbed_stats_thread_t)); 00096 size_t i = 0; 00097 00098 #if defined(MBED_THREAD_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) 00099 osThreadId_t *threads; 00100 00101 threads = malloc(sizeof(osThreadId_t) * count); 00102 MBED_ASSERT(threads != NULL); 00103 00104 osKernelLock(); 00105 count = osThreadEnumerate(threads, count); 00106 00107 for (i = 0; i < count; i++) { 00108 stats[i].id = (uint32_t)threads[i]; 00109 stats[i].state = (uint32_t)osThreadGetState(threads[i]); 00110 stats[i].priority = (uint32_t)osThreadGetPriority(threads[i]); 00111 stats[i].stack_size = osThreadGetStackSize(threads[i]); 00112 stats[i].stack_space = osThreadGetStackSpace(threads[i]); 00113 stats[i].name = osThreadGetName(threads[i]); 00114 } 00115 osKernelUnlock(); 00116 free(threads); 00117 #endif 00118 return i; 00119 } 00120 00121 void mbed_stats_sys_get(mbed_stats_sys_t *stats) 00122 { 00123 MBED_ASSERT(stats != NULL); 00124 memset(stats, 0, sizeof(mbed_stats_sys_t)); 00125 00126 #if defined(MBED_SYS_STATS_ENABLED) 00127 stats->os_version = MBED_VERSION; 00128 #if defined(__CORTEX_M) 00129 stats->cpu_id = SCB->CPUID; 00130 #endif 00131 #if defined(__IAR_SYSTEMS_ICC__) 00132 stats->compiler_id = IAR; 00133 stats->compiler_version = __VER__; 00134 #elif defined(__CC_ARM) 00135 stats->compiler_id = ARM; 00136 stats->compiler_version = __ARMCC_VERSION; 00137 #elif defined(__GNUC__) 00138 stats->compiler_id = GCC_ARM; 00139 stats->compiler_version = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100); 00140 #endif 00141 00142 #endif 00143 return; 00144 }
Generated on Tue Jul 12 2022 13:53:15 by
1.7.2