Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-platform-utils by
main.cpp@2:c03cd481c34b, 2017-10-30 (annotated)
- Committer:
- Senthil Ramakrishnan
- Date:
- Mon Oct 30 14:21:38 2017 -0500
- Revision:
- 2:c03cd481c34b
- Parent:
- 0:2ab002d36417
Updated README
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| SenRam | 0:2ab002d36417 | 1 | /* Example usage for Debug, Assert, Error and MemoryStats |
| SenRam | 0:2ab002d36417 | 2 | * Copyright (c) 2016 ARM Limited |
| SenRam | 0:2ab002d36417 | 3 | * |
| SenRam | 0:2ab002d36417 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| SenRam | 0:2ab002d36417 | 5 | * you may not use this file except in compliance with the License. |
| SenRam | 0:2ab002d36417 | 6 | * You may obtain a copy of the License at |
| SenRam | 0:2ab002d36417 | 7 | * |
| SenRam | 0:2ab002d36417 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| SenRam | 0:2ab002d36417 | 9 | * |
| SenRam | 0:2ab002d36417 | 10 | * Unless required by applicable law or agreed to in writing, software |
| SenRam | 0:2ab002d36417 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| SenRam | 0:2ab002d36417 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| SenRam | 0:2ab002d36417 | 13 | * See the License for the specific language governing permissions and |
| SenRam | 0:2ab002d36417 | 14 | * limitations under the License. |
| SenRam | 0:2ab002d36417 | 15 | */ |
| SenRam | 0:2ab002d36417 | 16 | |
| SenRam | 0:2ab002d36417 | 17 | #include "mbed.h" |
| SenRam | 0:2ab002d36417 | 18 | #include "platform/mbed_assert.h" |
| SenRam | 0:2ab002d36417 | 19 | #include "platform/mbed_debug.h" |
| SenRam | 0:2ab002d36417 | 20 | #include "platform/mbed_error.h" |
| SenRam | 0:2ab002d36417 | 21 | #include "platform/mbed_stats.h" |
| SenRam | 0:2ab002d36417 | 22 | |
| SenRam | 0:2ab002d36417 | 23 | #define MAX_THREAD_INFO 10 |
| SenRam | 0:2ab002d36417 | 24 | |
| SenRam | 0:2ab002d36417 | 25 | mbed_stats_heap_t heap_info; |
| SenRam | 0:2ab002d36417 | 26 | mbed_stats_stack_t stack_info[ MAX_THREAD_INFO ]; |
| SenRam | 0:2ab002d36417 | 27 | int main() |
| SenRam | 0:2ab002d36417 | 28 | { |
| SenRam | 0:2ab002d36417 | 29 | debug("\nThis message is from debug function"); |
| SenRam | 0:2ab002d36417 | 30 | debug_if(1,"\nThis message is from debug_if function"); |
| SenRam | 0:2ab002d36417 | 31 | debug_if(0,"\nSOMETHING WRONG!!! This message from debug_if function shouldn't show on bash"); |
| SenRam | 0:2ab002d36417 | 32 | |
| SenRam | 0:2ab002d36417 | 33 | printf("\nMemoryStats:"); |
| SenRam | 0:2ab002d36417 | 34 | mbed_stats_heap_get( &heap_info ); |
| SenRam | 0:2ab002d36417 | 35 | printf("\n\tBytes allocated currently: %d", heap_info.current_size); |
| SenRam | 0:2ab002d36417 | 36 | printf("\n\tMax bytes allocated at a given time: %d", heap_info.max_size); |
| SenRam | 0:2ab002d36417 | 37 | printf("\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size); |
| SenRam | 0:2ab002d36417 | 38 | printf("\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size); |
| SenRam | 0:2ab002d36417 | 39 | printf("\n\tCurrent number of allocations: %d", heap_info.alloc_cnt); |
| SenRam | 0:2ab002d36417 | 40 | printf("\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt); |
| SenRam | 0:2ab002d36417 | 41 | |
| SenRam | 0:2ab002d36417 | 42 | mbed_stats_stack_get( &stack_info[0] ); |
| SenRam | 0:2ab002d36417 | 43 | printf("\nCumulative Stack Info:"); |
| SenRam | 0:2ab002d36417 | 44 | printf("\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size); |
| SenRam | 0:2ab002d36417 | 45 | printf("\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size); |
| SenRam | 0:2ab002d36417 | 46 | printf("\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt); |
| SenRam | 0:2ab002d36417 | 47 | |
| SenRam | 0:2ab002d36417 | 48 | mbed_stats_stack_get_each( stack_info, MAX_THREAD_INFO ); |
| SenRam | 0:2ab002d36417 | 49 | printf("\nThread Stack Info:"); |
| SenRam | 0:2ab002d36417 | 50 | for(int i=0;i < MAX_THREAD_INFO; i++) { |
| SenRam | 0:2ab002d36417 | 51 | if(stack_info[i].thread_id != 0) { |
| SenRam | 0:2ab002d36417 | 52 | printf("\n\tThread: %d", i); |
| SenRam | 0:2ab002d36417 | 53 | printf("\n\t\tThread Id: 0x%08X", stack_info[i].thread_id); |
| SenRam | 0:2ab002d36417 | 54 | printf("\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size); |
| SenRam | 0:2ab002d36417 | 55 | printf("\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size); |
| SenRam | 0:2ab002d36417 | 56 | printf("\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt); |
| SenRam | 0:2ab002d36417 | 57 | } |
| SenRam | 0:2ab002d36417 | 58 | } |
| SenRam | 0:2ab002d36417 | 59 | |
| SenRam | 0:2ab002d36417 | 60 | printf("\nDone...\n\n"); |
| SenRam | 0:2ab002d36417 | 61 | } |
