Senthil Ramakrishnan / Mbed 2 deprecated mbed-os-example-platform-utils

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Example usage for Debug, Assert, Error and MemoryStats 
00002  * Copyright (c) 2016 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "platform/mbed_assert.h"
00019 #include "platform/mbed_debug.h"
00020 #include "platform/mbed_error.h"
00021 #include "platform/mbed_stats.h"
00022 
00023 #define MAX_THREAD_INFO 10
00024 
00025 mbed_stats_heap_t heap_info;
00026 mbed_stats_stack_t stack_info[ MAX_THREAD_INFO ];
00027 int main()
00028 {
00029     debug("\nThis message is from debug function");
00030     debug_if(1,"\nThis message is from debug_if function");
00031     debug_if(0,"\nSOMETHING WRONG!!! This message from debug_if function shouldn't show on bash");
00032     
00033     printf("\nMemoryStats:");
00034     mbed_stats_heap_get( &heap_info );
00035     printf("\n\tBytes allocated currently: %d", heap_info.current_size);
00036     printf("\n\tMax bytes allocated at a given time: %d", heap_info.max_size);
00037     printf("\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size);
00038     printf("\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size);
00039     printf("\n\tCurrent number of allocations: %d", heap_info.alloc_cnt);
00040     printf("\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt);
00041     
00042     mbed_stats_stack_get( &stack_info[0] );
00043     printf("\nCumulative Stack Info:");
00044     printf("\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size);
00045     printf("\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size);
00046     printf("\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt);
00047     
00048     mbed_stats_stack_get_each( stack_info, MAX_THREAD_INFO );
00049     printf("\nThread Stack Info:");
00050     for(int i=0;i < MAX_THREAD_INFO; i++) {
00051         if(stack_info[i].thread_id != 0) {
00052             printf("\n\tThread: %d", i);
00053             printf("\n\t\tThread Id: 0x%08X", stack_info[i].thread_id);
00054             printf("\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size);
00055             printf("\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size);
00056             printf("\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt); 
00057         }        
00058     }
00059     
00060     printf("\nDone...\n\n");
00061 }