MemoryUsage
Arduino library MemoryUsage
MemoryUsage.h
Go to the documentation of this file.
1 /*
2 MemoryUsage.h - MemoryUsage library V2.10
3 Copyright (c) 2015 Thierry Paris. All right reserved.
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #ifndef __MemoryUsage_h__
21 #define __MemoryUsage_h__
22 
23 #include <stdint.h>
24 
107 extern uint8_t _end;
108 extern uint8_t __stack;
109 extern uint8_t *__brkval;
110 extern uint8_t *__data_start;
111 extern uint8_t *__data_end;
112 extern uint8_t *__heap_start;
113 extern uint8_t *__heap_end;
114 extern uint8_t *__bss_start;
115 extern uint8_t *__bss_end;
116 
117 //
118 // Memory addresses
119 //
120 
122 #define MEMORY_PRINT_START { Serial.print(F("Data start:")); Serial.println((int) &__data_start); }
123 #define MEMORY_PRINT_HEAPSTART { Serial.print(F("Heap start:")); Serial.println((int)&__heap_start); }
125 #define MEMORY_PRINT_HEAPEND { Serial.print(F("Heap end:")); Serial.println(__brkval == 0 ? (int)&__heap_start : (int)__brkval); }
127 #define MEMORY_PRINT_STACKSTART { Serial.print(F("Stack start:")); Serial.println((int) SP); }
129 #define MEMORY_PRINT_END { Serial.print(F("Stack end:")); Serial.println((int) RAMEND); }
131 
133 #define MEMORY_PRINT_HEAPSIZE { Serial.print(F("Heap size:")); Serial.println((int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval) - (int)&__heap_start); }
134 #define MEMORY_PRINT_STACKSIZE { Serial.print(F("Stack size:")); Serial.println((int) RAMEND - (int)SP); }
136 #define MEMORY_PRINT_FREERAM { Serial.print(F("Free ram:")); Serial.println((int) SP - (int) (__brkval == 0 ? (int)&__heap_start : (int)__brkval) - (int)&__heap_start); }
138 #define MEMORY_PRINT_TOTALSIZE { Serial.print(F("SRAM size:")); Serial.println((int) RAMEND - (int) &__data_start); }
140 
142 void SRamDisplay(void);
143 
144 //
145 // Stack count part. STACK_COMPUTE will get the maximum size of the stack at the moment...
146 //
147 
149 #define STACK_DECLARE unsigned int mu_stack_size = (RAMEND - SP);
150 
152 #define STACK_COMPUTE { mu_stack_size = (RAMEND - SP) > mu_stack_size ? (RAMEND - SP) : mu_stack_size;}
153 
155 #define STACK_PRINT_TEXT(text) { STACK_COMPUTE; Serial.print(text); Serial.println(mu_stack_size); }
156 
158 #define STACK_PRINT STACK_PRINT_TEXT(F("Stack Maximum Size (Instrumentation method): "));
159 
160 //
161 // Free Ram part.
162 //
163 
165 #define FREERAM_PRINT_TEXT(text) Serial.print(text); Serial.println(mu_freeRam());
166 
168 #define FREERAM_PRINT FREERAM_PRINT_TEXT(F("Free Ram Size: "));
169 
171 int mu_freeRam(void);
172 
173 //
174 // StackPaint part. This macro gives a view of used stack area at the end of execution...
175 //
176 
178 uint16_t mu_StackCount(void);
179 
181 #define STACKPAINT_PRINT_TEXT(text) { Serial.print(text); Serial.println(mu_StackCount()); }
182 
184 #define STACKPAINT_PRINT STACKPAINT_PRINT_TEXT(F("Stack Maximum Size (Painting method): "));
185 
186 
187 #endif
uint16_t mu_StackCount(void)
Show the stack size on console.
Definition: MemoryUsage.cpp:72
int mu_freeRam(void)
Show the free Ram size on console.
void SRamDisplay(void)
Displays the &#39;map&#39; of the current state of the Arduino&#39;s SRAM memory on the Serial conso...
Definition: MemoryUsage.cpp:83