Skip to content

add memory stats examples #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions APIs_Platform/Heap_Stats_ex_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Heap stats example

Example to demonstrate usage of heap stats

31 changes: 31 additions & 0 deletions APIs_Platform/Heap_Stats_ex_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"
#include "mbed_stats.h"

int main(void)
{
mbed_stats_heap_t heap_stats;

printf("Starting heap stats example\r\n");
mbed_stats_heap_get(&heap_stats);
printf("Start; Current heap: %lu\n", heap_stats.current_size);
printf("Start; Max heap size: %lu\n", heap_stats.max_size);

printf("\nAllocating 1000 bytes\n");
void *allocation = malloc(1000);

mbed_stats_heap_get(&heap_stats);
printf("Post-Alloc; Current heap: %lu\n", heap_stats.current_size);
printf("Post-Alloc; Max heap size: %lu\n", heap_stats.max_size);

free(allocation);
printf("\nFreed 1000 bytes\n");

mbed_stats_heap_get(&heap_stats);
printf("Post-Free; Current heap: %lu\n", heap_stats.current_size);
printf("Post-Free; Max heap size: %lu\n", heap_stats.max_size);
}
3 changes: 3 additions & 0 deletions APIs_Platform/Heap_Stats_ex_1/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"macros": ["MBED_HEAP_STATS_ENABLED=1"]
}
4 changes: 4 additions & 0 deletions APIs_Platform/Stack_Stats_ex_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Stack stats example

Example to demonstrate usage of `mbed_stats_stack_get_each` API

24 changes: 24 additions & 0 deletions APIs_Platform/Stack_Stats_ex_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"
#include "mbed_stats.h"

int main(void)
{
printf("Starting stack stats example\r\n");

int cnt = osThreadGetCount();
mbed_stats_stack_t *stats = (mbed_stats_stack_t *) malloc(cnt * sizeof(mbed_stats_stack_t));

if (stats) {
cnt = mbed_stats_stack_get_each(stats, cnt);
for (int i = 0; i < cnt; i++) {
printf("Thread: 0x%lx, Stack size: %u, Max stack: %u\r\n",
stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
}
free(stats);
}
}
3 changes: 3 additions & 0 deletions APIs_Platform/Stack_Stats_ex_1/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"macros": ["MBED_STACK_STATS_ENABLED=1"]
}