[xiph-commits] r13403 - experimental/moritz/xalloc
moritz at svn.xiph.org
moritz at svn.xiph.org
Mon Jul 30 08:29:27 PDT 2007
Author: moritz
Date: 2007-07-30 08:29:26 -0700 (Mon, 30 Jul 2007)
New Revision: 13403
Modified:
experimental/moritz/xalloc/xalloc.c
Log:
Improve stats.
Modified: experimental/moritz/xalloc/xalloc.c
===================================================================
--- experimental/moritz/xalloc/xalloc.c 2007-07-30 15:29:06 UTC (rev 13402)
+++ experimental/moritz/xalloc/xalloc.c 2007-07-30 15:29:26 UTC (rev 13403)
@@ -104,6 +104,7 @@
static FILE *debug_output = NULL;
static int xalloc_initialized = 0;
static size_t xalloc_allocated;
+static size_t xalloc_total;
static size_t xalloc_peak;
static size_t xalloc_freed;
static void * (*real_malloc)(size_t) = NULL;
@@ -319,6 +320,7 @@
real_calloc = calloc;
real_realloc = realloc;
xalloc_allocated = 0;
+ xalloc_total = 0;
xalloc_peak = 0;
xalloc_freed = 0;
@@ -410,10 +412,11 @@
(unsigned long)leaked_bytes,
(unsigned long)xalloc_allocated);
- _xalloc_debug_printf(1, "XALLOC: STATS: leaked: %lu bytes, peak allocation: %lu bytes (freed: %lu bytes)\n",
+ _xalloc_debug_printf(1, "XALLOC: STATS: leaked: %lu bytes, peak allocation: %lu bytes (freed/total: %lu/%lu bytes)\n",
(unsigned long)xalloc_allocated,
(unsigned long)xalloc_peak,
- (unsigned long)xalloc_freed);
+ (unsigned long)xalloc_freed,
+ (unsigned long)xalloc_total);
XALLOC_UNLOCK(xalloc_mutex);
}
@@ -461,6 +464,7 @@
XALLOC_LOCK(xalloc_mutex);
RB_INSERT(memory_tree, &memory_tree_head, mem);
xalloc_allocated += size;
+ xalloc_total += size;
if (xalloc_allocated > xalloc_peak)
xalloc_peak = xalloc_allocated;
XALLOC_UNLOCK(xalloc_mutex);
@@ -505,6 +509,7 @@
XALLOC_LOCK(xalloc_mutex);
RB_INSERT(memory_tree, &memory_tree_head, mem);
xalloc_allocated += nmemb * size;
+ xalloc_total += nmemb * size;
if (xalloc_allocated > xalloc_peak)
xalloc_peak = xalloc_allocated;
XALLOC_UNLOCK(xalloc_mutex);
@@ -582,9 +587,14 @@
#ifdef XALLOC_DEBUG
if (debug_level > 0) {
+ ssize_t diff = nsiz - mem->size;
+
XALLOC_LOCK(xalloc_mutex);
- xalloc_allocated -= mem->size;
- xalloc_allocated += nsiz;
+ xalloc_allocated += diff;
+ if (diff < 0)
+ xalloc_freed += -diff;
+ else
+ xalloc_total += diff;
if (xalloc_allocated > xalloc_peak)
xalloc_peak = xalloc_allocated;
mem->size = nsiz;
@@ -708,6 +718,7 @@
XALLOC_LOCK(xalloc_mutex);
RB_INSERT(memory_tree, &memory_tree_head, mem);
xalloc_allocated += strsiz;
+ xalloc_total += strsiz;
if (xalloc_allocated > xalloc_peak)
xalloc_peak = xalloc_allocated;
XALLOC_UNLOCK(xalloc_mutex);
More information about the commits
mailing list