Commit 81b8ba53 authored by Philippe Kalaf's avatar Philippe Kalaf

Code for memory stats for debugging

parent 3137b1c9
......@@ -48,6 +48,10 @@
#include "string"
#include "brewcontrol.h"
#if MBED_HEAP_STATS_ENABLED || MBED_STACK_STATS_ENABLED
#include "platform/mbed_stats.h"
#endif
// This is for debugging and control without a LCD/joystick
Serial pc(USBTX, USBRX); // tx, rx
......@@ -563,6 +567,46 @@ void fire_away()
menu_thread.flags_set(FIRE);
}
#if MBED_HEAP_STATS_ENABLED
void print_heap_stats()
{
mbed_stats_heap_t heap_info;
pc.printf("\nMemoryStats:");
mbed_stats_heap_get( &heap_info );
pc.printf("\n\tBytes allocated currently: %d", heap_info.current_size);
pc.printf("\n\tMax bytes allocated at a given time: %d", heap_info.max_size);
pc.printf("\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size);
pc.printf("\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size);
pc.printf("\n\tCurrent number of allocations: %d", heap_info.alloc_cnt);
pc.printf("\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt);
}
#endif
#if MBED_STACK_STATS_ENABLED
void print_stack_stats()
{
mbed_stats_stack_t stack_info[ 10 ];
mbed_stats_stack_get( &stack_info[0] );
pc.printf("\nCumulative Stack Info:");
pc.printf("\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size);
pc.printf("\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size);
pc.printf("\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt);
mbed_stats_stack_get_each( stack_info, 10 );
pc.printf("\nThread Stack Info:");
for(int i=0;i < 10; i++) {
if(stack_info[i].thread_id != 0) {
pc.printf("\n\tThread: %d", i);
pc.printf("\n\t\tThread Id: 0x%08X", stack_info[i].thread_id);
pc.printf("\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size);
pc.printf("\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size);
pc.printf("\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt);
}
}
}
#endif
// print the actual contrast
int main()
{
......@@ -698,6 +742,13 @@ int main()
brew_control.get_last_pulse_count_side(),
brew_control.get_last_pulse_count_top()
);
#if MBED_HEAP_STATS_ENABLED
print_heap_stats();
#endif
#if MBED_STACK_STATS_ENABLED
print_stack_stats();
#endif
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment