From 2d15c1216ddad8ee603106fd86ad36baf2d40ff8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Jan 2014 20:33:20 +0000 Subject: stm: Add optional memory debugging output. --- py/malloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'py/malloc.c') diff --git a/py/malloc.c b/py/malloc.c index 4f01dc63f5..a2c55eb06b 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -4,6 +4,12 @@ #include "misc.h" #include "mpconfig.h" +#if 0 // print debugging info +#define DEBUG_printf(args...) printf(args) +#else // don't print debugging info +#define DEBUG_printf(args...) (void)0 +#endif + #if MICROPY_MEM_STATS static int total_bytes_allocated = 0; static int current_bytes_allocated = 0; @@ -26,6 +32,7 @@ void *m_malloc(int num_bytes) { current_bytes_allocated += num_bytes; UPDATE_PEAK(); #endif + DEBUG_printf("malloc %d : %p\n", num_bytes, ptr); return ptr; } @@ -43,6 +50,7 @@ void *m_malloc0(int num_bytes) { current_bytes_allocated += num_bytes; UPDATE_PEAK(); #endif + DEBUG_printf("malloc0 %d : %p\n", num_bytes, ptr); return ptr; } @@ -67,6 +75,7 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) { current_bytes_allocated += diff; UPDATE_PEAK(); #endif + DEBUG_printf("realloc %d, %d : %p\n", old_num_bytes, new_num_bytes, ptr); return ptr; } @@ -77,6 +86,7 @@ void m_free(void *ptr, int num_bytes) { #if MICROPY_MEM_STATS current_bytes_allocated -= num_bytes; #endif + DEBUG_printf("free %p, %d\n", ptr, num_bytes); } int m_get_total_bytes_allocated(void) { -- cgit v1.2.3