Bug 1142748 - Use a single configuration for starting/stopping recordings, r=jsantell
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Mar 2015 11:53:23 -0400
changeset 251866 6c16de2f0bbf6881dec74b7153d80797b57cc0c9
parent 251865 9790bffba1f3ba1537ece0162a3fa5c09da70f67
child 251867 d1ffaeb0dbfdea161d220d88742f49e4b3ce655c
push id7860
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:46:02 +0000
treeherdermozilla-aurora@8ac636cd51f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs1142748
milestone39.0a1
Bug 1142748 - Use a single configuration for starting/stopping recordings, r=jsantell
browser/devtools/performance/modules/front.js
browser/devtools/performance/modules/recording-model.js
browser/devtools/performance/performance-controller.js
browser/devtools/performance/test/browser_perf-compatibility-01.js
browser/devtools/performance/test/browser_perf-compatibility-03.js
browser/devtools/performance/test/browser_perf-front.js
browser/devtools/performance/test/browser_perf-options-allocations.js
browser/devtools/performance/test/head.js
--- a/browser/devtools/performance/modules/front.js
+++ b/browser/devtools/performance/modules/front.js
@@ -324,17 +324,20 @@ PerformanceFront.prototype = {
   /**
    * Starts the timeline actor, if necessary.
    */
   _startMemory: Task.async(function *(options) {
     if (!options.withAllocations) {
       return 0;
     }
     yield this._request("memory", "attach");
-    let memoryStartTime = yield this._request("memory", "startRecordingAllocations", options);
+    let memoryStartTime = yield this._request("memory", "startRecordingAllocations", {
+      probability: options.allocationsSampleProbability,
+      maxLogLength: options.allocationsMaxLogLength
+    });
     yield this._pullAllocationSites();
     return memoryStartTime;
   }),
 
   /**
    * Stops the timeline actor, if necessary.
    */
   _stopMemory: Task.async(function *(options) {
--- a/browser/devtools/performance/modules/recording-model.js
+++ b/browser/devtools/performance/modules/recording-model.js
@@ -19,17 +19,19 @@ loader.lazyRequireGetter(this, "Recordin
 const RecordingModel = function (options={}) {
   this._front = options.front;
   this._performance = options.performance;
   this._label = options.label || "";
 
   this._configuration = {
     withTicks: options.withTicks || false,
     withMemory: options.withMemory || false,
-    withAllocations: options.withAllocations || false
+    withAllocations: options.withAllocations || false,
+    allocationsSampleProbability: options.allocationsSampleProbability || 0,
+    allocationsMaxLogLength: options.allocationsMaxLogLength || 0
   };
 };
 
 RecordingModel.prototype = {
   // Private fields, only needed when a recording is started or stopped.
   _imported: false,
   _recording: false,
   _profilerStartTime: 0,
@@ -75,28 +77,25 @@ RecordingModel.prototype = {
    */
   exportRecording: Task.async(function *(file) {
     let recordingData = this.getAllData();
     yield PerformanceIO.saveRecordingToFile(recordingData, file);
   }),
 
   /**
    * Starts recording with the PerformanceFront.
-   *
-   * @param object options
-   *        @see PerformanceFront.prototype.startRecording
    */
-  startRecording: Task.async(function *(options = {}) {
+  startRecording: Task.async(function *() {
     // Times must come from the actor in order to be self-consistent.
     // However, we also want to update the view with the elapsed time
     // even when the actor is not generating data. To do this we get
     // the local time and use it to compute a reasonable elapsed time.
     this._localStartTime = this._performance.now();
 
-    let info = yield this._front.startRecording(options);
+    let info = yield this._front.startRecording(this.getConfiguration());
     this._profilerStartTime = info.profilerStartTime;
     this._timelineStartTime = info.timelineStartTime;
     this._memoryStartTime = info.memoryStartTime;
     this._recording = true;
 
     this._markers = [];
     this._frames = [];
     this._memory = [];
--- a/browser/devtools/performance/performance-controller.js
+++ b/browser/devtools/performance/performance-controller.js
@@ -256,26 +256,26 @@ let PerformanceController = {
     this._nonBooleanPrefs[prefName] = prefValue;
   },
 
   /**
    * Starts recording with the PerformanceFront. Emits `EVENTS.RECORDING_STARTED`
    * when the front has started to record.
    */
   startRecording: Task.async(function *() {
-    let withMemory = this.getOption("enable-memory");
-    let withTicks = this.getOption("enable-framerate");
-    let withAllocations = this.getOption("enable-memory");
-    let probability = this.getPref("memory-sample-probability");
-    let maxLogLength = this.getPref("memory-max-log-length");
-
-    let recording = this._createRecording({ withMemory, withTicks, withAllocations, probability, maxLogLength });
+    let recording = this._createRecording({
+      withMemory: this.getOption("enable-memory"),
+      withTicks: this.getOption("enable-framerate"),
+      withAllocations: this.getOption("enable-memory"),
+      allocationsSampleProbability: this.getPref("memory-sample-probability"),
+      allocationsMaxLogLength: this.getPref("memory-max-log-length")
+    });
 
     this.emit(EVENTS.RECORDING_WILL_START, recording);
-    yield recording.startRecording({ withMemory, withTicks, withAllocations, probability, maxLogLength });
+    yield recording.startRecording();
     this.emit(EVENTS.RECORDING_STARTED, recording);
 
     this.setCurrentRecording(recording);
   }),
 
   /**
    * Stops recording with the PerformanceFront. Emits `EVENTS.RECORDING_STOPPED`
    * when the front has stopped recording.
@@ -337,22 +337,20 @@ let PerformanceController = {
    * internally in the controller.
    *
    * @param object options
    *        @see PerformanceFront.prototype.startRecording
    * @return RecordingModel
    *         The newly created recording model.
    */
   _createRecording: function (options={}) {
-    let { withMemory, withTicks, withAllocations } = options;
-    let front = gFront;
-
-    let recording = new RecordingModel(
-      { front, performance, withMemory, withTicks, withAllocations });
-
+    let recording = new RecordingModel(Heritage.extend(options, {
+      front: gFront,
+      performance: window.performance
+    }));
     this._recordings.push(recording);
     return recording;
   },
 
   /**
    * Sets the currently active RecordingModel.
    * @param RecordingModel recording
    */
--- a/browser/devtools/performance/test/browser_perf-compatibility-01.js
+++ b/browser/devtools/performance/test/browser_perf-compatibility-01.js
@@ -20,17 +20,19 @@ function spawnTest () {
 
   let {
     profilerStartTime,
     timelineStartTime,
     memoryStartTime
   } = yield front.startRecording({
     withTicks: true,
     withMemory: true,
-    withAllocations: true
+    withAllocations: true,
+    allocationsSampleProbability: +Services.prefs.getCharPref(MEMORY_SAMPLE_PROB_PREF),
+    allocationsMaxLogLength: Services.prefs.getIntPref(MEMORY_MAX_LOG_LEN_PREF)
   });
 
   ok(typeof profilerStartTime === "number",
     "The front.startRecording() emits a profiler start time.");
   ok(typeof timelineStartTime === "number",
     "The front.startRecording() emits a timeline start time.");
   ok(typeof memoryStartTime === "number",
     "The front.startRecording() emits a memory start time.");
--- a/browser/devtools/performance/test/browser_perf-compatibility-03.js
+++ b/browser/devtools/performance/test/browser_perf-compatibility-03.js
@@ -19,17 +19,19 @@ function spawnTest () {
 
   let {
     profilerStartTime,
     timelineStartTime,
     memoryStartTime
   } = yield front.startRecording({
     withTicks: true,
     withMemory: true,
-    withAllocations: true
+    withAllocations: true,
+    allocationsSampleProbability: +Services.prefs.getCharPref(MEMORY_SAMPLE_PROB_PREF),
+    allocationsMaxLogLength: Services.prefs.getIntPref(MEMORY_MAX_LOG_LEN_PREF)
   });
 
   ok(typeof profilerStartTime === "number",
     "The front.startRecording() emits a profiler start time.");
   ok(typeof timelineStartTime === "number",
     "The front.startRecording() emits a timeline start time.");
   ok(typeof memoryStartTime === "number",
     "The front.startRecording() emits a memory start time.");
--- a/browser/devtools/performance/test/browser_perf-front.js
+++ b/browser/devtools/performance/test/browser_perf-front.js
@@ -5,65 +5,67 @@
  * Test basic functionality of PerformanceFront, emitting start and endtime values
  */
 
 let WAIT_TIME = 1000;
 
 function spawnTest () {
   let { target, front } = yield initBackend(SIMPLE_URL);
 
-  let count = 0;
-  let counter = () => count++;
-
   let {
     profilerStartTime,
     timelineStartTime,
     memoryStartTime
   } = yield front.startRecording({
-    withAllocations: true
+    withAllocations: true,
+    allocationsSampleProbability: +Services.prefs.getCharPref(MEMORY_SAMPLE_PROB_PREF),
+    allocationsMaxLogLength: Services.prefs.getIntPref(MEMORY_MAX_LOG_LEN_PREF)
   });
 
+  let allocationsCount = 0;
+  let allocationsCounter = () => allocationsCount++;
+
+  // Record allocation events to ensure it's called more than once
+  // so we know it's polling
+  front.on("allocations", allocationsCounter);
+
   ok(typeof profilerStartTime === "number",
     "The front.startRecording() emits a profiler start time.");
   ok(typeof timelineStartTime === "number",
     "The front.startRecording() emits a timeline start time.");
   ok(typeof memoryStartTime === "number",
     "The front.startRecording() emits a memory start time.");
 
-  // Record allocation events to ensure it's called more than once
-  // so we know it's polling
-  front.on("allocations", counter);
-
   yield Promise.all([
     busyWait(WAIT_TIME),
-    waitUntil(() => count > 1)
+    waitUntil(() => allocationsCount > 1)
   ]);
 
   let {
     profilerEndTime,
     timelineEndTime,
     memoryEndTime
   } = yield front.stopRecording({
     withAllocations: true
   });
 
-  front.off("allocations", counter);
+  front.off("allocations", allocationsCounter);
 
   ok(typeof profilerEndTime === "number",
     "The front.stopRecording() emits a profiler end time.");
   ok(typeof timelineEndTime === "number",
     "The front.stopRecording() emits a timeline end time.");
   ok(typeof memoryEndTime === "number",
     "The front.stopRecording() emits a memory end time.");
 
   ok(profilerEndTime > profilerStartTime,
     "The profilerEndTime is after profilerStartTime.");
   ok(timelineEndTime > timelineStartTime,
     "The timelineEndTime is after timelineStartTime.");
   ok(memoryEndTime > memoryStartTime,
     "The memoryEndTime is after memoryStartTime.");
 
   is((yield front._request("memory", "getState")), "detached",
-    "memory actor is detached when stopping recording with allocations");
+    "Memory actor is detached when stopping recording with allocations.");
 
   yield removeTab(target.tab);
   finish();
 }
--- a/browser/devtools/performance/test/browser_perf-options-allocations.js
+++ b/browser/devtools/performance/test/browser_perf-options-allocations.js
@@ -5,29 +5,29 @@
 /**
  * Tests that setting the `devtools.performance.memory.` prefs propagate to the memory actor.
  */
 function spawnTest () {
   let { panel } = yield initPerformance(SIMPLE_URL);
   let { EVENTS, PerformanceController, $, gFront } = panel.panelWin;
   Services.prefs.setBoolPref(MEMORY_PREF, true);
 
-  let originalProbability = Services.prefs.getCharPref("devtools.performance.memory.sample-probability");
-  let originalLogLength = Services.prefs.getIntPref("devtools.performance.memory.max-log-length");
+  let originalProbability = Services.prefs.getCharPref(MEMORY_SAMPLE_PROB_PREF);
+  let originalLogLength = Services.prefs.getIntPref(MEMORY_MAX_LOG_LEN_PREF);
 
-  Services.prefs.setCharPref("devtools.performance.memory.sample-probability", "0.213");
-  Services.prefs.setIntPref("devtools.performance.memory.max-log-length", 777777);
+  Services.prefs.setCharPref(MEMORY_SAMPLE_PROB_PREF, "0.213");
+  Services.prefs.setIntPref(MEMORY_MAX_LOG_LEN_PREF, 777777);
 
   yield startRecording(panel);
 
   let { probability, maxLogLength } = yield gFront._request("memory", "getAllocationsSettings");
 
   yield stopRecording(panel);
 
   is(probability, 0.213, "allocations probability option is set on memory actor");
   is(maxLogLength, 777777, "allocations max log length option is set on memory actor");
 
   Services.prefs.setBoolPref(MEMORY_PREF, false);
-  Services.prefs.setCharPref("devtools.performance.memory.sample-probability", originalProbability);
-  Services.prefs.setIntPref("devtools.performance.memory.max-log-length", originalLogLength);
+  Services.prefs.setCharPref(MEMORY_SAMPLE_PROB_PREF, originalProbability);
+  Services.prefs.setIntPref(MEMORY_MAX_LOG_LEN_PREF, originalLogLength);
   yield teardown(panel);
   finish();
 }
--- a/browser/devtools/performance/test/head.js
+++ b/browser/devtools/performance/test/head.js
@@ -18,18 +18,22 @@ let { getPerformanceActorsConnection, Pe
 let nsIProfilerModule = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
 let TargetFactory = devtools.TargetFactory;
 let mm = null;
 
 const FRAME_SCRIPT_UTILS_URL = "chrome://browser/content/devtools/frame-script-utils.js"
 const EXAMPLE_URL = "http://example.com/browser/browser/devtools/performance/test/";
 const SIMPLE_URL = EXAMPLE_URL + "doc_simple-test.html";
 
+const MEMORY_SAMPLE_PROB_PREF = "devtools.performance.memory.sample-probability";
+const MEMORY_MAX_LOG_LEN_PREF = "devtools.performance.memory.max-log-length";
+
 const FRAMERATE_PREF = "devtools.performance.ui.enable-framerate";
 const MEMORY_PREF = "devtools.performance.ui.enable-memory";
+
 const PLATFORM_DATA_PREF = "devtools.performance.ui.show-platform-data";
 const IDLE_PREF = "devtools.performance.ui.show-idle-blocks";
 const INVERT_PREF = "devtools.performance.ui.invert-call-tree";
 const INVERT_FLAME_PREF = "devtools.performance.ui.invert-flame-graph";
 const FLATTEN_PREF = "devtools.performance.ui.flatten-tree-recursion";
 
 // All tests are asynchronous.
 waitForExplicitFinish();