Skip to content

Commit 42ff22c

Browse files
author
Qinghao Shi
authored
Merge pull request #83 from maciejbocianski/move_stats_examples
add memory stats examples
2 parents 3190112 + bb2d635 commit 42ff22c

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Heap stats example
2+
3+
Example to demonstrate usage of heap stats
4+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
#include "mbed_stats.h"
8+
9+
int main(void)
10+
{
11+
mbed_stats_heap_t heap_stats;
12+
13+
printf("Starting heap stats example\r\n");
14+
mbed_stats_heap_get(&heap_stats);
15+
printf("Start; Current heap: %lu\n", heap_stats.current_size);
16+
printf("Start; Max heap size: %lu\n", heap_stats.max_size);
17+
18+
printf("\nAllocating 1000 bytes\n");
19+
void *allocation = malloc(1000);
20+
21+
mbed_stats_heap_get(&heap_stats);
22+
printf("Post-Alloc; Current heap: %lu\n", heap_stats.current_size);
23+
printf("Post-Alloc; Max heap size: %lu\n", heap_stats.max_size);
24+
25+
free(allocation);
26+
printf("\nFreed 1000 bytes\n");
27+
28+
mbed_stats_heap_get(&heap_stats);
29+
printf("Post-Free; Current heap: %lu\n", heap_stats.current_size);
30+
printf("Post-Free; Max heap size: %lu\n", heap_stats.max_size);
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"macros": ["MBED_HEAP_STATS_ENABLED=1"]
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Stack stats example
2+
3+
Example to demonstrate usage of `mbed_stats_stack_get_each` API
4+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
#include "mbed_stats.h"
8+
9+
int main(void)
10+
{
11+
printf("Starting stack stats example\r\n");
12+
13+
int cnt = osThreadGetCount();
14+
mbed_stats_stack_t *stats = (mbed_stats_stack_t *) malloc(cnt * sizeof(mbed_stats_stack_t));
15+
16+
if (stats) {
17+
cnt = mbed_stats_stack_get_each(stats, cnt);
18+
for (int i = 0; i < cnt; i++) {
19+
printf("Thread: 0x%lx, Stack size: %u, Max stack: %u\r\n",
20+
stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
21+
}
22+
free(stats);
23+
}
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"macros": ["MBED_STACK_STATS_ENABLED=1"]
3+
}

0 commit comments

Comments
 (0)