Bug 1382768 - Performance API must be a memory reporter, r=njn
☠☠ backed out by fafcbde04754 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 21 Jul 2017 16:51:53 +0200
changeset 419035 abd1b9db490509a1d029ab438fe8714d28328fe4
parent 419034 f39688016fcb6f5a406f34d693b9004dd37fab62
child 419036 1b2ab38ba0b83e2c5dd137b6c8959bfa575c4d7d
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1382768
milestone56.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 1382768 - Performance API must be a memory reporter, r=njn
dom/performance/Performance.cpp
dom/performance/Performance.h
dom/performance/PerformanceEntry.cpp
dom/performance/PerformanceEntry.h
dom/performance/PerformanceMark.cpp
dom/performance/PerformanceMark.h
dom/performance/PerformanceMeasure.cpp
dom/performance/PerformanceMeasure.h
dom/performance/PerformanceResourceTiming.cpp
dom/performance/PerformanceResourceTiming.h
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -83,16 +83,17 @@ public:
 private:
   bool mEnabled;
   nsCString mPrefName;
 };
 
 } // anonymous namespace
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Performance)
+  NS_INTERFACE_MAP_ENTRY(nsIMemoryReporter)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(Performance,
                                    DOMEventTargetHelper,
                                    mUserEntries,
                                    mResourceEntries);
 
 NS_IMPL_ADDREF_INHERITED(Performance, DOMEventTargetHelper)
@@ -102,26 +103,28 @@ NS_IMPL_RELEASE_INHERITED(Performance, D
 Performance::CreateForMainThread(nsPIDOMWindowInner* aWindow,
                                  nsDOMNavigationTiming* aDOMTiming,
                                  nsITimedChannel* aChannel)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<Performance> performance =
     PerformanceMainThread::Create(aWindow, aDOMTiming, aChannel);
+  RegisterWeakMemoryReporter(performance);
   return performance.forget();
 }
 
 /* static */ already_AddRefed<Performance>
 Performance::CreateForWorker(workers::WorkerPrivate* aWorkerPrivate)
 {
   MOZ_ASSERT(aWorkerPrivate);
   aWorkerPrivate->AssertIsOnWorkerThread();
 
   RefPtr<Performance> performance = new PerformanceWorker(aWorkerPrivate);
+  RegisterWeakMemoryReporter(performance);
   return performance.forget();
 }
 
 Performance::Performance()
   : mResourceTimingBufferSize(kDefaultResourceTimingBufferSize)
   , mPendingNotificationObserversTask(false)
 {
   MOZ_ASSERT(!NS_IsMainThread());
@@ -131,17 +134,19 @@ Performance::Performance(nsPIDOMWindowIn
   : DOMEventTargetHelper(aWindow)
   , mResourceTimingBufferSize(kDefaultResourceTimingBufferSize)
   , mPendingNotificationObserversTask(false)
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 Performance::~Performance()
-{}
+{
+  UnregisterWeakMemoryReporter(this);
+}
 
 DOMHighResTimeStamp
 Performance::Now() const
 {
   TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
   return RoundTime(duration.ToMilliseconds());
 }
 
@@ -568,10 +573,34 @@ Performance::IsObserverEnabled(JSContext
 }
 
 void
 Performance::MemoryPressure()
 {
   mUserEntries.Clear();
 }
 
+NS_IMETHODIMP
+Performance::CollectReports(nsIHandleReportCallback* aHandleReport,
+                            nsISupports* aData, bool aAnonymize)
+{
+  size_t userEntries = 0;
+  for (const PerformanceEntry* entry : mUserEntries) {
+    userEntries += entry->SizeOfIncludingThis(MallocSizeOf);
+  }
+
+  MOZ_COLLECT_REPORT(
+    "explicit/dom/performance/userEntries", KIND_HEAP, UNITS_BYTES,
+    userEntries, "Memory used for performance user entries.");
+
+  size_t resourceEntries = 0;
+  for (const PerformanceEntry* entry : mResourceEntries) {
+    resourceEntries += entry->SizeOfIncludingThis(MallocSizeOf);
+  }
+
+  MOZ_COLLECT_REPORT(
+    "explicit/dom/performance/userEntries", KIND_HEAP, UNITS_BYTES,
+    resourceEntries, "Memory used for performance resource entries.");
+  return NS_OK;
+}
+
 } // dom namespace
 } // mozilla namespace
--- a/dom/performance/Performance.h
+++ b/dom/performance/Performance.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_dom_Performance_h
 #define mozilla_dom_Performance_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "nsCOMPtr.h"
 #include "nsDOMNavigationTiming.h"
+#include "nsIMemoryReporter.h"
 
 class nsITimedChannel;
 class nsIHttpChannel;
 
 namespace mozilla {
 
 class ErrorResult;
 
@@ -28,19 +29,23 @@ class PerformanceService;
 class PerformanceTiming;
 
 namespace workers {
 class WorkerPrivate;
 }
 
 // Base class for main-thread and worker Performance API
 class Performance : public DOMEventTargetHelper
+                  , public nsIMemoryReporter
 {
+  MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
+
 public:
   NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_NSIMEMORYREPORTER
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Performance,
                                            DOMEventTargetHelper)
 
   static bool IsObserverEnabled(JSContext* aCx, JSObject* aGlobal);
 
   static already_AddRefed<Performance>
   CreateForMainThread(nsPIDOMWindowInner* aWindow,
                       nsDOMNavigationTiming* aDOMTiming,
--- a/dom/performance/PerformanceEntry.cpp
+++ b/dom/performance/PerformanceEntry.cpp
@@ -36,8 +36,21 @@ PerformanceEntry::~PerformanceEntry()
 {
 }
 
 JSObject*
 PerformanceEntry::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return mozilla::dom::PerformanceEntryBinding::Wrap(aCx, this, aGivenProto);
 }
+
+size_t
+PerformanceEntry::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return mName.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
+         mEntryType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+}
+
+size_t
+PerformanceEntry::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
--- a/dom/performance/PerformanceEntry.h
+++ b/dom/performance/PerformanceEntry.h
@@ -79,17 +79,21 @@ public:
     return 0;
   }
 
   virtual const PerformanceResourceTiming* ToResourceTiming() const
   {
     return nullptr;
   }
 
+  virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 protected:
+  virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
   nsCOMPtr<nsISupports> mParent;
   nsString mName;
   nsString mEntryType;
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/performance/PerformanceMark.cpp
+++ b/dom/performance/PerformanceMark.cpp
@@ -24,8 +24,14 @@ PerformanceMark::~PerformanceMark()
 {
 }
 
 JSObject*
 PerformanceMark::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return PerformanceMarkBinding::Wrap(aCx, this, aGivenProto);
 }
+
+size_t
+PerformanceMark::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
--- a/dom/performance/PerformanceMark.h
+++ b/dom/performance/PerformanceMark.h
@@ -22,16 +22,18 @@ public:
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   virtual DOMHighResTimeStamp StartTime() const override
   {
     return mStartTime;
   }
 
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+
 protected:
   virtual ~PerformanceMark();
   DOMHighResTimeStamp mStartTime;
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/performance/PerformanceMeasure.cpp
+++ b/dom/performance/PerformanceMeasure.cpp
@@ -26,8 +26,14 @@ PerformanceMeasure::~PerformanceMeasure(
 {
 }
 
 JSObject*
 PerformanceMeasure::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return PerformanceMeasureBinding::Wrap(aCx, this, aGivenProto);
 }
+
+size_t
+PerformanceMeasure::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
--- a/dom/performance/PerformanceMeasure.h
+++ b/dom/performance/PerformanceMeasure.h
@@ -28,16 +28,18 @@ public:
     return mStartTime;
   }
 
   virtual DOMHighResTimeStamp Duration() const override
   {
     return mDuration;
   }
 
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+
 protected:
   virtual ~PerformanceMeasure();
   DOMHighResTimeStamp mStartTime;
   DOMHighResTimeStamp mDuration;
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/performance/PerformanceResourceTiming.cpp
+++ b/dom/performance/PerformanceResourceTiming.cpp
@@ -21,17 +21,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
 NS_INTERFACE_MAP_END_INHERITING(PerformanceEntry)
 
 NS_IMPL_ADDREF_INHERITED(PerformanceResourceTiming, PerformanceEntry)
 NS_IMPL_RELEASE_INHERITED(PerformanceResourceTiming, PerformanceEntry)
 
 PerformanceResourceTiming::PerformanceResourceTiming(PerformanceTiming* aPerformanceTiming,
                                                      Performance* aPerformance,
                                                      const nsAString& aName)
-: PerformanceEntry(aPerformance, aName, NS_LITERAL_STRING("resource")),
+: PerformanceEntry(aPerformance->GetParentObject(), aName, NS_LITERAL_STRING("resource")),
   mTiming(aPerformanceTiming),
   mEncodedBodySize(0),
   mTransferSize(0),
   mDecodedBodySize(0)
 {
   MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
 }
 
@@ -46,8 +46,22 @@ PerformanceResourceTiming::StartTime() c
   return startTime ? startTime : mTiming->FetchStartHighRes();
 }
 
 JSObject*
 PerformanceResourceTiming::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return PerformanceResourceTimingBinding::Wrap(aCx, this, aGivenProto);
 }
+
+size_t
+PerformanceResourceTiming::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
+
+size_t
+PerformanceResourceTiming::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+  return PerformanceEntry::SizeOfExcludingThis(aMallocSizeOf) +
+         mInitiatorType.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
+         mNextHopProtocol.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+}
--- a/dom/performance/PerformanceResourceTiming.h
+++ b/dom/performance/PerformanceResourceTiming.h
@@ -163,19 +163,25 @@ public:
     mTransferSize = aTransferSize;
   }
 
   void SetDecodedBodySize(uint64_t aDecodedBodySize)
   {
     mDecodedBodySize = aDecodedBodySize;
   }
 
+  size_t
+  SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+
 protected:
   virtual ~PerformanceResourceTiming();
 
+  size_t
+  SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+
   nsString mInitiatorType;
   nsString mNextHopProtocol;
   RefPtr<PerformanceTiming> mTiming;
   uint64_t mEncodedBodySize;
   uint64_t mTransferSize;
   uint64_t mDecodedBodySize;
 };