From d1d6a132974db8b5dd19c6ee9a4d0af487e1491a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 28 Aug 2013 10:17:26 +0000 Subject: include slop-space in debug statistics (gcc/clang only) --- intern/guardedalloc/intern/mallocn.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'intern/guardedalloc') diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index 0af16e58f0a..27b85f41a88 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -48,6 +48,11 @@ # define __func__ __FUNCTION__ #endif +/* only for utility functions */ +#if defined(__GNUC__) +#include +#endif + #include "MEM_guardedalloc.h" /* should always be defined except for experimental cases */ @@ -620,7 +625,9 @@ void MEM_printmemlist_stats(void) MemHead *membl; MemPrintBlock *pb, *printblock; int totpb, a, b; - +#ifdef __GNUC__ + size_t mem_in_use_slop; +#endif mem_lock_thread(); /* put memory blocks into array */ @@ -640,6 +647,11 @@ void MEM_printmemlist_stats(void) totpb++; pb++; +#ifdef __GNUC__ + mem_in_use_slop += (sizeof(MemHead) + sizeof(MemTail) + + malloc_usable_size((void *)membl)) - membl->len; +#endif + if (membl->next) membl = MEMNEXT(membl->next); else break; @@ -668,6 +680,10 @@ void MEM_printmemlist_stats(void) (double)mem_in_use / (double)(1024 * 1024)); printf("peak memory len: %.3f MB\n", (double)peak_mem / (double)(1024 * 1024)); +#ifdef __GNUC__ + printf("slop memory len: %.3f MB\n", + (double)mem_in_use_slop / (double)(1024 * 1024)); +#endif printf(" ITEMS TOTAL-MiB AVERAGE-KiB TYPE\n"); for (a = 0, pb = printblock; a < totpb; a++, pb++) { printf("%6d (%8.3f %8.3f) %s\n", -- cgit v1.2.3