diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-06-30 01:59:24 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-06-30 12:56:21 +0300 |
commit | 6a6e0b7e05c430239c67efb702c44359e044c25d (patch) | |
tree | cc6a0326865f58d9881a529525d43768bb84b788 /py/gc.c | |
parent | 69074960168970979769fa227dfd928189eaf062 (diff) | |
download | micropython-6a6e0b7e05c430239c67efb702c44359e044c25d.tar.gz micropython-6a6e0b7e05c430239c67efb702c44359e044c25d.zip |
py/gc: Be sure to count last allocated block at heap end in stats.
Previously, if there was chain of allocated blocks ending with the last
block of heap, it wasn't included in number of 1/2-block or max block
size stats.
Diffstat (limited to 'py/gc.c')
-rw-r--r-- | py/gc.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -327,18 +327,9 @@ void gc_info(gc_info_t *info) { info->num_1block = 0; info->num_2block = 0; info->max_block = 0; - for (size_t block = 0, len = 0; block < MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB; block++) { + bool finish = false; + for (size_t block = 0, len = 0; !finish;) { size_t kind = ATB_GET_KIND(block); - if (kind == AT_FREE || kind == AT_HEAD) { - if (len == 1) { - info->num_1block += 1; - } else if (len == 2) { - info->num_2block += 1; - } - if (len > info->max_block) { - info->max_block = len; - } - } switch (kind) { case AT_FREE: info->free += 1; @@ -359,6 +350,24 @@ void gc_info(gc_info_t *info) { // shouldn't happen break; } + + block++; + finish = (block == MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB); + // Get next block type if possible + if (!finish) { + kind = ATB_GET_KIND(block); + } + + if (finish || kind == AT_FREE || kind == AT_HEAD) { + if (len == 1) { + info->num_1block += 1; + } else if (len == 2) { + info->num_2block += 1; + } + if (len > info->max_block) { + info->max_block = len; + } + } } info->used *= BYTES_PER_BLOCK; |