summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2016-11-23 17:31:53 -0800
committerScott Shawcroft <scott.shawcroft@gmail.com>2016-11-23 17:31:53 -0800
commita8fbad5d8bfd6c0abca8a6759785c61d1f553b3f (patch)
tree15bbb65ac1626096e3f91e2ff0f0b116ddc76871 /py
parentea1320bee7fbd0f895e8afe528e4b528489b2c5e (diff)
Add heap analysis scripts based on GDB breakpoint logs.
Diffstat (limited to 'py')
-rw-r--r--py/gc.c28
1 files changed, 28 insertions, 0 deletions
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;
}