Bug 1340928 (part 3) - Remove Sampler from ProfileGatherer. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 15 Feb 2017 14:44:12 +1100
changeset 373442 cbc8f0119f8ba08e5c2f9782107531c085e794d7
parent 373441 a3a18d2124d73caac76f56fc87410fcaec7336b4
child 373443 c043ce740d1bed8c359290b5b7125cc27f238147
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1340928
milestone54.0a1
Bug 1340928 (part 3) - Remove Sampler from ProfileGatherer. r=mstange. It's only being used in a boolean fashion, so this patch replaces it with a boolean.
tools/profiler/core/platform.cpp
tools/profiler/gecko/ProfileGatherer.cpp
tools/profiler/public/ProfileGatherer.h
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2024,17 +2024,17 @@ profiler_start(int aProfileEntries, doub
   }
 
 #ifdef MOZ_TASK_TRACER
   if (gTaskTracer) {
     mozilla::tasktracer::StartLogging();
   }
 #endif
 
-  gGatherer = new mozilla::ProfileGatherer(gSampler);
+  gGatherer = new mozilla::ProfileGatherer();
 
   MOZ_ASSERT(!gIsActive && !gIsPaused);
   PlatformStart();
   MOZ_ASSERT(gIsActive && !gIsPaused);  // PlatformStart() sets gIsActive.
 
   if (gProfileJS || privacyMode) {
     mozilla::StaticMutexAutoLock lock(gRegisteredThreadsMutex);
 
--- a/tools/profiler/gecko/ProfileGatherer.cpp
+++ b/tools/profiler/gecko/ProfileGatherer.cpp
@@ -22,18 +22,18 @@ namespace mozilla {
  * only store up to MAX_SUBPROCESS_EXIT_PROFILES. The buffer is
  * circular, so as soon as we receive another exit profile, we'll
  * bump the oldest one out of the buffer.
  */
 static const uint32_t MAX_SUBPROCESS_EXIT_PROFILES = 5;
 
 NS_IMPL_ISUPPORTS(ProfileGatherer, nsIObserver)
 
-ProfileGatherer::ProfileGatherer(Sampler* aSampler)
-  : mSampler(aSampler)
+ProfileGatherer::ProfileGatherer()
+  : mIsCancelled(false)
   , mSinceTime(0)
   , mPendingProfiles(0)
   , mGathering(false)
 {
 }
 
 void
 ProfileGatherer::GatheredOOPProfile()
@@ -140,17 +140,17 @@ ProfileGatherer::Start(double aSinceTime
   Start(aSinceTime, file);
 }
 
 void
 ProfileGatherer::Finish()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!mSampler) {
+  if (mIsCancelled) {
     // We somehow got called after we were cancelled! This shouldn't
     // be possible, but doing a belt-and-suspenders check to be sure.
     return;
   }
 
   UniquePtr<char[]> buf = ToJSON(mSinceTime);
 
   if (mFile) {
@@ -211,26 +211,25 @@ ProfileGatherer::Reset()
   mFile = nullptr;
   mPendingProfiles = 0;
   mGathering = false;
 }
 
 void
 ProfileGatherer::Cancel()
 {
-  // The Sampler is going away. If we have a Promise in flight, we should
+  // We're about to stop profiling. If we have a Promise in flight, we should
   // reject it.
   if (mPromise) {
     mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
   }
   mPromise = nullptr;
   mFile = nullptr;
 
-  // Clear out the Sampler reference, since it's being destroyed.
-  mSampler = nullptr;
+  mIsCancelled = true;
 }
 
 void
 ProfileGatherer::OOPExitProfile(const nsCString& aProfile)
 {
   if (mExitProfiles.Length() >= MAX_SUBPROCESS_EXIT_PROFILES) {
     mExitProfiles.RemoveElementAt(0);
   }
--- a/tools/profiler/public/ProfileGatherer.h
+++ b/tools/profiler/public/ProfileGatherer.h
@@ -3,44 +3,42 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZ_PROFILE_GATHERER_H
 #define MOZ_PROFILE_GATHERER_H
 
 #include "mozilla/dom/Promise.h"
 #include "nsIFile.h"
 
-class Sampler;
-
 namespace mozilla {
 
 class ProfileGatherer final : public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
-  explicit ProfileGatherer(Sampler* aSampler);
+  explicit ProfileGatherer();
   void WillGatherOOPProfile();
   void GatheredOOPProfile();
   void Start(double aSinceTime, mozilla::dom::Promise* aPromise);
   void Start(double aSinceTime, nsIFile* aFile);
   void Start(double aSinceTime, const nsACString& aFileName);
   void Cancel();
   void OOPExitProfile(const nsCString& aProfile);
 
 private:
   ~ProfileGatherer() {};
   void Finish();
   void Reset();
 
   nsTArray<nsCString> mExitProfiles;
   RefPtr<mozilla::dom::Promise> mPromise;
   nsCOMPtr<nsIFile> mFile;
-  Sampler* mSampler;
+  bool mIsCancelled;
   double mSinceTime;
   uint32_t mPendingProfiles;
   bool mGathering;
 };
 
 } // namespace mozilla
 
 #endif