From a7cbd5008e830224e73e2e55f89d0783ded422e5 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Tue, 4 May 2010 12:31:24 +0000 Subject: merging revisions 28564-28569 from render branch into trunk --- intern/guardedalloc/MEM_guardedalloc.h | 6 ++++++ intern/guardedalloc/intern/mallocn.c | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'intern/guardedalloc') diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 705f099ab63..c51e96f04b5 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -144,6 +144,12 @@ extern "C" { uintptr_t MEM_get_mapped_memory_in_use(void); int MEM_get_memory_blocks_in_use(void); + /*reset the peak memory statistic to zero*/ + void MEM_reset_peak_memory(void); + + /*get the peak memory usage in bytes, including mmap allocations*/ + uintptr_t MEM_get_peak_memory(void); + #ifdef __cplusplus } #endif diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index 9f2f57e119c..09f2d33a674 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -138,7 +138,7 @@ static const char *check_memlist(MemHead *memh); static volatile int totblock= 0; -static volatile uintptr_t mem_in_use= 0, mmap_in_use= 0; +static volatile uintptr_t mem_in_use= 0, mmap_in_use= 0, peak_mem = 0; static volatile struct localListBase _membase; static volatile struct localListBase *membase = &_membase; @@ -293,6 +293,8 @@ static void make_memhead_header(MemHead *memh, size_t len, const char *str) totblock++; mem_in_use += len; + + peak_mem = mem_in_use > peak_mem ? mem_in_use : peak_mem; } void *MEM_mallocN(size_t len, const char *str) @@ -377,6 +379,7 @@ void *MEM_mapallocN(size_t len, const char *str) make_memhead_header(memh, len, str); memh->mmap= 1; mmap_in_use += len; + peak_mem = mmap_in_use > peak_mem ? mmap_in_use : peak_mem; mem_unlock_thread(); #ifdef DEBUG_MEMCOUNTER if(_mallocn_count==DEBUG_MEMCOUNTER_ERROR_VAL) @@ -802,6 +805,24 @@ static const char *check_memlist(MemHead *memh) return(name); } +uintptr_t MEM_get_peak_memory(void) +{ + uintptr_t _peak_mem; + + mem_lock_thread(); + _peak_mem = peak_mem; + mem_unlock_thread(); + + return _peak_mem; +} + +void MEM_reset_peak_memory(void) +{ + mem_lock_thread(); + peak_mem = 0; + mem_unlock_thread(); +} + uintptr_t MEM_get_memory_in_use(void) { uintptr_t _mem_in_use; -- cgit v1.2.3