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-os/platform/mbed_stats.c@0:4beb2ea291ec, 2020-03-16 (annotated)
- Committer:
- boro
- Date:
- Mon Mar 16 13:12:31 2020 +0000
- Revision:
- 0:4beb2ea291ec
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 0:4beb2ea291ec | 1 | #include "mbed_stats.h" |
boro | 0:4beb2ea291ec | 2 | #include <string.h> |
boro | 0:4beb2ea291ec | 3 | #include <stdlib.h> |
boro | 0:4beb2ea291ec | 4 | #include "mbed_assert.h" |
boro | 0:4beb2ea291ec | 5 | |
boro | 0:4beb2ea291ec | 6 | #if MBED_CONF_RTOS_PRESENT |
boro | 0:4beb2ea291ec | 7 | #include "cmsis_os2.h" |
boro | 0:4beb2ea291ec | 8 | #endif |
boro | 0:4beb2ea291ec | 9 | |
boro | 0:4beb2ea291ec | 10 | // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp |
boro | 0:4beb2ea291ec | 11 | |
boro | 0:4beb2ea291ec | 12 | void mbed_stats_stack_get(mbed_stats_stack_t *stats) |
boro | 0:4beb2ea291ec | 13 | { |
boro | 0:4beb2ea291ec | 14 | memset(stats, 0, sizeof(mbed_stats_stack_t)); |
boro | 0:4beb2ea291ec | 15 | |
boro | 0:4beb2ea291ec | 16 | #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
boro | 0:4beb2ea291ec | 17 | uint32_t thread_n = osThreadGetCount(); |
boro | 0:4beb2ea291ec | 18 | unsigned i; |
boro | 0:4beb2ea291ec | 19 | osThreadId_t *threads; |
boro | 0:4beb2ea291ec | 20 | |
boro | 0:4beb2ea291ec | 21 | threads = malloc(sizeof(osThreadId_t) * thread_n); |
boro | 0:4beb2ea291ec | 22 | MBED_ASSERT(threads != NULL); |
boro | 0:4beb2ea291ec | 23 | |
boro | 0:4beb2ea291ec | 24 | osKernelLock(); |
boro | 0:4beb2ea291ec | 25 | thread_n = osThreadEnumerate(threads, thread_n); |
boro | 0:4beb2ea291ec | 26 | |
boro | 0:4beb2ea291ec | 27 | for(i = 0; i < thread_n; i++) { |
boro | 0:4beb2ea291ec | 28 | uint32_t stack_size = osThreadGetStackSize(threads[i]); |
boro | 0:4beb2ea291ec | 29 | stats->max_size += stack_size - osThreadGetStackSpace(threads[i]); |
boro | 0:4beb2ea291ec | 30 | stats->reserved_size += stack_size; |
boro | 0:4beb2ea291ec | 31 | stats->stack_cnt++; |
boro | 0:4beb2ea291ec | 32 | } |
boro | 0:4beb2ea291ec | 33 | osKernelUnlock(); |
boro | 0:4beb2ea291ec | 34 | |
boro | 0:4beb2ea291ec | 35 | free(threads); |
boro | 0:4beb2ea291ec | 36 | #endif |
boro | 0:4beb2ea291ec | 37 | } |
boro | 0:4beb2ea291ec | 38 | |
boro | 0:4beb2ea291ec | 39 | size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) |
boro | 0:4beb2ea291ec | 40 | { |
boro | 0:4beb2ea291ec | 41 | memset(stats, 0, count*sizeof(mbed_stats_stack_t)); |
boro | 0:4beb2ea291ec | 42 | size_t i = 0; |
boro | 0:4beb2ea291ec | 43 | |
boro | 0:4beb2ea291ec | 44 | #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
boro | 0:4beb2ea291ec | 45 | osThreadId_t *threads; |
boro | 0:4beb2ea291ec | 46 | |
boro | 0:4beb2ea291ec | 47 | threads = malloc(sizeof(osThreadId_t) * count); |
boro | 0:4beb2ea291ec | 48 | MBED_ASSERT(threads != NULL); |
boro | 0:4beb2ea291ec | 49 | |
boro | 0:4beb2ea291ec | 50 | osKernelLock(); |
boro | 0:4beb2ea291ec | 51 | count = osThreadEnumerate(threads, count); |
boro | 0:4beb2ea291ec | 52 | |
boro | 0:4beb2ea291ec | 53 | for(i = 0; i < count; i++) { |
boro | 0:4beb2ea291ec | 54 | uint32_t stack_size = osThreadGetStackSize(threads[i]); |
boro | 0:4beb2ea291ec | 55 | stats[i].max_size = stack_size - osThreadGetStackSpace(threads[i]); |
boro | 0:4beb2ea291ec | 56 | stats[i].reserved_size = stack_size; |
boro | 0:4beb2ea291ec | 57 | stats[i].thread_id = (uint32_t)threads[i]; |
boro | 0:4beb2ea291ec | 58 | stats[i].stack_cnt = 1; |
boro | 0:4beb2ea291ec | 59 | } |
boro | 0:4beb2ea291ec | 60 | osKernelUnlock(); |
boro | 0:4beb2ea291ec | 61 | |
boro | 0:4beb2ea291ec | 62 | free(threads); |
boro | 0:4beb2ea291ec | 63 | #endif |
boro | 0:4beb2ea291ec | 64 | |
boro | 0:4beb2ea291ec | 65 | return i; |
boro | 0:4beb2ea291ec | 66 | } |
boro | 0:4beb2ea291ec | 67 | |
boro | 0:4beb2ea291ec | 68 | #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT |
boro | 0:4beb2ea291ec | 69 | #warning Stack statistics are currently not supported without the rtos. |
boro | 0:4beb2ea291ec | 70 | #endif |