summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-30 01:59:24 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-30 12:56:21 +0300
commit6a6e0b7e05c430239c67efb702c44359e044c25d (patch)
treecc6a0326865f58d9881a529525d43768bb84b788
parent69074960168970979769fa227dfd928189eaf062 (diff)
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.
-rw-r--r--py/gc.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/py/gc.c b/py/gc.c
index 1fd320602..2cc64f362 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -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;