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.
This commit is contained in:
Paul Sokolovsky 2016-06-30 01:59:24 +03:00
parent 6907496016
commit 6a6e0b7e05
1 changed files with 20 additions and 11 deletions

31
py/gc.c
View File

@ -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;