summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/gc.c11
-rw-r--r--unix/gccollect.c12
2 files changed, 14 insertions, 9 deletions
diff --git a/py/gc.c b/py/gc.c
index c8256fb03b..9c8d203d28 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -240,7 +240,7 @@ void gc_info(gc_info_t *info) {
void *gc_alloc(machine_uint_t n_bytes) {
machine_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
- //printf("gc_alloc(%u bytes -> %u blocks)\n", n_bytes, n_blocks);
+ DEBUG_printf("gc_alloc(%u bytes -> %u blocks)\n", n_bytes, n_blocks);
// check for 0 allocation
if (n_blocks == 0) {
@@ -267,6 +267,7 @@ void *gc_alloc(machine_uint_t n_bytes) {
if (collected) {
return NULL;
}
+ DEBUG_printf("gc_alloc(" UINT_FMT "): no free mem, triggering GC\n", n_bytes);
gc_collect();
collected = 1;
}
@@ -341,6 +342,14 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) {
}
}
+void gc_dump_info() {
+ gc_info_t info;
+ gc_info(&info);
+ printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free);
+ printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
+ info.num_1block, info.num_2block, info.max_block);
+}
+
#if DEBUG_PRINT
static void gc_dump_at(void) {
for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) {
diff --git a/unix/gccollect.c b/unix/gccollect.c
index cb2cc7a034..60bc99323e 100644
--- a/unix/gccollect.c
+++ b/unix/gccollect.c
@@ -48,6 +48,8 @@ void gc_helper_get_regs(regs_t arr) {
#endif
void gc_collect(void) {
+ //gc_dump_info();
+
gc_collect_start();
// this traces .data and .bss sections
extern char __bss_start, _end;
@@ -59,14 +61,8 @@ void gc_collect(void) {
gc_collect_root((void**)&regs, ((uint32_t)stack_top - (uint32_t)&regs) / sizeof(uint32_t));
gc_collect_end();
- if (0) {
- // print GC info
- gc_info_t info;
- gc_info(&info);
- printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free);
- printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
- info.num_1block, info.num_2block, info.max_block);
- }
+ //printf("-----\n");
+ //gc_dump_info();
}
#endif //MICROPY_ENABLE_GC