bug 1366294 - Part 12 - Clean up after onesself. r=gfritzsche
authorChris H-C <chutten@mozilla.com>
Fri, 14 Jul 2017 15:02:54 -0400
changeset 419312 bd42fa11936e3c2ecb91ab935aaefa48e6f99892
parent 419311 da02984a8e1f8e053a9a65542fe79c1d413b5eeb
child 419313 7b77ed78841f72748a1da9f0830f4317b21a5661
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)
reviewersgfritzsche
bugs1366294
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 1366294 - Part 12 - Clean up after onesself. r=gfritzsche Without the StatisticsRecorder cleaning up after us we need to now manually delete the Histograms we create. MozReview-Commit-ID: 8jrPPBQmU0Z
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -137,16 +137,17 @@ enum class SessionType {
   Session = 0,
   Subsession = 1,
   Count,
 };
 
 class KeyedHistogram {
 public:
   KeyedHistogram(HistogramID id, const HistogramInfo& info);
+  ~KeyedHistogram();
   nsresult GetHistogram(const nsCString& name, Histogram** histogram, bool subsession);
   Histogram* GetHistogram(const nsCString& name, bool subsession);
   uint32_t GetHistogramType() const { return mHistogramInfo.histogramType; }
   nsresult GetJSKeys(JSContext* cx, JS::CallArgs& args);
   nsresult GetJSSnapshot(JSContext* cx, JS::Handle<JSObject*> obj,
                          bool subsession, bool clearSubsession);
 
   nsresult Add(const nsCString& key, uint32_t aSample, ProcessID aProcessType);
@@ -637,16 +638,39 @@ KeyedHistogram::KeyedHistogram(Histogram
 #if !defined(MOZ_WIDGET_ANDROID)
   , mSubsessionMap()
 #endif
   , mId(id)
   , mHistogramInfo(info)
 {
 }
 
+KeyedHistogram::~KeyedHistogram()
+{
+  for (auto iter = mHistogramMap.Iter(); !iter.Done(); iter.Next()) {
+    Histogram* h = iter.Get()->mData;
+    if (h == gExpiredHistogram) {
+      continue;
+    }
+    delete h;
+  }
+  mHistogramMap.Clear();
+
+#if !defined(MOZ_WIDGET_ANDROID)
+  for (auto iter = mSubsessionMap.Iter(); !iter.Done(); iter.Next()) {
+    Histogram* h = iter.Get()->mData;
+    if (h == gExpiredHistogram) {
+      continue;
+    }
+    delete h;
+  }
+  mSubsessionMap.Clear();
+#endif
+}
+
 nsresult
 KeyedHistogram::GetHistogram(const nsCString& key, Histogram** histogram,
                              bool subsession)
 {
 #if !defined(MOZ_WIDGET_ANDROID)
   KeyedHistogramMapType& map = subsession ? mSubsessionMap : mHistogramMap;
 #else
   KeyedHistogramMapType& map = mHistogramMap;
@@ -722,26 +746,34 @@ void
 KeyedHistogram::Clear(bool onlySubsession)
 {
   MOZ_ASSERT(XRE_IsParentProcess());
   if (!XRE_IsParentProcess()) {
     return;
   }
 #if !defined(MOZ_WIDGET_ANDROID)
   for (auto iter = mSubsessionMap.Iter(); !iter.Done(); iter.Next()) {
-    iter.Get()->mData->Clear();
+    Histogram* h = iter.Get()->mData;
+    if (h == gExpiredHistogram) {
+      continue;
+    }
+    delete h;
   }
   mSubsessionMap.Clear();
   if (onlySubsession) {
     return;
   }
 #endif
 
   for (auto iter = mHistogramMap.Iter(); !iter.Done(); iter.Next()) {
-    iter.Get()->mData->Clear();
+    Histogram* h = iter.Get()->mData;
+    if (h == gExpiredHistogram) {
+      continue;
+    }
+    delete h;
   }
   mHistogramMap.Clear();
 }
 
 nsresult
 KeyedHistogram::GetJSKeys(JSContext* cx, JS::CallArgs& args)
 {
   JS::AutoValueVector keys(cx);
@@ -1625,16 +1657,34 @@ void TelemetryHistogram::InitializeGloba
 
 void TelemetryHistogram::DeInitializeGlobalState()
 {
   StaticMutexAutoLock locker(gTelemetryHistogramMutex);
   gCanRecordBase = false;
   gCanRecordExtended = false;
   gNameToHistogramIDMap.Clear();
   gInitDone = false;
+
+  // FactoryGet `new`s Histograms for us, but requires us to manually delete.
+  for (size_t i = 0; i < HistogramCount; ++i) {
+    for (uint32_t process = 0; process < static_cast<uint32_t>(ProcessID::Count); ++process) {
+      delete gKeyedHistogramStorage[i][process];
+      gKeyedHistogramStorage[i][process] = nullptr;
+      for (uint32_t session = 0; session <
+        static_cast<uint32_t>(SessionType::Count); ++session) {
+        if (gHistogramStorage[i][process][session] == gExpiredHistogram) {
+          continue;
+        }
+        delete gHistogramStorage[i][process][session];
+        gHistogramStorage[i][process][session] = nullptr;
+      }
+    }
+  }
+  delete gExpiredHistogram;
+  gExpiredHistogram = nullptr;
 }
 
 #ifdef DEBUG
 bool TelemetryHistogram::GlobalStateHasBeenInitialized() {
   StaticMutexAutoLock locker(gTelemetryHistogramMutex);
   return gInitDone;
 }
 #endif