py/gc: Add "max new split" value in result of gc.mem_free().
Follow-up to 519c24dd48
when MICROPY_GC_SPLIT_HEAP_AUTO is enabled, based
on discussion at
https://github.com/orgs/micropython/discussions/12316#discussioncomment-6858007
gc.mem_free() is always a heuristic, but this makes it a more useful
heuristic for common use cases.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
parent
174bb28d8e
commit
3e8aed9fcc
7
py/gc.c
7
py/gc.c
@ -701,6 +701,11 @@ void gc_info(gc_info_t *info) {
|
|||||||
|
|
||||||
info->used *= BYTES_PER_BLOCK;
|
info->used *= BYTES_PER_BLOCK;
|
||||||
info->free *= BYTES_PER_BLOCK;
|
info->free *= BYTES_PER_BLOCK;
|
||||||
|
|
||||||
|
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
||||||
|
info->max_new_split = gc_get_max_new_split();
|
||||||
|
#endif
|
||||||
|
|
||||||
GC_EXIT();
|
GC_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,7 +1164,7 @@ void gc_dump_info(const mp_print_t *print) {
|
|||||||
mp_printf(print, "GC: total: %u, used: %u, free: %u",
|
mp_printf(print, "GC: total: %u, used: %u, free: %u",
|
||||||
(uint)info.total, (uint)info.used, (uint)info.free);
|
(uint)info.total, (uint)info.used, (uint)info.free);
|
||||||
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
||||||
mp_printf(print, ", max new split: %u", (uint)gc_get_max_new_split());
|
mp_printf(print, ", max new split: %u", (uint)info.max_new_split);
|
||||||
#endif
|
#endif
|
||||||
mp_printf(print, "\n No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n",
|
mp_printf(print, "\n 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);
|
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free);
|
||||||
|
3
py/gc.h
3
py/gc.h
@ -75,6 +75,9 @@ typedef struct _gc_info_t {
|
|||||||
size_t num_1block;
|
size_t num_1block;
|
||||||
size_t num_2block;
|
size_t num_2block;
|
||||||
size_t max_block;
|
size_t max_block;
|
||||||
|
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
||||||
|
size_t max_new_split;
|
||||||
|
#endif
|
||||||
} gc_info_t;
|
} gc_info_t;
|
||||||
|
|
||||||
void gc_info(gc_info_t *info);
|
void gc_info(gc_info_t *info);
|
||||||
|
@ -64,7 +64,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
|
|||||||
STATIC mp_obj_t gc_mem_free(void) {
|
STATIC mp_obj_t gc_mem_free(void) {
|
||||||
gc_info_t info;
|
gc_info_t info;
|
||||||
gc_info(&info);
|
gc_info(&info);
|
||||||
|
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
||||||
|
// Include max_new_split value here as a more useful heuristic
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(info.free + info.max_new_split);
|
||||||
|
#else
|
||||||
return MP_OBJ_NEW_SMALL_INT(info.free);
|
return MP_OBJ_NEW_SMALL_INT(info.free);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
|
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user