From 09b9d71f9241f0ed9c1f43c2176f9acbb626c8c5 Mon Sep 17 00:00:00 2001 From: "wtc%google.com" Date: Sun, 10 Feb 2013 18:34:43 +0000 Subject: [PATCH] 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 . r=wtc. Modified Files: plarena.c plarenas.h plds.def git-svn-id: svn://10.0.0.236/trunk@264710 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/lib/ds/plarena.c | 16 ++++++++++++++++ mozilla/nsprpub/lib/ds/plarenas.h | 13 +++++++++++++ mozilla/nsprpub/lib/ds/plds.def | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/mozilla/nsprpub/lib/ds/plarena.c b/mozilla/nsprpub/lib/ds/plarena.c index 5b1e53af1f9..cc2ffb00a89 100644 --- a/mozilla/nsprpub/lib/ds/plarena.c +++ b/mozilla/nsprpub/lib/ds/plarena.c @@ -345,6 +345,22 @@ PR_IMPLEMENT(void) PL_ArenaFinish(void) 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) { diff --git a/mozilla/nsprpub/lib/ds/plarenas.h b/mozilla/nsprpub/lib/ds/plarenas.h index b4705624318..4cbe32c4c39 100644 --- a/mozilla/nsprpub/lib/ds/plarenas.h +++ b/mozilla/nsprpub/lib/ds/plarenas.h @@ -60,6 +60,19 @@ PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark); */ 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 */ diff --git a/mozilla/nsprpub/lib/ds/plds.def b/mozilla/nsprpub/lib/ds/plds.def index 5c672abb344..cc54a4de2e7 100644 --- a/mozilla/nsprpub/lib/ds/plds.def +++ b/mozilla/nsprpub/lib/ds/plds.def @@ -54,3 +54,7 @@ PL_HashTableRawLookupConst; ;+ global: PL_ClearArenaPool; ;+} NSPR_4.1; +;+NSPR_4.9.6 { +;+ global: +PL_SizeOfArenaPoolExcludingPool; +;+} NSPR_4.8.5;