Example to demonstrate usage of mbed_stats_stack_get_each API

Fork of heap_stats_example by mbed_example

main.cpp

Committer:
deepikabhavnani
Date:
19 months ago
Revision:
5:dcc8640ad89c
Parent:
4:539750137652

File content as of revision 5:dcc8640ad89c:

#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);
    }
}