diff --git a/py/malloc.c b/py/malloc.c index 13f0a8fc3e4d3404f3bd2888b710ac305ec93e04..a3736cde4d28f7b05ed2429d01fc5404a0f39bd1 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -5,6 +5,9 @@ static int total_bytes_allocated = 0; static int current_bytes_allocated = 0; +static int peak_bytes_allocated = 0; + +#define UPDATE_PEAK() { if (current_bytes_allocated > peak_bytes_allocated) peak_bytes_allocated = current_bytes_allocated; } void *m_malloc(int num_bytes) { if (num_bytes == 0) { @@ -17,6 +20,7 @@ void *m_malloc(int num_bytes) { } total_bytes_allocated += num_bytes; current_bytes_allocated += num_bytes; + UPDATE_PEAK(); return ptr; } @@ -31,6 +35,7 @@ void *m_malloc0(int num_bytes) { } total_bytes_allocated += num_bytes; current_bytes_allocated += num_bytes; + UPDATE_PEAK(); return ptr; } @@ -52,6 +57,7 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) { int diff = new_num_bytes - old_num_bytes; total_bytes_allocated += diff; current_bytes_allocated += diff; + UPDATE_PEAK(); return ptr; } @@ -69,3 +75,7 @@ int m_get_total_bytes_allocated(void) { int m_get_current_bytes_allocated(void) { return current_bytes_allocated; } + +int m_get_peak_bytes_allocated(void) { + return peak_bytes_allocated; +} diff --git a/py/misc.h b/py/misc.h index 383d3986a7eca7e5f7e3e68ac2b9c9af851b5e52..153218ba2f8b6abf03eea3bb2b82d1d1a121cc1c 100644 --- a/py/misc.h +++ b/py/misc.h @@ -33,6 +33,7 @@ void m_free(void *ptr, int num_bytes); int m_get_total_bytes_allocated(void); int m_get_current_bytes_allocated(void); +int m_get_peak_bytes_allocated(void); /** unichar / UTF-8 *********************************************/