Skip to content

Commit 9b630b3

Browse files
committed
stats - Added stack stats api for individual threads
Added the following - size_t mbed_stats_stack_get_each(mbed_stats_stack_t *, size_t)
1 parent 14aa57f commit 9b630b3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

platform/mbed_stats.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,40 @@ void mbed_stats_stack_get(mbed_stats_stack_t *stats)
3030

3131
stats->stack_cnt += 1;
3232
}
33-
#elif MBED_STACK_STATS_ENABLED
34-
#warning Stack statistics are not supported without the rtos.
3533
#endif
3634
}
3735

36+
size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
37+
{
38+
memset(stats, 0, count*sizeof(mbed_stats_stack_t));
39+
size_t i = 0;
40+
41+
#if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
42+
osThreadEnumId enumid = _osThreadsEnumStart();
43+
osThreadId threadid;
44+
45+
while ((threadid = _osThreadEnumNext(enumid)) && i < count) {
46+
osEvent e;
47+
48+
e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
49+
if (e.status == osOK) {
50+
stats[i].max_size = (uint32_t)e.value.p;
51+
}
52+
53+
e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
54+
if (e.status == osOK) {
55+
stats[i].reserved_size = (uint32_t)e.value.p;
56+
}
57+
58+
stats[i].thread_id = (uint32_t)threadid;
59+
stats[i].stack_cnt = 1;
60+
i += 1;
61+
}
62+
#endif
63+
64+
return i;
65+
}
66+
67+
#if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT
68+
#warning Stack statistics are currently not supported without the rtos.
69+
#endif

platform/mbed_stats.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef MBED_STATS_H
2020
#define MBED_STATS_H
2121
#include <stdint.h>
22+
#include <stddef.h>
2223

2324
#ifdef __cplusplus
2425
extern "C" {
@@ -39,6 +40,7 @@ typedef struct {
3940
void mbed_stats_heap_get(mbed_stats_heap_t *stats);
4041

4142
typedef struct {
43+
uint32_t thread_id; /**< Identifier for thread that owns the stack. */
4244
uint32_t max_size; /**< Sum of the maximum number of bytes used in each stack. */
4345
uint32_t reserved_size; /**< Current number of bytes allocated for all stacks. */
4446
uint32_t stack_cnt; /**< Number of stacks currently allocated. */
@@ -49,6 +51,12 @@ typedef struct {
4951
*/
5052
void mbed_stats_stack_get(mbed_stats_stack_t *stats);
5153

54+
/**
55+
* Fill the passed array of stat structures with the stack stats
56+
* for each available stack.
57+
*/
58+
size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
59+
5260
#ifdef __cplusplus
5361
}
5462
#endif

0 commit comments

Comments
 (0)