forked

Committer:
<>
Date:
Thu Dec 15 11:48:27 2016 +0000
Revision:
152:9a67f0b066fc
Child:
167:e84263d55307
This updates the lib to the mbed lib v131

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 152:9a67f0b066fc 1 #include "mbed_stats.h"
<> 152:9a67f0b066fc 2 #include <string.h>
<> 152:9a67f0b066fc 3
<> 152:9a67f0b066fc 4 #if MBED_CONF_RTOS_PRESENT
<> 152:9a67f0b066fc 5 #include "cmsis_os.h"
<> 152:9a67f0b066fc 6 #endif
<> 152:9a67f0b066fc 7
<> 152:9a67f0b066fc 8 // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
<> 152:9a67f0b066fc 9
<> 152:9a67f0b066fc 10 void mbed_stats_stack_get(mbed_stats_stack_t *stats)
<> 152:9a67f0b066fc 11 {
<> 152:9a67f0b066fc 12 memset(stats, 0, sizeof(mbed_stats_stack_t));
<> 152:9a67f0b066fc 13
<> 152:9a67f0b066fc 14 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
<> 152:9a67f0b066fc 15 osThreadEnumId enumid = _osThreadsEnumStart();
<> 152:9a67f0b066fc 16 osThreadId threadid;
<> 152:9a67f0b066fc 17
<> 152:9a67f0b066fc 18 while ((threadid = _osThreadEnumNext(enumid))) {
<> 152:9a67f0b066fc 19 osEvent e;
<> 152:9a67f0b066fc 20
<> 152:9a67f0b066fc 21 e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
<> 152:9a67f0b066fc 22 if (e.status == osOK) {
<> 152:9a67f0b066fc 23 stats->max_size += (uint32_t)e.value.p;
<> 152:9a67f0b066fc 24 }
<> 152:9a67f0b066fc 25
<> 152:9a67f0b066fc 26 e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
<> 152:9a67f0b066fc 27 if (e.status == osOK) {
<> 152:9a67f0b066fc 28 stats->reserved_size += (uint32_t)e.value.p;
<> 152:9a67f0b066fc 29 }
<> 152:9a67f0b066fc 30
<> 152:9a67f0b066fc 31 stats->stack_cnt += 1;
<> 152:9a67f0b066fc 32 }
<> 152:9a67f0b066fc 33 #endif
<> 152:9a67f0b066fc 34 }
<> 152:9a67f0b066fc 35
<> 152:9a67f0b066fc 36 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
<> 152:9a67f0b066fc 37 {
<> 152:9a67f0b066fc 38 memset(stats, 0, count*sizeof(mbed_stats_stack_t));
<> 152:9a67f0b066fc 39 size_t i = 0;
<> 152:9a67f0b066fc 40
<> 152:9a67f0b066fc 41 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
<> 152:9a67f0b066fc 42 osThreadEnumId enumid = _osThreadsEnumStart();
<> 152:9a67f0b066fc 43 osThreadId threadid;
<> 152:9a67f0b066fc 44
<> 152:9a67f0b066fc 45 while ((threadid = _osThreadEnumNext(enumid)) && i < count) {
<> 152:9a67f0b066fc 46 osEvent e;
<> 152:9a67f0b066fc 47
<> 152:9a67f0b066fc 48 e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
<> 152:9a67f0b066fc 49 if (e.status == osOK) {
<> 152:9a67f0b066fc 50 stats[i].max_size = (uint32_t)e.value.p;
<> 152:9a67f0b066fc 51 }
<> 152:9a67f0b066fc 52
<> 152:9a67f0b066fc 53 e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
<> 152:9a67f0b066fc 54 if (e.status == osOK) {
<> 152:9a67f0b066fc 55 stats[i].reserved_size = (uint32_t)e.value.p;
<> 152:9a67f0b066fc 56 }
<> 152:9a67f0b066fc 57
<> 152:9a67f0b066fc 58 stats[i].thread_id = (uint32_t)threadid;
<> 152:9a67f0b066fc 59 stats[i].stack_cnt = 1;
<> 152:9a67f0b066fc 60 i += 1;
<> 152:9a67f0b066fc 61 }
<> 152:9a67f0b066fc 62 #endif
<> 152:9a67f0b066fc 63
<> 152:9a67f0b066fc 64 return i;
<> 152:9a67f0b066fc 65 }
<> 152:9a67f0b066fc 66
<> 152:9a67f0b066fc 67 #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT
<> 152:9a67f0b066fc 68 #warning Stack statistics are currently not supported without the rtos.
<> 152:9a67f0b066fc 69 #endif