Skip to content
Snippets Groups Projects
Commit 749cbaca authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py/gc: Calculate (and report) maximum contiguous free block size.

Just as maximum allocated block size, it's reported in allocation units
(not bytes).
parent 35962eaa
No related branches found
No related tags found
No related merge requests found
......@@ -324,15 +324,17 @@ void gc_info(gc_info_t *info) {
info->total = MP_STATE_MEM(gc_pool_end) - MP_STATE_MEM(gc_pool_start);
info->used = 0;
info->free = 0;
info->max_free = 0;
info->num_1block = 0;
info->num_2block = 0;
info->max_block = 0;
bool finish = false;
for (size_t block = 0, len = 0; !finish;) {
for (size_t block = 0, len = 0, len_free = 0; !finish;) {
size_t kind = ATB_GET_KIND(block);
switch (kind) {
case AT_FREE:
info->free += 1;
len_free += 1;
len = 0;
break;
......@@ -367,6 +369,12 @@ void gc_info(gc_info_t *info) {
if (len > info->max_block) {
info->max_block = len;
}
if (finish || kind == AT_HEAD) {
if (len_free > info->max_free) {
info->max_free = len_free;
}
len_free = 0;
}
}
}
......@@ -726,8 +734,8 @@ void gc_dump_info(void) {
gc_info(&info);
mp_printf(&mp_plat_print, "GC: total: %u, used: %u, free: %u\n",
(uint)info.total, (uint)info.used, (uint)info.free);
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u\n",
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block);
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n",
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free);
}
void gc_dump_alloc_table(void) {
......
......@@ -54,6 +54,7 @@ typedef struct _gc_info_t {
size_t total;
size_t used;
size_t free;
size_t max_free;
size_t num_1block;
size_t num_2block;
size_t max_block;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment