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-dev/platform/mbed_stats.c@2:5acdd8565d02, 2017-02-25 (annotated)
- Committer:
- elmot
- Date:
- Sat Feb 25 00:23:53 2017 +0000
- Revision:
- 2:5acdd8565d02
- Parent:
- 1:d0dfbce63a89
Ready to show
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elmot | 1:d0dfbce63a89 | 1 | #include "mbed_stats.h" |
elmot | 1:d0dfbce63a89 | 2 | #include <string.h> |
elmot | 1:d0dfbce63a89 | 3 | |
elmot | 1:d0dfbce63a89 | 4 | #if MBED_CONF_RTOS_PRESENT |
elmot | 1:d0dfbce63a89 | 5 | #include "cmsis_os.h" |
elmot | 1:d0dfbce63a89 | 6 | #endif |
elmot | 1:d0dfbce63a89 | 7 | |
elmot | 1:d0dfbce63a89 | 8 | // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp |
elmot | 1:d0dfbce63a89 | 9 | |
elmot | 1:d0dfbce63a89 | 10 | void mbed_stats_stack_get(mbed_stats_stack_t *stats) |
elmot | 1:d0dfbce63a89 | 11 | { |
elmot | 1:d0dfbce63a89 | 12 | memset(stats, 0, sizeof(mbed_stats_stack_t)); |
elmot | 1:d0dfbce63a89 | 13 | |
elmot | 1:d0dfbce63a89 | 14 | #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
elmot | 1:d0dfbce63a89 | 15 | osThreadEnumId enumid = _osThreadsEnumStart(); |
elmot | 1:d0dfbce63a89 | 16 | osThreadId threadid; |
elmot | 1:d0dfbce63a89 | 17 | |
elmot | 1:d0dfbce63a89 | 18 | while ((threadid = _osThreadEnumNext(enumid))) { |
elmot | 1:d0dfbce63a89 | 19 | osEvent e; |
elmot | 1:d0dfbce63a89 | 20 | |
elmot | 1:d0dfbce63a89 | 21 | e = _osThreadGetInfo(threadid, osThreadInfoStackMax); |
elmot | 1:d0dfbce63a89 | 22 | if (e.status == osOK) { |
elmot | 1:d0dfbce63a89 | 23 | stats->max_size += (uint32_t)e.value.p; |
elmot | 1:d0dfbce63a89 | 24 | } |
elmot | 1:d0dfbce63a89 | 25 | |
elmot | 1:d0dfbce63a89 | 26 | e = _osThreadGetInfo(threadid, osThreadInfoStackSize); |
elmot | 1:d0dfbce63a89 | 27 | if (e.status == osOK) { |
elmot | 1:d0dfbce63a89 | 28 | stats->reserved_size += (uint32_t)e.value.p; |
elmot | 1:d0dfbce63a89 | 29 | } |
elmot | 1:d0dfbce63a89 | 30 | |
elmot | 1:d0dfbce63a89 | 31 | stats->stack_cnt += 1; |
elmot | 1:d0dfbce63a89 | 32 | } |
elmot | 1:d0dfbce63a89 | 33 | #endif |
elmot | 1:d0dfbce63a89 | 34 | } |
elmot | 1:d0dfbce63a89 | 35 | |
elmot | 1:d0dfbce63a89 | 36 | size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count) |
elmot | 1:d0dfbce63a89 | 37 | { |
elmot | 1:d0dfbce63a89 | 38 | memset(stats, 0, count*sizeof(mbed_stats_stack_t)); |
elmot | 1:d0dfbce63a89 | 39 | size_t i = 0; |
elmot | 1:d0dfbce63a89 | 40 | |
elmot | 1:d0dfbce63a89 | 41 | #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT |
elmot | 1:d0dfbce63a89 | 42 | osThreadEnumId enumid = _osThreadsEnumStart(); |
elmot | 1:d0dfbce63a89 | 43 | osThreadId threadid; |
elmot | 1:d0dfbce63a89 | 44 | |
elmot | 1:d0dfbce63a89 | 45 | while ((threadid = _osThreadEnumNext(enumid)) && i < count) { |
elmot | 1:d0dfbce63a89 | 46 | osEvent e; |
elmot | 1:d0dfbce63a89 | 47 | |
elmot | 1:d0dfbce63a89 | 48 | e = _osThreadGetInfo(threadid, osThreadInfoStackMax); |
elmot | 1:d0dfbce63a89 | 49 | if (e.status == osOK) { |
elmot | 1:d0dfbce63a89 | 50 | stats[i].max_size = (uint32_t)e.value.p; |
elmot | 1:d0dfbce63a89 | 51 | } |
elmot | 1:d0dfbce63a89 | 52 | |
elmot | 1:d0dfbce63a89 | 53 | e = _osThreadGetInfo(threadid, osThreadInfoStackSize); |
elmot | 1:d0dfbce63a89 | 54 | if (e.status == osOK) { |
elmot | 1:d0dfbce63a89 | 55 | stats[i].reserved_size = (uint32_t)e.value.p; |
elmot | 1:d0dfbce63a89 | 56 | } |
elmot | 1:d0dfbce63a89 | 57 | |
elmot | 1:d0dfbce63a89 | 58 | stats[i].thread_id = (uint32_t)threadid; |
elmot | 1:d0dfbce63a89 | 59 | stats[i].stack_cnt = 1; |
elmot | 1:d0dfbce63a89 | 60 | i += 1; |
elmot | 1:d0dfbce63a89 | 61 | } |
elmot | 1:d0dfbce63a89 | 62 | #endif |
elmot | 1:d0dfbce63a89 | 63 | |
elmot | 1:d0dfbce63a89 | 64 | return i; |
elmot | 1:d0dfbce63a89 | 65 | } |
elmot | 1:d0dfbce63a89 | 66 | |
elmot | 1:d0dfbce63a89 | 67 | #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT |
elmot | 1:d0dfbce63a89 | 68 | #warning Stack statistics are currently not supported without the rtos. |
elmot | 1:d0dfbce63a89 | 69 | #endif |