From a8fbad5d8bfd6c0abca8a6759785c61d1f553b3f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 23 Nov 2016 17:31:53 -0800 Subject: Add heap analysis scripts based on GDB breakpoint logs. --- py/gc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'py/gc.c') diff --git a/py/gc.c b/py/gc.c index f883a724e..a93f7347a 100644 --- a/py/gc.c +++ b/py/gc.c @@ -102,6 +102,15 @@ #define GC_EXIT() #endif +#ifdef LOG_HEAP_ACTIVITY +volatile uint32_t change_me; + +void __attribute__ ((noinline)) gc_log_change(uint32_t start_block, uint32_t length) { + change_me += start_block; + change_me += length; // Break on this line. +} +#endif + // TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool void gc_init(void *start, void *end) { // align end pointer on block boundary @@ -278,6 +287,10 @@ STATIC void gc_sweep(void) { #endif free_tail = 1; DEBUG_printf("gc_sweep(%x)\n", PTR_FROM_BLOCK(block)); + + #ifdef LOG_HEAP_ACTIVITY + gc_log_change(block, 0); + #endif #if MICROPY_PY_GC_COLLECT_RETVAL MP_STATE_MEM(gc_collected)++; #endif @@ -470,6 +483,10 @@ found: MP_STATE_MEM(gc_last_free_atb_index) = (i + 1) / BLOCKS_PER_ATB; } + #ifdef LOG_HEAP_ACTIVITY + gc_log_change(start_block, end_block - start_block + 1); + #endif + // mark first block as used head ATB_FREE_TO_HEAD(start_block); @@ -556,6 +573,9 @@ void gc_free(void *ptr) { } // free head and all of its tail blocks + #ifdef LOG_HEAP_ACTIVITY + gc_log_change(block, 0); + #endif do { ATB_ANY_TO_FREE(block); block += 1; @@ -715,6 +735,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { gc_dump_alloc_table(); #endif + #ifdef LOG_HEAP_ACTIVITY + gc_log_change(block, new_blocks); + #endif + return ptr_in; } @@ -740,6 +764,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { gc_dump_alloc_table(); #endif + #ifdef LOG_HEAP_ACTIVITY + gc_log_change(block, new_blocks); + #endif + return ptr_in; } -- cgit v1.2.3