Bug 675624: Enumerate style sets in about:memory. r=bz
authorKyle Huey <khuey@kylehuey.com>
Mon, 01 Aug 2011 14:24:38 -0400
changeset 73727 26a5993c1193bfc2e465114d8b59eb6536117026
parent 73659 345ba237404d2ae78f4a4629799f9fc47a65ee2c
child 73728 94aa13f4a1a6a63e95640a7551be992b59d80457
push id939
push usermak77@bonardo.net
push dateWed, 03 Aug 2011 08:50:01 +0000
treeherdermozilla-inbound@1d1c771a3aba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs675624
milestone8.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 675624: Enumerate style sets in about:memory. r=bz
dom/base/nsDOMClassInfo.cpp
layout/base/nsPresShell.cpp
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -193,17 +193,16 @@
 // XBL related includes.
 #include "nsIXBLService.h"
 #include "nsXBLBinding.h"
 #include "nsBindingManager.h"
 #include "nsIFrame.h"
 #include "nsIPresShell.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMCSSStyleDeclaration.h"
-#include "nsStyleSet.h"
 #include "nsStyleContext.h"
 #include "nsAutoPtr.h"
 #include "nsMemory.h"
 
 // Tranformiix
 #include "nsIDOMXPathEvaluator.h"
 #include "nsIXSLTProcessor.h"
 #include "nsIXSLTProcessorPrivate.h"
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1427,29 +1427,41 @@ public:
   {
     PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
     PRUint32 *val = (PRUint32*)userArg;
     *val += aShell->EstimateMemoryUsed();
     *val += aShell->mPresContext->EstimateMemoryUsed();
     return PL_DHASH_NEXT;
   }
 
+  static PLDHashOperator StyleSizeEnumerator(PresShellPtrKey *aEntry,
+                                             void *userArg)
+  {
+    PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
+    PRUint32 *val = (PRUint32*)userArg;
+    *val += aShell->StyleSet()->SizeOf();
+    return PL_DHASH_NEXT;
+  }
+
   static PRUint32
   EstimateShellsMemory(nsTHashtable<PresShellPtrKey>::Enumerator aEnumerator)
   {
     PRUint32 result = 0;
     sLiveShells->EnumerateEntries(aEnumerator, &result);
     return result;
   }
-                  
-                                  
+
   static PRInt64 SizeOfLayoutMemoryReporter() {
     return EstimateShellsMemory(LiveShellSizeEnumerator);
   }
 
+  static PRInt64 SizeOfStyleMemoryReporter() {
+    return EstimateShellsMemory(StyleSizeEnumerator);
+  }
+
 protected:
   void QueryIsActive();
   nsresult UpdateImageLockingState();
 };
 
 class nsAutoCauseReflowNotifier
 {
 public:
@@ -1649,22 +1661,29 @@ NS_NewPresShell(nsIPresShell** aInstance
   NS_ADDREF(*aInstancePtrResult);
   return NS_OK;
 }
 
 nsTHashtable<PresShell::PresShellPtrKey> *nsIPresShell::sLiveShells = 0;
 static PRBool sSynthMouseMove = PR_TRUE;
 
 NS_MEMORY_REPORTER_IMPLEMENT(LayoutPresShell,
-    "explicit/layout/all",
+    "explicit/layout/arenas",
     KIND_HEAP,
     UNITS_BYTES,
     PresShell::SizeOfLayoutMemoryReporter,
     "Memory used by layout PresShell, PresContext, and other related areas.")
 
+NS_MEMORY_REPORTER_IMPLEMENT(LayoutStyle,
+    "explicit/layout/styledata",
+    KIND_HEAP,
+    UNITS_BYTES,
+    PresShell::SizeOfStyleMemoryReporter,
+    "Memory used by the style system.")
+
 PresShell::PresShell()
   : mMouseLocation(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)
 {
   mSelection = nsnull;
 #ifdef MOZ_REFLOW_PERF
   mReflowCountMgr = new ReflowCountMgr();
   mReflowCountMgr->SetPresContext(mPresContext);
   mReflowCountMgr->SetPresShell(this);
@@ -1683,16 +1702,17 @@ PresShell::PresShell()
   mRenderFlags = 0;
   mXResolution = 1.0;
   mYResolution = 1.0;
   mViewportOverridden = PR_FALSE;
 
   static bool registeredReporter = false;
   if (!registeredReporter) {
     NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutPresShell));
+    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutStyle));
     Preferences::AddBoolVarCache(&sSynthMouseMove,
                                  "layout.reflow.synthMouseMove", PR_TRUE);
     registeredReporter = true;
   }
 
   new (this) nsFrameManager();
 
   sLiveShells->PutEntry(this);
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -93,16 +93,22 @@ nsStyleSet::nsStyleSet()
     mBatching(0),
     mInShutdown(PR_FALSE),
     mAuthorStyleDisabled(PR_FALSE),
     mInReconstruct(PR_FALSE),
     mDirty(0)
 {
 }
 
+size_t
+nsStyleSet::SizeOf() const
+{
+  return sizeof(*this);
+}
+
 nsresult
 nsStyleSet::Init(nsPresContext *aPresContext)
 {
   mFirstLineRule = new nsEmptyStyleRule;
   mFirstLetterRule = new nsEmptyStyleRule;
   if (!mFirstLineRule || !mFirstLetterRule) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -78,16 +78,18 @@ class nsEmptyStyleRule : public nsIStyle
 // then handed off to the PresShell.  Only the PresShell should delete a
 // style set.
 
 class nsStyleSet
 {
  public:
   nsStyleSet();
 
+  size_t SizeOf() const;
+
   // Initialize the object.  You must check the return code and not use
   // the nsStyleSet if Init() fails.
 
   nsresult Init(nsPresContext *aPresContext);
 
   // For getting the cached default data in case we hit out-of-memory.
   // To be used only by nsRuleNode.
   nsCachedStyleData* DefaultStyleData() { return &mDefaultStyleData; }