Bug 1493563 - Part 8: Report the memorty usage of the Content Blocking log; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 23 Sep 2018 01:43:18 -0400
changeset 494538 e255803a5af2da97823c3241ad005126875572ff
parent 494537 c25ea7b5e8d8472c5efab7a6122a977cbb5407d4
child 494539 c5858df458e7635a6630d20c884ee4363eb1fd65
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
 {