SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

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