Bug 1493563 - Part 8: Report the memorty usage of the Content Blocking log; r=baku
☠☠ backed out by a95c13dd55c5 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 23 Sep 2018 01:43:18 -0400
changeset 493974 205d69890f50e8bf53591c23e6a9834b1e2bc3e8
parent 493973 5f922cd6c21e5f60a37afbcf24d867f16ff60d51
child 493975 68de8f0866d0c9e0883b8eaf33b91d3e308198e6
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
@@ -11771,16 +11771,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
 {