Merge pull request #574 from openmv/fb_alloc_stats

Add FB alloc stats.
This commit is contained in:
Ibrahim Abd Elkader 2019-08-30 17:15:17 +02:00 committed by GitHub
commit 70c00c7c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -75,6 +75,11 @@ ifeq ($(STACK_PROTECTOR), 1)
CFLAGS += -fstack-protector-all -DSTACK_PROTECTOR CFLAGS += -fstack-protector-all -DSTACK_PROTECTOR
endif endif
# Enable debug printf
ifeq ($(FB_ALLOC_STATS), 1)
CFLAGS += -DFB_ALLOC_STATS
endif
# Compiler Flags # Compiler Flags
include $(OMV_BOARD_CONFIG_DIR)/omv_boardconfig.mk include $(OMV_BOARD_CONFIG_DIR)/omv_boardconfig.mk
CFLAGS += -std=gnu99 -Wall -Werror -Warray-bounds -mthumb -nostartfiles -fdata-sections -ffunction-sections CFLAGS += -std=gnu99 -Wall -Werror -Warray-bounds -mthumb -nostartfiles -fdata-sections -ffunction-sections

View File

@ -13,6 +13,9 @@
extern char _fballoc; extern char _fballoc;
static char *pointer = &_fballoc; static char *pointer = &_fballoc;
static int marks = 0; static int marks = 0;
#if defined(FB_ALLOC_STATS)
static uint32_t alloc_bytes;
#endif
__weak NORETURN void fb_alloc_fail() __weak NORETURN void fb_alloc_fail()
{ {
@ -51,6 +54,9 @@ void fb_alloc_mark()
*((uint32_t *) new_pointer) = sizeof(uint32_t); // Save size. *((uint32_t *) new_pointer) = sizeof(uint32_t); // Save size.
pointer = new_pointer; pointer = new_pointer;
marks += 1; marks += 1;
#if defined(FB_ALLOC_STATS)
alloc_bytes = 0;
#endif
} }
void fb_alloc_free_till_mark() void fb_alloc_free_till_mark()
@ -62,6 +68,9 @@ void fb_alloc_free_till_mark()
if (size == sizeof(uint32_t)) break; // Break on first marker. if (size == sizeof(uint32_t)) break; // Break on first marker.
} }
marks -= 1; marks -= 1;
#if defined(FB_ALLOC_STATS)
printf("Total allocated FB memory: %lu bytes\n", alloc_bytes);
#endif
} }
// returns null pointer without error if size==0 // returns null pointer without error if size==0
@ -83,6 +92,10 @@ void *fb_alloc(uint32_t size)
// size is always 4/8/12/etc. so the value below must be 8 or more. // size is always 4/8/12/etc. so the value below must be 8 or more.
*((uint32_t *) new_pointer) = size + sizeof(uint32_t); // Save size. *((uint32_t *) new_pointer) = size + sizeof(uint32_t); // Save size.
pointer = new_pointer; pointer = new_pointer;
#if defined(FB_ALLOC_STATS)
alloc_bytes += size;
printf("fb_alloc %lu bytes\n", size);
#endif
return result; return result;
} }
@ -110,6 +123,10 @@ void *fb_alloc_all(uint32_t *size)
// size is always 4/8/12/etc. so the value below must be 8 or more. // size is always 4/8/12/etc. so the value below must be 8 or more.
*((uint32_t *) new_pointer) = *size + sizeof(uint32_t); // Save size. *((uint32_t *) new_pointer) = *size + sizeof(uint32_t); // Save size.
pointer = new_pointer; pointer = new_pointer;
#if defined(FB_ALLOC_STATS)
alloc_bytes += *size;
printf("fb_alloc_all %lu bytes\n", *size);
#endif
return result; return result;
} }