Bug 765344 - xpti-working-set numbers should include xptiWorkingSet's hashtables; r=njn,jlebar
authorNathan Froyd <froydnj@mozilla.com>
Mon, 18 Jun 2012 20:10:08 -0400
changeset 101781 657f9a63368b976b1852d3e6a1e846eb13adea51
parent 101780 46665ca7257196e8c1364e210d09cfa9d485907b
child 101782 df8f2986f750fc98e1ca72cfa2a5811cfb4a83d1
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn, jlebar
bugs765344
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 765344 - xpti-working-set numbers should include xptiWorkingSet's hashtables; r=njn,jlebar
xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp
xpcom/reflect/xptinfo/src/xptiprivate.h
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
@@ -8,28 +8,64 @@
 #include "xptiprivate.h"
 #include "nsDependentString.h"
 #include "nsString.h"
 #include "nsISupportsArray.h"
 #include "nsArrayEnumerator.h"
 #include "mozilla/FunctionTimer.h"
 #include "nsDirectoryService.h"
 #include "mozilla/FileUtils.h"
+#include "nsIMemoryReporter.h"
 
 using namespace mozilla;
 
 NS_IMPL_THREADSAFE_ISUPPORTS2(xptiInterfaceInfoManager, 
                               nsIInterfaceInfoManager,
                               nsIInterfaceInfoSuperManager)
 
 static xptiInterfaceInfoManager* gInterfaceInfoManager = nsnull;
 #ifdef DEBUG
 static int gCallCount = 0;
 #endif
 
+
+NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(XPTMallocSizeOf, "xpti-working-set")
+
+size_t
+xptiInterfaceInfoManager::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
+{
+    size_t n = aMallocSizeOf(this);
+    ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
+    // The entries themselves are allocated out of an arena accounted
+    // for elsewhere, so don't measure them
+    n += mWorkingSet.mIIDTable.SizeOfExcludingThis(NULL, XPTMallocSizeOf);
+    n += mWorkingSet.mNameTable.SizeOfExcludingThis(NULL, XPTMallocSizeOf);
+    return n;
+}
+
+// static
+PRInt64
+xptiInterfaceInfoManager::GetXPTIWorkingSetSize()
+{
+    size_t n = XPT_SizeOfArena(gXPTIStructArena, XPTMallocSizeOf);
+
+    if (gInterfaceInfoManager) {
+        n += gInterfaceInfoManager->SizeOfIncludingThis(XPTMallocSizeOf);
+    }
+
+    return n;
+}
+
+NS_MEMORY_REPORTER_IMPLEMENT(xptiWorkingSet,
+                             "explicit/xpti-working-set",
+                             KIND_HEAP,
+                             UNITS_BYTES,
+                             xptiInterfaceInfoManager::GetXPTIWorkingSetSize,
+                             "Memory used by the XPCOM typelib system.")
+
 // static
 xptiInterfaceInfoManager*
 xptiInterfaceInfoManager::GetSingleton()
 {
     if (!gInterfaceInfoManager) {
         NS_TIME_FUNCTION;
 
         gInterfaceInfoManager = new xptiInterfaceInfoManager();
@@ -45,16 +81,17 @@ xptiInterfaceInfoManager::FreeInterfaceI
 }
 
 xptiInterfaceInfoManager::xptiInterfaceInfoManager()
     :   mWorkingSet(),
         mResolveLock("xptiInterfaceInfoManager.mResolveLock"),
         mAdditionalManagersLock(
             "xptiInterfaceInfoManager.mAdditionalManagersLock")
 {
+    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(xptiWorkingSet));
 }
 
 xptiInterfaceInfoManager::~xptiInterfaceInfoManager()
 {
     // We only do this on shutdown of the service.
     mWorkingSet.InvalidateInterfaceInfos();
 
     gInterfaceInfoManager = nsnull;
--- a/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp
@@ -2,49 +2,32 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implementation of xptiWorkingSet. */
 
 #include "xptiprivate.h"
 #include "nsString.h"
-#include "nsIMemoryReporter.h"
 
 using namespace mozilla;
 
-NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(XPTMallocSizeOf, "xpti-working-set")
-
-static PRInt64 GetXPTArenaSize()
-{
-  return XPT_SizeOfArena(gXPTIStructArena, XPTMallocSizeOf);
-}
-
-NS_MEMORY_REPORTER_IMPLEMENT(xptiWorkingSet,
-                             "explicit/xpti-working-set",
-                             KIND_HEAP,
-                             UNITS_BYTES,
-                             GetXPTArenaSize,
-                             "Memory used by the XPCOM typelib system.")
-
 #define XPTI_STRUCT_ARENA_BLOCK_SIZE    (1024 * 1)
 #define XPTI_HASHTABLE_SIZE             2048
 
 xptiWorkingSet::xptiWorkingSet()
     : mTableReentrantMonitor("xptiWorkingSet::mTableReentrantMonitor")
 {
     MOZ_COUNT_CTOR(xptiWorkingSet);
 
     mIIDTable.Init(XPTI_HASHTABLE_SIZE);
     mNameTable.Init(XPTI_HASHTABLE_SIZE);
 
     gXPTIStructArena = XPT_NewArena(XPTI_STRUCT_ARENA_BLOCK_SIZE, sizeof(double),
                                     "xptiWorkingSet structs");
-
-    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(xptiWorkingSet));
 }        
 
 static PLDHashOperator
 xpti_Invalidator(const char* keyname, xptiInterfaceEntry* entry, void* arg)
 {
     entry->LockedInvalidateInterfaceInfo();
     return PL_DHASH_NEXT;
 }
--- a/xpcom/reflect/xptinfo/src/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/src/xptiprivate.h
@@ -418,16 +418,20 @@ public:
     static Mutex& GetResolveLock(xptiInterfaceInfoManager* self = nsnull) 
     {
         self = self ? self : GetSingleton();
         return self->mResolveLock;
     }
 
     xptiInterfaceEntry* GetInterfaceEntryForIID(const nsIID *iid);
 
+    size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
+
+    static PRInt64 GetXPTIWorkingSetSize();
+
 private:
     xptiInterfaceInfoManager();
     ~xptiInterfaceInfoManager();
 
     void RegisterXPTHeader(XPTHeader* aHeader);
                           
     // idx is the index of this interface in the XPTHeader
     void VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* iface,