Bug 1422061 - Prevent performance actor from stopping profiler started by Talos. r=gregtatum draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 16 Jan 2018 08:26:30 -0800
changeset 720962 fc80c51c20143e6dda1368cdeb8e464abdedde1d
parent 720380 b7d66e4e60ef177ec9ae687daa29443ae4a2acfc
child 746212 bc6dd5be44574c7f514d94227ebc67776a438444
push id95708
push userbmo:poirot.alex@gmail.com
push dateTue, 16 Jan 2018 16:34:02 +0000
reviewersgregtatum
bugs1422061
milestone59.0a1
Bug 1422061 - Prevent performance actor from stopping profiler started by Talos. r=gregtatum MozReview-Commit-ID: 7PrI9ZwUMtX
devtools/server/performance/profiler.js
--- a/devtools/server/performance/profiler.js
+++ b/devtools/server/performance/profiler.js
@@ -45,16 +45,19 @@ const ProfilerManager = (function () {
   return {
 
     // How often the "profiler-status" is emitted
     _profilerStatusInterval: BUFFER_STATUS_INTERVAL_DEFAULT,
 
     // How many subscribers there
     _profilerStatusSubscribers: 0,
 
+    // Has the profiler ever been started by the actor?
+    started: false,
+
     /**
      * The nsIProfiler is target agnostic and interacts with the whole platform.
      * Therefore, special care needs to be given to make sure different profiler
      * consumers (i.e. "toolboxes") don't interfere with each other. Register
      * the profiler actor instances here.
      *
      * @param Profiler instance
      *        A profiler actor class.
@@ -119,33 +122,38 @@ const ProfilerManager = (function () {
           config.threadFilters.length
         );
       } catch (e) {
         // For some reason, the profiler couldn't be started. This could happen,
         // for example, when in private browsing mode.
         Cu.reportError(`Could not start the profiler module: ${e.message}`);
         return { started: false, reason: e, currentTime };
       }
+      this.started = true;
 
       this._updateProfilerStatusPolling();
 
       let { position, totalSize, generation } = this.getBufferInfo();
       return { started: true, position, totalSize, generation, currentTime };
     },
 
     /**
      * Attempts to stop the nsIProfiler module.
      */
     stop: function () {
       // Actually stop the profiler only if the last client has stopped profiling.
       // Since this is used as a root actor, and the profiler module interacts
       // with the whole platform, we need to avoid a case in which the profiler
       // is stopped when there might be other clients still profiling.
-      if (this.length <= 1) {
+      // Also check for `started` to only stop the profiler when the actor
+      // actually started it. This is to prevent stopping the profiler initiated
+      // by some other code, like Talos.
+      if (this.length <= 1 && this.started) {
         nsIProfilerModule.StopProfiler();
+        this.started = false;
       }
       this._updateProfilerStatusPolling();
       return { started: false };
     },
 
     /**
      * Returns all the samples accumulated since the profiler was started,
      * along with the current time. The data has the following format: