Bug 1493563 - Part 8: Report the memorty usage of the Content Blocking log; r=baku
☠☠ backed out by 1681bd622c63 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 23 Sep 2018 01:43:18 -0400
changeset 494519 3ef707008502d3555d384f8803b97d4b4c7a0d55
parent 494518 bb2720a401fed1848e792b202d744171a60af7d5
child 494520 02b8b073f7d7007ce41c2fb71aab5ceafe5d371b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1493563
milestone64.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 1493563 - Part 8: Report the memorty usage of the Content Blocking log; r=baku Differential Revision: https://phabricator.services.mozilla.com/D6598
dom/base/ContentBlockingLog.h
dom/base/nsDocument.cpp
--- a/dom/base/ContentBlockingLog.h
+++ b/dom/base/ContentBlockingLog.h
@@ -9,31 +9,33 @@
 
 #include "mozilla/JSONWriter.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/UniquePtr.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
+#include "nsWindowSizes.h"
 
 namespace mozilla {
 namespace dom {
 
 class ContentBlockingLog final
 {
   struct LogEntry {
     uint32_t mType;
     uint32_t mRepeatCount;
     bool mBlocked;
   };
 
   // Each element is a tuple of (type, blocked, repeatCount). The type values
   // come from the blocking types defined in nsIWebProgressListener.
   typedef nsTArray<LogEntry> OriginLog;
+  typedef nsClassHashtable<nsStringHashKey, OriginLog> OriginLogHashTable;
 
   struct StringWriteFunc : public JSONWriteFunc
   {
     nsAString& mBuffer; // The lifetime of the struct must be bound to the buffer
     explicit StringWriteFunc(nsAString& aBuffer)
       : mBuffer(aBuffer)
     {}
 
@@ -106,16 +108,32 @@ public:
       w.EndArray();
     }
 
     w.End();
 
     return buffer;
   }
 
+  void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const
+  {
+    aSizes.mDOMOtherSize += mLog.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
+
+    // Now add the sizes of each origin log queue.
+    // The const_cast is needed because the nsTHashtable::Iterator interface is
+    // not const-safe.  :-(
+    for (auto iter = const_cast<OriginLogHashTable&>(mLog).Iter();
+         !iter.Done(); iter.Next()) {
+      if (iter.UserData()) {
+        aSizes.mDOMOtherSize +=
+          iter.UserData()->ShallowSizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
+      }
+    }
+  }
+
 private:
-  nsClassHashtable<nsStringHashKey, OriginLog> mLog;
+  OriginLogHashTable mLog;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -11784,16 +11784,18 @@ nsIDocument::DocAddSizeOfExcludingThis(n
   aSizes.mDOMMediaQueryLists +=
     mDOMMediaQueryLists.sizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
 
   for (const MediaQueryList* mql : mDOMMediaQueryLists) {
     aSizes.mDOMMediaQueryLists +=
       mql->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
   }
 
+  mContentBlockingLog.AddSizeOfExcludingThis(aSizes);
+
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - many!
 }
 
 void
 nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const
 {