Skip to content

Commit b6e8f44

Browse files
committed
stats - Added stack stats api
Matched heap stats api - void mbed_stats_heap_get(mbed_stats_heap_t *) - void mbed_stats_stack_get(mbed_stats_stack_t *)
1 parent 03b8ae1 commit b6e8f44

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

platform/mbed_stats.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "mbed_stats.h"
2+
#include <string.h>
3+
4+
#if MBED_CONF_RTOS_PRESENT
5+
#include "cmsis_os.h"
6+
#endif
7+
8+
// note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
9+
10+
void mbed_stats_stack_get(mbed_stats_stack_t *stats)
11+
{
12+
memset(stats, 0, sizeof(mbed_stats_stack_t));
13+
14+
#if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
15+
osThreadEnumId enumid = _osThreadsEnumStart();
16+
osThreadId threadid;
17+
18+
while ((threadid = _osThreadEnumNext(enumid))) {
19+
osEvent e;
20+
21+
e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
22+
if (e.status == osOK) {
23+
stats->max_size += (uint32_t)e.value.p;
24+
}
25+
26+
e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
27+
if (e.status == osOK) {
28+
stats->reserved_size += (uint32_t)e.value.p;
29+
}
30+
31+
stats->stack_cnt += 1;
32+
}
33+
#elif MBED_STACK_STATS_ENABLED
34+
#warning Stack statistics are not supported without the rtos.
35+
#endif
36+
}
37+

platform/mbed_stats.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
#ifndef MBED_STATS_H
2020
#define MBED_STATS_H
21+
#include <stdint.h>
2122

2223
#ifdef __cplusplus
2324
extern "C" {
@@ -36,6 +37,17 @@ typedef struct {
3637
*/
3738
void mbed_stats_heap_get(mbed_stats_heap_t *stats);
3839

40+
typedef struct {
41+
uint32_t max_size; /**< Sum of the maximum number of bytes used in each stack. */
42+
uint32_t reserved_size; /**< Current number of bytes allocated for all stacks. */
43+
uint32_t stack_cnt; /**< Number of stacks currently allocated. */
44+
} mbed_stats_stack_t;
45+
46+
/**
47+
* Fill the passed in structure with stack stats.
48+
*/
49+
void mbed_stats_stack_get(mbed_stats_stack_t *stats);
50+
3951
#ifdef __cplusplus
4052
}
4153
#endif

0 commit comments

Comments
 (0)