From 58316a84d3b8a8bb5fa7fa42d6ac4ceb0b461b9a Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 17 Jun 2011 09:22:15 -0700 Subject: [PATCH] Bug 664913: Add about:memory reporter for xptiWorkingSet. r=njn --- xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp | 17 ++++++++++++++++- xpcom/typelib/xpt/public/xpt_arena.h | 3 +++ xpcom/typelib/xpt/src/xpt_arena.c | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp b/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp index 7b2e4bd7101f..c27bc06ed6a3 100644 --- a/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp +++ b/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp @@ -41,9 +41,22 @@ #include "xptiprivate.h" #include "nsString.h" +#include "nsIMemoryReporter.h" using namespace mozilla; +static PRInt64 GetXPTArenaSize(void*) +{ + return XPT_SizeOfArena(gXPTIStructArena); +} + +NS_MEMORY_REPORTER_IMPLEMENT(xptiWorkingSet, + "explicit/xpti-working-set", + MR_HEAP, + "Memory used by the XPCOM typelib system.", + GetXPTArenaSize, + nsnull) + #define XPTI_STRUCT_ARENA_BLOCK_SIZE (1024 * 1) #define XPTI_HASHTABLE_SIZE 2048 @@ -57,6 +70,8 @@ xptiWorkingSet::xptiWorkingSet() gXPTIStructArena = XPT_NewArena(XPTI_STRUCT_ARENA_BLOCK_SIZE, sizeof(double), "xptiWorkingSet structs"); + + NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(xptiWorkingSet)); } static PLDHashOperator @@ -82,6 +97,6 @@ xptiWorkingSet::~xptiWorkingSet() #ifdef NS_FREE_PERMANENT_DATA XPT_DestroyArena(gXPTIStructArena); #endif -} +} XPTArena* gXPTIStructArena; diff --git a/xpcom/typelib/xpt/public/xpt_arena.h b/xpcom/typelib/xpt/public/xpt_arena.h index 2872f84f800f..7a4a8deebdb7 100644 --- a/xpcom/typelib/xpt/public/xpt_arena.h +++ b/xpcom/typelib/xpt/public/xpt_arena.h @@ -82,6 +82,9 @@ XPT_NotifyDoneLoading(XPTArena *arena); XPT_PUBLIC_API(void) XPT_ArenaFree(XPTArena *arena, void* block); +XPT_PUBLIC_API(size_t) +XPT_SizeOfArena(XPTArena *arena); + /* --------------------------------------------------------- */ #define XPT_MALLOC(_arena, _bytes) \ diff --git a/xpcom/typelib/xpt/src/xpt_arena.c b/xpcom/typelib/xpt/src/xpt_arena.c index 738b647e4d52..9b1da6a03aa4 100644 --- a/xpcom/typelib/xpt/src/xpt_arena.c +++ b/xpcom/typelib/xpt/src/xpt_arena.c @@ -336,3 +336,21 @@ XPT_AssertFailed(const char *s, const char *file, PRUint32 lineno) abort(); } #endif + +XPT_PUBLIC_API(size_t) +XPT_SizeOfArena(XPTArena *arena) +{ + size_t n = sizeof(XPTArena); + + BLK_HDR* cur; + BLK_HDR* next; + + cur = arena->first; + while (cur) { + next = cur->next; + n += cur->size; + cur = next; + } + + return n; +}