Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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