BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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