From c04bb40595d2c98d324db6585a6cd9e6f59aa213 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 30 Aug 2019 17:06:15 +0200 Subject: [PATCH] Add FB alloc stats. --- src/Makefile | 5 +++++ src/omv/fb_alloc.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Makefile b/src/Makefile index 3ee696d70..1df5ec5fc 100755 --- a/src/Makefile +++ b/src/Makefile @@ -75,6 +75,11 @@ ifeq ($(STACK_PROTECTOR), 1) CFLAGS += -fstack-protector-all -DSTACK_PROTECTOR endif +# Enable debug printf +ifeq ($(FB_ALLOC_STATS), 1) +CFLAGS += -DFB_ALLOC_STATS +endif + # Compiler Flags include $(OMV_BOARD_CONFIG_DIR)/omv_boardconfig.mk CFLAGS += -std=gnu99 -Wall -Werror -Warray-bounds -mthumb -nostartfiles -fdata-sections -ffunction-sections diff --git a/src/omv/fb_alloc.c b/src/omv/fb_alloc.c index a289965fc..d07761d6d 100644 --- a/src/omv/fb_alloc.c +++ b/src/omv/fb_alloc.c @@ -13,6 +13,9 @@ extern char _fballoc; static char *pointer = &_fballoc; static int marks = 0; +#if defined(FB_ALLOC_STATS) +static uint32_t alloc_bytes; +#endif __weak NORETURN void fb_alloc_fail() { @@ -51,6 +54,9 @@ void fb_alloc_mark() *((uint32_t *) new_pointer) = sizeof(uint32_t); // Save size. pointer = new_pointer; marks += 1; + #if defined(FB_ALLOC_STATS) + alloc_bytes = 0; + #endif } 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. } 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 @@ -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. *((uint32_t *) new_pointer) = size + sizeof(uint32_t); // Save size. pointer = new_pointer; + #if defined(FB_ALLOC_STATS) + alloc_bytes += size; + printf("fb_alloc %lu bytes\n", size); + #endif 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. *((uint32_t *) new_pointer) = *size + sizeof(uint32_t); // Save size. pointer = new_pointer; + #if defined(FB_ALLOC_STATS) + alloc_bytes += *size; + printf("fb_alloc_all %lu bytes\n", *size); + #endif return result; }