Skip to content

Commit 749cbac

Browse files
committed
py/gc: Calculate (and report) maximum contiguous free block size.
Just as maximum allocated block size, it's reported in allocation units (not bytes).
1 parent 35962ea commit 749cbac

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

py/gc.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,17 @@ void gc_info(gc_info_t *info) {
324324
info->total = MP_STATE_MEM(gc_pool_end) - MP_STATE_MEM(gc_pool_start);
325325
info->used = 0;
326326
info->free = 0;
327+
info->max_free = 0;
327328
info->num_1block = 0;
328329
info->num_2block = 0;
329330
info->max_block = 0;
330331
bool finish = false;
331-
for (size_t block = 0, len = 0; !finish;) {
332+
for (size_t block = 0, len = 0, len_free = 0; !finish;) {
332333
size_t kind = ATB_GET_KIND(block);
333334
switch (kind) {
334335
case AT_FREE:
335336
info->free += 1;
337+
len_free += 1;
336338
len = 0;
337339
break;
338340

@@ -367,6 +369,12 @@ void gc_info(gc_info_t *info) {
367369
if (len > info->max_block) {
368370
info->max_block = len;
369371
}
372+
if (finish || kind == AT_HEAD) {
373+
if (len_free > info->max_free) {
374+
info->max_free = len_free;
375+
}
376+
len_free = 0;
377+
}
370378
}
371379
}
372380

@@ -726,8 +734,8 @@ void gc_dump_info(void) {
726734
gc_info(&info);
727735
mp_printf(&mp_plat_print, "GC: total: %u, used: %u, free: %u\n",
728736
(uint)info.total, (uint)info.used, (uint)info.free);
729-
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u\n",
730-
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block);
737+
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n",
738+
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free);
731739
}
732740

733741
void gc_dump_alloc_table(void) {

py/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct _gc_info_t {
5454
size_t total;
5555
size_t used;
5656
size_t free;
57+
size_t max_free;
5758
size_t num_1block;
5859
size_t num_2block;
5960
size_t max_block;

0 commit comments

Comments
 (0)