Bug 807883: Add the PL_SizeOfArenaPoolExcludingPool function to measure all
authorwtc%google.com
Sun, 10 Feb 2013 18:34:43 +0000
changeset 4436 22d76c1a141fdc0a0defb21d94cc5d407617fcac
parent 4435 2a173d37ec987dad81bf7723d14d20e76bf3228d
child 4437 7e7d5e18015b48c42ae1780d3f47f64254f46a68
push idunknown
push userunknown
push dateunknown
bugs807883
Bug 807883: Add the PL_SizeOfArenaPoolExcludingPool function to measure all memory used by a PLArenaPool, excluding the PLArenaPool structure. The patch is contributed by Nicholas Nethercote <nnethercote@mozilla.com>. r=wtc. Modified Files: plarena.c plarenas.h plds.def
lib/ds/plarena.c
lib/ds/plarenas.h
lib/ds/plds.def
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -340,16 +340,32 @@ PR_IMPLEMENT(void) PL_ArenaFinish(void)
 
     if (arenaLock) {
         PR_DestroyLock(arenaLock);
         arenaLock = NULL;
     }
     once = pristineCallOnce;
 }
 
+PR_IMPLEMENT(size_t) PL_SizeOfArenaPoolExcludingPool(
+    PLArenaPool *pool, PLMallocSizeFn mallocSizeOf)
+{
+    /*
+     * The first PLArena is within |pool|, so don't measure it.  Subsequent
+     * PLArenas are separate and must measured.
+     */
+    size_t size = 0;
+    PLArena *arena = pool->first.next;
+    while (arena) {
+        size += mallocSizeOf(arena);
+        arena = arena->next;
+    }
+    return size;
+}
+
 #ifdef PL_ARENAMETER
 PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
 {
     pool->stats.nallocs++;
     pool->stats.nbytes += nb;
     if (nb > pool->stats.maxalloc)
         pool->stats.maxalloc = nb;
     pool->stats.variance += nb * nb;
--- a/lib/ds/plarenas.h
+++ b/lib/ds/plarenas.h
@@ -55,11 +55,24 @@ PR_EXTERN(void *) PL_ArenaGrow(
 
 PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
 
 /*
 ** memset contents of all arenas in pool to pattern
 */
 PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
 
+/*
+** A function like malloc_size() or malloc_usable_size() that returns the
+** size of a heap block.
+*/
+typedef size_t (*PLMallocSizeFn)(const void *ptr);
+
+/*
+** Return all memory used by a PLArenaPool, excluding the PLArenaPool
+** structure.
+*/
+PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool(
+    PLArenaPool *pool, PLMallocSizeFn mallocSizeOf);
+
 PR_END_EXTERN_C
 
 #endif /* PLARENAS_H */
--- a/lib/ds/plds.def
+++ b/lib/ds/plds.def
@@ -49,8 +49,12 @@ libVersionPoint;
 PL_HashTableLookupConst;
 PL_HashTableRawLookupConst;
 ;+} NSPR_4.0;
 ;+
 ;+NSPR_4.8.5 {
 ;+    global:
 PL_ClearArenaPool;
 ;+} NSPR_4.1;
+;+NSPR_4.9.6 {
+;+    global:
+PL_SizeOfArenaPoolExcludingPool;
+;+} NSPR_4.8.5;