Bug 760831 - split out per-node type stats in about:memory; r=njn, bz
authorNathan Froyd <froydnj@mozilla.com>
Tue, 05 Jun 2012 10:49:48 -0400
changeset 95990 aff9bc34ee04838402d4e645f281c00f71ffceed
parent 95989 088893efefc7a9dd90105f189ffced21a44b8892
child 95991 107f611fb258529209d6ca2eb935d7aaaebd8327
push id22869
push useremorley@mozilla.com
push dateThu, 07 Jun 2012 09:35:19 +0000
treeherdermozilla-central@3933384d8315 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn, bz
bugs760831
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 760831 - split out per-node type stats in about:memory; r=njn, bz
content/base/src/nsDocument.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsWindowMemoryReporter.cpp
dom/base/nsWindowMemoryReporter.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -9653,17 +9653,17 @@ nsDocument::GetMozVisibilityState(nsAStr
   PR_STATIC_ASSERT(NS_ARRAY_LENGTH(states) == eVisibilityStateCount);
   aState.AssignASCII(states[mVisibilityState]);
   return NS_OK;
 }
 
 /* virtual */ void
 nsIDocument::DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const
 {
-  aWindowSizes->mDOM +=
+  aWindowSizes->mDOMOther +=
     nsINode::SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
 
   if (mPresShell) {
     mPresShell->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf,
                                     &aWindowSizes->mLayoutArenas,
                                     &aWindowSizes->mLayoutStyleSets,
                                     &aWindowSizes->mLayoutTextRuns,
                                     &aWindowSizes->mLayoutPresContext);
@@ -9672,17 +9672,17 @@ nsIDocument::DocSizeOfExcludingThis(nsWi
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - many!
 }
 
 void
 nsIDocument::DocSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
 {
-  aWindowSizes->mDOM += aWindowSizes->mMallocSizeOf(this);
+  aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this);
   DocSizeOfExcludingThis(aWindowSizes);
 }
 
 static size_t
 SizeOfStyleSheetsElementIncludingThis(nsIStyleSheet* aStyleSheet,
                                       nsMallocSizeOfFun aMallocSizeOf,
                                       void* aData)
 {
@@ -9704,24 +9704,44 @@ void
 nsDocument::DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const
 {
   nsIDocument::DocSizeOfExcludingThis(aWindowSizes);
 
   for (nsIContent* node = nsINode::GetFirstChild();
        node;
        node = node->GetNextNode(this))
   {
-    aWindowSizes->mDOM +=
-      node->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
+    size_t nodeSize = node->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
+    size_t* p;
+
+    switch (node->NodeType()) {
+    case nsIDOMNode::ELEMENT_NODE:
+      p = &aWindowSizes->mDOMElementNodes;
+      break;
+    case nsIDOMNode::TEXT_NODE:
+      p = &aWindowSizes->mDOMTextNodes;
+      break;
+    case nsIDOMNode::CDATA_SECTION_NODE:
+      p = &aWindowSizes->mDOMCDATANodes;
+      break;
+    case nsIDOMNode::COMMENT_NODE:
+      p = &aWindowSizes->mDOMCommentNodes;
+      break;
+    default:
+      p = &aWindowSizes->mDOMOther;
+      break;
+    }
+
+    *p += nodeSize;
   }
 
   aWindowSizes->mStyleSheets +=
     mStyleSheets.SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis,
                                      aWindowSizes->mMallocSizeOf); 
-  aWindowSizes->mDOM +=
+  aWindowSizes->mDOMOther +=
     mAttrStyleSheet ?
     mAttrStyleSheet->DOMSizeOfIncludingThis(aWindowSizes->mMallocSizeOf) :
     0;
 
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - many!
 }
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -10126,31 +10126,31 @@ bool
 nsGlobalWindow::HasPerformanceSupport() 
 {
   return Preferences::GetBool("dom.enable_performance", false);
 }
 
 void
 nsGlobalWindow::SizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
 {
-  aWindowSizes->mDOM += aWindowSizes->mMallocSizeOf(this);
+  aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this);
 
   if (IsInnerWindow()) {
     nsEventListenerManager* elm =
       const_cast<nsGlobalWindow*>(this)->GetListenerManager(false);
     if (elm) {
-      aWindowSizes->mDOM +=
+      aWindowSizes->mDOMOther +=
         elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
     }
     if (mDoc) {
       mDoc->DocSizeOfIncludingThis(aWindowSizes);
     }
   }
 
-  aWindowSizes->mDOM +=
+  aWindowSizes->mDOMOther +=
     mNavigator ?
       mNavigator->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf) : 0;
 }
 
 void
 nsGlobalWindow::SetIsApp(bool aValue)
 {
   FORWARD_TO_OUTER_VOID(SetIsApp, (aValue));
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -151,19 +151,36 @@ CollectWindowReports(nsGlobalWindow *aWi
                       NS_LITERAL_CSTRING(_desc), aClosure);                   \
         NS_ENSURE_SUCCESS(rv, rv);                                            \
     }                                                                         \
   } while (0)
 
   nsWindowSizes windowSizes(DOMStyleMallocSizeOf);
   aWindow->SizeOfIncludingThis(&windowSizes);
 
-  REPORT("/dom", windowSizes.mDOM,
-         "Memory used by a window and the DOM within it.");
-  aWindowTotalSizes->mDOM += windowSizes.mDOM;
+  REPORT("/dom/other", windowSizes.mDOMOther,
+         "Memory used by a window's DOM, excluding element, text, CDATA, "
+         "and comment nodes.");
+  aWindowTotalSizes->mDOMOther += windowSizes.mDOMOther;
+
+  REPORT("/dom/element-nodes", windowSizes.mDOMElementNodes,
+         "Memory used by the element nodes in a window's DOM.");
+  aWindowTotalSizes->mDOMElementNodes += windowSizes.mDOMElementNodes;
+
+  REPORT("/dom/text-nodes", windowSizes.mDOMTextNodes,
+         "Memory used by the text nodes in a window's DOM.");
+  aWindowTotalSizes->mDOMTextNodes += windowSizes.mDOMTextNodes;
+
+  REPORT("/dom/cdata-nodes", windowSizes.mDOMCDATANodes,
+         "Memory used by the CDATA nodes in a window's DOM.");
+  aWindowTotalSizes->mDOMCDATANodes += windowSizes.mDOMCDATANodes;
+
+  REPORT("/dom/comment-nodes", windowSizes.mDOMCommentNodes,
+         "Memory used by the comment nodes in a window's DOM.");
+  aWindowTotalSizes->mDOMCommentNodes += windowSizes.mDOMCommentNodes;
 
   REPORT("/style-sheets", windowSizes.mStyleSheets,
          "Memory used by style sheets within a window.");
   aWindowTotalSizes->mStyleSheets += windowSizes.mStyleSheets;
 
   REPORT("/layout/arenas", windowSizes.mLayoutArenas,
          "Memory used by layout PresShell, PresContext, and other related "
          "areas within a window.");
@@ -241,20 +258,37 @@ nsWindowMemoryReporter::CollectReports(n
     nsresult rv;                                                              \
     rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path),             \
                        nsIMemoryReporter::KIND_OTHER,                         \
                        nsIMemoryReporter::UNITS_BYTES, _amount,               \
                        NS_LITERAL_CSTRING(_desc), aClosure);                  \
     NS_ENSURE_SUCCESS(rv, rv);                                                \
   } while (0)
 
-  REPORT("window-objects-dom", windowTotalSizes.mDOM, 
-         "Memory used for the DOM within windows. "
-         "This is the sum of all windows' 'dom' numbers.");
-    
+  REPORT("window-objects-dom-other", windowTotalSizes.mDOMOther, 
+         "Memory used for the DOM within windows, "
+         "excluding element, text, CDATA, and comment nodes. "
+         "This is the sum of all windows' 'dom/other' numbers.");
+
+  REPORT("window-objects-dom-element-nodes", windowTotalSizes.mDOMElementNodes,
+         "Memory used for DOM element nodes within windows. "
+         "This is the sum of all windows' 'dom/element-nodes' numbers.");
+
+  REPORT("window-objects-dom-text-nodes", windowTotalSizes.mDOMTextNodes,
+         "Memory used for DOM text nodes within windows. "
+         "This is the sum of all windows' 'dom/text-nodes' numbers.");
+
+  REPORT("window-objects-dom-cdata-nodes", windowTotalSizes.mDOMCDATANodes,
+         "Memory used for DOM CDATA nodes within windows. "
+         "This is the sum of all windows' 'dom/cdata-nodes' numbers.");
+
+  REPORT("window-objects-dom-comment-nodes", windowTotalSizes.mDOMCommentNodes,
+         "Memory used for DOM comment nodes within windows. "
+         "This is the sum of all windows' 'dom/comment-nodes' numbers.");
+
   REPORT("window-objects-style-sheets", windowTotalSizes.mStyleSheets, 
          "Memory used for style sheets within windows. "
          "This is the sum of all windows' 'style-sheets' numbers.");
     
   REPORT("window-objects-layout-arenas", windowTotalSizes.mLayoutArenas, 
          "Memory used by layout PresShell and other related "
          "areas within windows. This is the sum of all windows' "
          "'layout/arenas' numbers.");
--- a/dom/base/nsWindowMemoryReporter.h
+++ b/dom/base/nsWindowMemoryReporter.h
@@ -22,17 +22,21 @@
 
 class nsWindowSizes {
 public:
   nsWindowSizes(nsMallocSizeOfFun aMallocSizeOf) {
     memset(this, 0, sizeof(nsWindowSizes));
     mMallocSizeOf = aMallocSizeOf;
   }
   nsMallocSizeOfFun mMallocSizeOf;
-  size_t mDOM;
+  size_t mDOMElementNodes;
+  size_t mDOMTextNodes;
+  size_t mDOMCDATANodes;
+  size_t mDOMCommentNodes;
+  size_t mDOMOther;
   size_t mStyleSheets;
   size_t mLayoutArenas;
   size_t mLayoutStyleSets;
   size_t mLayoutTextRuns;
   size_t mLayoutPresContext;
 };
 
 /**