Initial commit
mbed-dev-master/platform/mbed_stats.c@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | #include "mbed_assert.h" |
lypinator | 0:bb348c97df44 | 2 | #include "mbed_stats.h" |
lypinator | 0:bb348c97df44 | 3 | #include "mbed_power_mgmt.h" |
lypinator | 0:bb348c97df44 | 4 | #include "mbed_version.h" |
lypinator | 0:bb348c97df44 | 5 | #include <string.h> |
lypinator | 0:bb348c97df44 | 6 | #include <stdlib.h> |
lypinator | 0:bb348c97df44 | 7 | |
lypinator | 0:bb348c97df44 | 8 | #include "device.h" |
lypinator | 0:bb348c97df44 | 9 | #ifdef MBED_CONF_RTOS_PRESENT |
lypinator | 0:bb348c97df44 | 10 | #include "cmsis_os2.h" |
lypinator | 0:bb348c97df44 | 11 | #include "rtos_idle.h" |
lypinator | 0:bb348c97df44 | 12 | #elif defined(MBED_STACK_STATS_ENABLED) || defined(MBED_THREAD_STATS_ENABLED) || defined(MBED_CPU_STATS_ENABLED) |
lypinator | 0:bb348c97df44 | 13 | #warning Statistics are currently not supported without the rtos. |
lypinator | 0:bb348c97df44 | 14 | #endif |
lypinator | 0:bb348c97df44 | 15 | |
lypinator | 0:bb348c97df44 | 16 | #if defined(MBED_CPU_STATS_ENABLED) && (!defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP)) |
lypinator | 0:bb348c97df44 | 17 | #warning CPU statistics are not supported without low power timer support. |
lypinator | 0:bb348c97df44 | 18 | #endif |
lypinator | 0:bb348c97df44 | 19 | |
lypinator | 0:bb348c97df44 | 20 | void mbed_stats_cpu_get(mbed_stats_cpu_t *stats) |
lypinator | 0:bb348c97df44 | 21 | { |
lypinator | 0:bb348c97df44 | 22 | MBED_ASSERT(stats != NULL); |
lypinator | 0:bb348c97df44 | 23 | memset(stats, 0, sizeof(mbed_stats_cpu_t)); |
lypinator | 0:bb348c97df44 | 24 | #if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LPTICKER) && defined(DEVICE_SLEEP) |
lypinator | 0:bb348c97df44 | 25 | stats->uptime = mbed_uptime(); |
lypinator | 0:bb348c97df44 | 26 | stats->idle_time = mbed_time_idle(); |
lypinator | 0:bb348c97df44 | 27 | stats->sleep_time = mbed_time_sleep(); |
lypinator | 0:bb348c97df44 | 28 | stats->deep_sleep_time = mbed_time_deepsleep(); |
lypinator | 0:bb348c97df44 | 29 | #endif |
lypinator | 0:bb348c97df44 | 30 | } |
lypinator | 0:bb348c97df44 | 31 | |
lypinator | 0:bb348c97df44 | 32 | // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp |
lypinator | 0:bb348c97df44 | 33 | void mbed_stats_stack_get(mbed_stats_stack_t *stats) |
lypinator | 0:bb348c97df44 | 34 | { |
lypinator | 0:bb348c97df44 | 35 | MBED_ASSERT(stats != NULL); |
lypinator | 0:bb348c97df44 | 36 | memset(stats, 0, sizeof(mbed_stats_stack_t)); |
lypinator | 0:bb348c97df44 | 37 | |
lypinator | 0:bb348c97df44 | 38 | #if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) |
lypinator | 0:bb348c97df44 | 39 | uint32_t thread_n = osThreadGetCount(); |
lypinator | 0:bb348c97df44 | 40 | unsigned i; |
lypinator | 0:bb348c97df44 | 41 | osThreadId_t *threads; |
lypinator | 0:bb348c97df44 | 42 | |
lypinator | 0:bb348c97df44 | 43 | threads = malloc(sizeof(osThreadId_t) * thread_n); |
lypinator | 0:bb348c97df44 | 44 | MBED_ASSERT(threads != NULL); |
lypinator | 0:bb348c97df44 | 45 | |
lypinator | 0:bb348c97df44 | 46 | osKernelLock(); |
lypinator | 0:bb348c97df44 | 47 | thread_n = osThreadEnumerate(threads, thread_n); |
lypinator | 0:bb348c97df44 | 48 | |
lypinator | 0:bb348c97df44 | 49 | for (i = 0; i < thread_n; i++) { |
lypinator | 0:bb348c97df44 | 50 | uint32_t stack_size = osThreadGetStackSize(threads[i]); |
lypinator | 0:bb348c97df44 | 51 | stats->max_size += stack_size - osThreadGetStackSpace(threads[i]); |
lypinator | 0:bb348c97df44 | 52 | stats->reserved_size += stack_size; |
lypinator | 0:bb348c97df44 | 53 | stats->stack_cnt++; |
lypinator | 0:bb348c97df44 | 54 | } |
lypinator | 0:bb348c97df44 | 55 | osKernelUnlock(); |
lypinator | 0:bb348c97df44 | 56 | |
lypinator | 0:bb348c97df44 | 57 | free(threads); |
lypinator | 0:bb348c97df44 | 58 | #endif |
lypinator | 0:bb348c97df44 | 59 | } |
lypinator | 0:bb348c97df44 | 60 | |
lypinator | 0:bb348c97df44 | 61 | size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) |
lypinator | 0:bb348c97df44 | 62 | { |
lypinator | 0:bb348c97df44 | 63 | MBED_ASSERT(stats != NULL); |
lypinator | 0:bb348c97df44 | 64 | memset(stats, 0, count * sizeof(mbed_stats_stack_t)); |
lypinator | 0:bb348c97df44 | 65 | |
lypinator | 0:bb348c97df44 | 66 | size_t i = 0; |
lypinator | 0:bb348c97df44 | 67 | |
lypinator | 0:bb348c97df44 | 68 | #if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) |
lypinator | 0:bb348c97df44 | 69 | osThreadId_t *threads; |
lypinator | 0:bb348c97df44 | 70 | |
lypinator | 0:bb348c97df44 | 71 | threads = malloc(sizeof(osThreadId_t) * count); |
lypinator | 0:bb348c97df44 | 72 | MBED_ASSERT(threads != NULL); |
lypinator | 0:bb348c97df44 | 73 | |
lypinator | 0:bb348c97df44 | 74 | osKernelLock(); |
lypinator | 0:bb348c97df44 | 75 | count = osThreadEnumerate(threads, count); |
lypinator | 0:bb348c97df44 | 76 | |
lypinator | 0:bb348c97df44 | 77 | for (i = 0; i < count; i++) { |
lypinator | 0:bb348c97df44 | 78 | uint32_t stack_size = osThreadGetStackSize(threads[i]); |
lypinator | 0:bb348c97df44 | 79 | stats[i].max_size = stack_size - osThreadGetStackSpace(threads[i]); |
lypinator | 0:bb348c97df44 | 80 | stats[i].reserved_size = stack_size; |
lypinator | 0:bb348c97df44 | 81 | stats[i].thread_id = (uint32_t)threads[i]; |
lypinator | 0:bb348c97df44 | 82 | stats[i].stack_cnt = 1; |
lypinator | 0:bb348c97df44 | 83 | } |
lypinator | 0:bb348c97df44 | 84 | osKernelUnlock(); |
lypinator | 0:bb348c97df44 | 85 | |
lypinator | 0:bb348c97df44 | 86 | free(threads); |
lypinator | 0:bb348c97df44 | 87 | #endif |
lypinator | 0:bb348c97df44 | 88 | |
lypinator | 0:bb348c97df44 | 89 | return i; |
lypinator | 0:bb348c97df44 | 90 | } |
lypinator | 0:bb348c97df44 | 91 | |
lypinator | 0:bb348c97df44 | 92 | size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count) |
lypinator | 0:bb348c97df44 | 93 | { |
lypinator | 0:bb348c97df44 | 94 | MBED_ASSERT(stats != NULL); |
lypinator | 0:bb348c97df44 | 95 | memset(stats, 0, count * sizeof(mbed_stats_thread_t)); |
lypinator | 0:bb348c97df44 | 96 | size_t i = 0; |
lypinator | 0:bb348c97df44 | 97 | |
lypinator | 0:bb348c97df44 | 98 | #if defined(MBED_THREAD_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT) |
lypinator | 0:bb348c97df44 | 99 | osThreadId_t *threads; |
lypinator | 0:bb348c97df44 | 100 | |
lypinator | 0:bb348c97df44 | 101 | threads = malloc(sizeof(osThreadId_t) * count); |
lypinator | 0:bb348c97df44 | 102 | MBED_ASSERT(threads != NULL); |
lypinator | 0:bb348c97df44 | 103 | |
lypinator | 0:bb348c97df44 | 104 | osKernelLock(); |
lypinator | 0:bb348c97df44 | 105 | count = osThreadEnumerate(threads, count); |
lypinator | 0:bb348c97df44 | 106 | |
lypinator | 0:bb348c97df44 | 107 | for (i = 0; i < count; i++) { |
lypinator | 0:bb348c97df44 | 108 | stats[i].id = (uint32_t)threads[i]; |
lypinator | 0:bb348c97df44 | 109 | stats[i].state = (uint32_t)osThreadGetState(threads[i]); |
lypinator | 0:bb348c97df44 | 110 | stats[i].priority = (uint32_t)osThreadGetPriority(threads[i]); |
lypinator | 0:bb348c97df44 | 111 | stats[i].stack_size = osThreadGetStackSize(threads[i]); |
lypinator | 0:bb348c97df44 | 112 | stats[i].stack_space = osThreadGetStackSpace(threads[i]); |
lypinator | 0:bb348c97df44 | 113 | stats[i].name = osThreadGetName(threads[i]); |
lypinator | 0:bb348c97df44 | 114 | } |
lypinator | 0:bb348c97df44 | 115 | osKernelUnlock(); |
lypinator | 0:bb348c97df44 | 116 | free(threads); |
lypinator | 0:bb348c97df44 | 117 | #endif |
lypinator | 0:bb348c97df44 | 118 | return i; |
lypinator | 0:bb348c97df44 | 119 | } |
lypinator | 0:bb348c97df44 | 120 | |
lypinator | 0:bb348c97df44 | 121 | void mbed_stats_sys_get(mbed_stats_sys_t *stats) |
lypinator | 0:bb348c97df44 | 122 | { |
lypinator | 0:bb348c97df44 | 123 | MBED_ASSERT(stats != NULL); |
lypinator | 0:bb348c97df44 | 124 | memset(stats, 0, sizeof(mbed_stats_sys_t)); |
lypinator | 0:bb348c97df44 | 125 | |
lypinator | 0:bb348c97df44 | 126 | #if defined(MBED_SYS_STATS_ENABLED) |
lypinator | 0:bb348c97df44 | 127 | stats->os_version = MBED_VERSION; |
lypinator | 0:bb348c97df44 | 128 | #if defined(__CORTEX_M) |
lypinator | 0:bb348c97df44 | 129 | stats->cpu_id = SCB->CPUID; |
lypinator | 0:bb348c97df44 | 130 | #endif |
lypinator | 0:bb348c97df44 | 131 | #if defined(__IAR_SYSTEMS_ICC__) |
lypinator | 0:bb348c97df44 | 132 | stats->compiler_id = IAR; |
lypinator | 0:bb348c97df44 | 133 | stats->compiler_version = __VER__; |
lypinator | 0:bb348c97df44 | 134 | #elif defined(__CC_ARM) |
lypinator | 0:bb348c97df44 | 135 | stats->compiler_id = ARM; |
lypinator | 0:bb348c97df44 | 136 | stats->compiler_version = __ARMCC_VERSION; |
lypinator | 0:bb348c97df44 | 137 | #elif defined(__GNUC__) |
lypinator | 0:bb348c97df44 | 138 | stats->compiler_id = GCC_ARM; |
lypinator | 0:bb348c97df44 | 139 | stats->compiler_version = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100); |
lypinator | 0:bb348c97df44 | 140 | #endif |
lypinator | 0:bb348c97df44 | 141 | |
lypinator | 0:bb348c97df44 | 142 | #endif |
lypinator | 0:bb348c97df44 | 143 | return; |
lypinator | 0:bb348c97df44 | 144 | } |