Bug 1340928 (part 14) - Factor out code repeated in both ProfileGatherer::Start() methods. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 22 Feb 2017 11:46:28 +1100
changeset 373486 d0d5dcaa2c361b2b5bd66f9ff06292098305c726
parent 373485 e5f1cf49bed1d6466244b54d9d9b2483a1fc0627
child 373487 494906dbf2d99146cc25c27f8cb51f84c6fe4759
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 14) - Factor out code repeated in both ProfileGatherer::Start() methods. r=mstange.
tools/profiler/gecko/ProfileGatherer.cpp
tools/profiler/gecko/ProfileGatherer.h
--- a/tools/profiler/gecko/ProfileGatherer.cpp
+++ b/tools/profiler/gecko/ProfileGatherer.cpp
@@ -68,42 +68,29 @@ ProfileGatherer::WillGatherOOPProfile()
   mPendingProfiles++;
 }
 
 void
 ProfileGatherer::Start(double aSinceTime,
                        Promise* aPromise)
 {
   MOZ_ASSERT(NS_IsMainThread());
+
   if (mGathering) {
     // If we're already gathering, reject the promise - this isn't going
     // to end well.
     if (aPromise) {
       aPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
     }
     return;
   }
 
-  mSinceTime = aSinceTime;
   mPromise = aPromise;
-  mGathering = true;
-  mPendingProfiles = 0;
 
-  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-  if (os) {
-    DebugOnly<nsresult> rv =
-      os->AddObserver(this, "profiler-subprocess", false);
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "AddObserver failed");
-    rv = os->NotifyObservers(this, "profiler-subprocess-gather", nullptr);
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NotifyObservers failed");
-  }
-
-  if (!mPendingProfiles) {
-    Finish();
-  }
+  Start2(aSinceTime);
 }
 
 void
 ProfileGatherer::Start(double aSinceTime,
                        const nsACString& aFileName)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -112,18 +99,26 @@ ProfileGatherer::Start(double aSinceTime
   if (NS_FAILED(rv)) {
     MOZ_CRASH();
   }
 
   if (mGathering) {
     return;
   }
 
+  mFile = file;
+
+  Start2(aSinceTime);
+}
+
+// This is the common tail shared by both Start() methods.
+void
+ProfileGatherer::Start2(double aSinceTime)
+{
   mSinceTime = aSinceTime;
-  mFile = file;
   mGathering = true;
   mPendingProfiles = 0;
 
   nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os) {
     DebugOnly<nsresult> rv =
       os->AddObserver(this, "profiler-subprocess", false);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "AddObserver failed");
--- a/tools/profiler/gecko/ProfileGatherer.h
+++ b/tools/profiler/gecko/ProfileGatherer.h
@@ -23,16 +23,17 @@ public:
   void Start(double aSinceTime, const nsACString& aFileName);
   void Cancel();
   void OOPExitProfile(const nsCString& aProfile);
 
 private:
   ~ProfileGatherer() {};
   void Finish();
   void Reset();
+  void Start2(double aSinceTime);
 
   nsTArray<nsCString> mExitProfiles;
   RefPtr<mozilla::dom::Promise> mPromise;
   nsCOMPtr<nsIFile> mFile;
   bool mIsCancelled;
   double mSinceTime;
   uint32_t mPendingProfiles;
   bool mGathering;