Bug 1475988 - Report memory usage per Telemetry submodule r=gfritzsche
authorJan-Erik Rediger <jrediger@mozilla.com>
Wed, 18 Jul 2018 13:46:27 +0000
changeset 819853 2d8e5069654588a436d3c45ddd6e5ed8d729fb70
parent 819852 c028d93bbf3fc40ebdced747dd93d59b9e35c398
child 819854 8c535b56f2cdba467671dcc9d3dce85918f3e432
push id116678
push userbmo:nchevobbe@mozilla.com
push dateWed, 18 Jul 2018 18:05:12 +0000
reviewersgfritzsche
bugs1475988
milestone63.0a1
Bug 1475988 - Report memory usage per Telemetry submodule r=gfritzsche Differential Revision: https://phabricator.services.mozilla.com/D2159
toolkit/components/telemetry/KeyedStackCapturer.cpp
toolkit/components/telemetry/KeyedStackCapturer.h
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/KeyedStackCapturer.cpp
+++ b/toolkit/components/telemetry/KeyedStackCapturer.cpp
@@ -154,10 +154,18 @@ KeyedStackCapturer::ReflectCapturedStack
 void
 KeyedStackCapturer::Clear()
 {
   MutexAutoLock captureStackMutex(mStackCapturerMutex);
   mStackInfos.Clear();
   mStacks.Clear();
 }
 
+size_t
+KeyedStackCapturer::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
+  size_t n = 0;
+  n += mStackInfos.SizeOfExcludingThis(aMallocSizeOf);
+  n += mStacks.SizeOfExcludingThis();
+  return n;
+}
+
 } // namespace Telemetry
 } // namespace mozilla
--- a/toolkit/components/telemetry/KeyedStackCapturer.h
+++ b/toolkit/components/telemetry/KeyedStackCapturer.h
@@ -41,16 +41,18 @@ public:
    NS_IMETHODIMP ReflectCapturedStacks(
     JSContext *cx, JS::MutableHandle<JS::Value> ret);
 
   /**
    * Resets captured stacks and the information related to them.
    */
   void Clear();
 
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 private:
   /**
    * Describes how often a stack was captured.
    */
   struct StackFrequencyInfo {
     // A number of times the stack was captured.
     uint32_t mCount;
     // Index of the stack inside stacks array.
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -143,17 +143,16 @@ public:
 
   static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
   static void ShutdownTelemetry();
   static void RecordSlowStatement(const nsACString &sql, const nsACString &dbName,
                                   uint32_t delay);
 #if defined(MOZ_GECKO_PROFILER)
   static void DoStackCapture(const nsACString& aKey);
 #endif
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
   struct Stat {
     uint32_t hitCount;
     uint32_t totalTime;
   };
   struct StmtStats {
     struct Stat mainThread;
     struct Stat otherThreads;
   };
@@ -215,20 +214,80 @@ private:
 TelemetryImpl*  TelemetryImpl::sTelemetry = nullptr;
 
 MOZ_DEFINE_MALLOC_SIZE_OF(TelemetryMallocSizeOf)
 
 NS_IMETHODIMP
 TelemetryImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
                               nsISupports* aData, bool aAnonymize)
 {
-  MOZ_COLLECT_REPORT(
-    "explicit/telemetry", KIND_HEAP, UNITS_BYTES,
-    SizeOfIncludingThis(TelemetryMallocSizeOf),
-    "Memory used by the telemetry system.");
+  mozilla::MallocSizeOf aMallocSizeOf = TelemetryMallocSizeOf;
+
+#define COLLECT_REPORT(name, size, desc) \
+  MOZ_COLLECT_REPORT(name, KIND_HEAP, UNITS_BYTES, size, desc)
+
+  COLLECT_REPORT("explicit/telemetry/impl", aMallocSizeOf(this),
+      "Memory used by the Telemetry core implemenation");
+
+  COLLECT_REPORT("explicit/telemetry/histogram/shallow",
+      TelemetryHistogram::GetMapShallowSizesOfExcludingThis(aMallocSizeOf),
+      "Memory used by the Telemetry Histogram implementation");
+
+  COLLECT_REPORT("explicit/telemetry/scalar/shallow",
+      TelemetryScalar::GetMapShallowSizesOfExcludingThis(aMallocSizeOf),
+      "Memory used by the Telemetry Scalar implemenation");
+
+  COLLECT_REPORT("explicit/telemetry/WebRTC",
+      mWebrtcTelemetry.SizeOfExcludingThis(aMallocSizeOf),
+      "Memory used by WebRTC Telemetry");
+
+  { // Scope for mHashMutex lock
+    MutexAutoLock lock(mHashMutex);
+    COLLECT_REPORT("explicit/telemetry/PrivateSQL",
+        mPrivateSQL.SizeOfExcludingThis(aMallocSizeOf),
+        "Memory used by the PrivateSQL Telemetry");
+
+    COLLECT_REPORT("explicit/telemetry/SanitizedSQL",
+        mSanitizedSQL.SizeOfExcludingThis(aMallocSizeOf),
+        "Memory used by the SanitizedSQL Telemetry");
+  }
+
+  if (sTelemetryIOObserver) {
+    COLLECT_REPORT("explicit/telemetry/IOObserver",
+        sTelemetryIOObserver->SizeOfIncludingThis(aMallocSizeOf),
+        "Memory used by the Telemetry IO Observer");
+  }
+
+#if defined(MOZ_GECKO_PROFILER)
+  COLLECT_REPORT("explicit/telemetry/StackCapturer",
+        mStackCapturer.SizeOfExcludingThis(aMallocSizeOf),
+        "Memory used by the Telemetry Stack capturer");
+#endif
+
+  COLLECT_REPORT("explicit/telemetry/LateWritesStacks",
+        mLateWritesStacks.SizeOfExcludingThis(),
+        "Memory used by the Telemetry LateWrites Stack capturer");
+
+  COLLECT_REPORT("explicit/telemetry/Callbacks",
+        mCallbacks.ShallowSizeOfExcludingThis(aMallocSizeOf),
+        "Memory used by the Telemetry Callbacks array (shallow)");
+
+  COLLECT_REPORT("explicit/telemetry/histogram/data",
+      TelemetryHistogram::GetHistogramSizesofIncludingThis(aMallocSizeOf),
+      "Memory used by Telemetry Histogram data");
+
+  COLLECT_REPORT("explicit/telemetry/scalar/data",
+      TelemetryScalar::GetScalarSizesOfIncludingThis(aMallocSizeOf),
+      "Memory used by Telemetry Scalar data");
+
+  COLLECT_REPORT("explicit/telemetry/event/data",
+      TelemetryEvent::SizeOfIncludingThis(aMallocSizeOf),
+      "Memory used by Telemetry Event data");
+
+#undef COLLECT_REPORT
 
   return NS_OK;
 }
 
 void
 InitHistogramRecordingEnabled()
 {
   TelemetryHistogram::InitHistogramRecordingEnabled();
@@ -1736,43 +1795,16 @@ TelemetryImpl::SetEventRecordingEnabled(
 
 NS_IMETHODIMP
 TelemetryImpl::FlushBatchedChildTelemetry()
 {
   TelemetryIPCAccumulator::IPCTimerFired(nullptr, nullptr);
   return NS_OK;
 }
 
-size_t
-TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
-{
-  size_t n = aMallocSizeOf(this);
-
-  n += TelemetryHistogram::GetMapShallowSizesOfExcludingThis(aMallocSizeOf);
-  n += TelemetryScalar::GetMapShallowSizesOfExcludingThis(aMallocSizeOf);
-  n += mWebrtcTelemetry.SizeOfExcludingThis(aMallocSizeOf);
-  { // Scope for mHashMutex lock
-    MutexAutoLock lock(mHashMutex);
-    n += mPrivateSQL.SizeOfExcludingThis(aMallocSizeOf);
-    n += mSanitizedSQL.SizeOfExcludingThis(aMallocSizeOf);
-  }
-
-  // It's a bit gross that we measure this other stuff that lives outside of
-  // TelemetryImpl... oh well.
-  if (sTelemetryIOObserver) {
-    n += sTelemetryIOObserver->SizeOfIncludingThis(aMallocSizeOf);
-  }
-
-  n += TelemetryHistogram::GetHistogramSizesofIncludingThis(aMallocSizeOf);
-  n += TelemetryScalar::GetScalarSizesOfIncludingThis(aMallocSizeOf);
-  n += TelemetryEvent::SizeOfIncludingThis(aMallocSizeOf);
-
-  return n;
-}
-
 } // namespace
 
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 //
 // EXTERNALLY VISIBLE FUNCTIONS in no name space
 // These are NOT listed in Telemetry.h