Skip to content

Commit 723a6ed

Browse files
committed
More GC debugging improvements.
1 parent 20632e4 commit 723a6ed

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

py/gc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void gc_info(gc_info_t *info) {
240240

241241
void *gc_alloc(machine_uint_t n_bytes) {
242242
machine_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
243-
//printf("gc_alloc(%u bytes -> %u blocks)\n", n_bytes, n_blocks);
243+
DEBUG_printf("gc_alloc(%u bytes -> %u blocks)\n", n_bytes, n_blocks);
244244

245245
// check for 0 allocation
246246
if (n_blocks == 0) {
@@ -267,6 +267,7 @@ void *gc_alloc(machine_uint_t n_bytes) {
267267
if (collected) {
268268
return NULL;
269269
}
270+
DEBUG_printf("gc_alloc(" UINT_FMT "): no free mem, triggering GC\n", n_bytes);
270271
gc_collect();
271272
collected = 1;
272273
}
@@ -341,6 +342,14 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) {
341342
}
342343
}
343344

345+
void gc_dump_info() {
346+
gc_info_t info;
347+
gc_info(&info);
348+
printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free);
349+
printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
350+
info.num_1block, info.num_2block, info.max_block);
351+
}
352+
344353
#if DEBUG_PRINT
345354
static void gc_dump_at(void) {
346355
for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) {

unix/gccollect.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ void gc_helper_get_regs(regs_t arr) {
4848
#endif
4949

5050
void gc_collect(void) {
51+
//gc_dump_info();
52+
5153
gc_collect_start();
5254
// this traces .data and .bss sections
5355
extern char __bss_start, _end;
@@ -59,14 +61,8 @@ void gc_collect(void) {
5961
gc_collect_root((void**)&regs, ((uint32_t)stack_top - (uint32_t)&regs) / sizeof(uint32_t));
6062
gc_collect_end();
6163

62-
if (0) {
63-
// print GC info
64-
gc_info_t info;
65-
gc_info(&info);
66-
printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free);
67-
printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
68-
info.num_1block, info.num_2block, info.max_block);
69-
}
64+
//printf("-----\n");
65+
//gc_dump_info();
7066
}
7167

7268
#endif //MICROPY_ENABLE_GC

0 commit comments

Comments
 (0)