Bug 1290142 - Lint devtools/client/performance/legacy; r?jsantell
MozReview-Commit-ID: 9zX19SxK8rw
--- a/.eslintignore
+++ b/.eslintignore
@@ -79,17 +79,16 @@ devtools/client/canvasdebugger/**
devtools/client/commandline/**
devtools/client/debugger/**
devtools/client/eyedropper/**
devtools/client/framework/**
devtools/client/jsonview/lib/**
devtools/client/memory/**
devtools/client/netmonitor/test/**
devtools/client/netmonitor/har/test/**
-devtools/client/performance/legacy/**
devtools/client/performance/modules/**
devtools/client/performance/test/**
devtools/client/projecteditor/**
devtools/client/promisedebugger/**
devtools/client/responsivedesign/**
devtools/client/scratchpad/**
devtools/client/shadereditor/**
devtools/client/shared/*.jsm
--- a/devtools/client/performance/legacy/actors.js
+++ b/devtools/client/performance/legacy/actors.js
@@ -1,26 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Task } = require("devtools/shared/task");
-const promise = require("promise");
const EventEmitter = require("devtools/shared/event-emitter");
const { Poller } = require("devtools/client/shared/poller");
const CompatUtils = require("devtools/client/performance/legacy/compatibility");
const RecordingUtils = require("devtools/shared/performance/recording-utils");
const { TimelineFront } = require("devtools/shared/fronts/timeline");
const { ProfilerFront } = require("devtools/shared/fronts/profiler");
-// how often do we check the status of the profiler's circular buffer
-const PROFILER_CHECK_TIMER = 5000; // ms
+// How often do we check the status of the profiler's circular buffer in milliseconds.
+const PROFILER_CHECK_TIMER = 5000;
const TIMELINE_ACTOR_METHODS = [
"start", "stop",
];
const PROFILER_ACTOR_METHODS = [
"startProfiler", "getStartOptions", "stopProfiler",
"registerEventNotifications", "unregisterEventNotifications"
@@ -28,17 +27,18 @@ const PROFILER_ACTOR_METHODS = [
/**
* Constructor for a facade around an underlying ProfilerFront.
*/
function LegacyProfilerFront(target) {
this._target = target;
this._onProfilerEvent = this._onProfilerEvent.bind(this);
this._checkProfilerStatus = this._checkProfilerStatus.bind(this);
- this._PROFILER_CHECK_TIMER = this._target.TEST_MOCK_PROFILER_CHECK_TIMER || PROFILER_CHECK_TIMER;
+ this._PROFILER_CHECK_TIMER = this._target.TEST_MOCK_PROFILER_CHECK_TIMER ||
+ PROFILER_CHECK_TIMER;
EventEmitter.decorate(this);
}
LegacyProfilerFront.prototype = {
EVENTS: ["console-api-profiler", "profiler-stopped"],
// Connects to the targets underlying real ProfilerFront.
@@ -75,37 +75,46 @@ LegacyProfilerFront.prototype = {
* @option {number?} bufferSize
* @option {number?} sampleFrequency
*/
start: Task.async(function* (options = {}) {
// Check for poller status even if the profiler is already active --
// profiler can be activated via `console.profile` or another source, like
// the Gecko Profiler.
if (!this._poller) {
- this._poller = new Poller(this._checkProfilerStatus, this._PROFILER_CHECK_TIMER, false);
+ this._poller = new Poller(this._checkProfilerStatus, this._PROFILER_CHECK_TIMER,
+ false);
}
if (!this._poller.isPolling()) {
this._poller.on();
}
// Start the profiler only if it wasn't already active. The built-in
// nsIPerformance module will be kept recording, because it's the same instance
// for all targets and interacts with the whole platform, so we don't want
// to affect other clients by stopping (or restarting) it.
- let { isActive, currentTime, position, generation, totalSize } = yield this.getStatus();
+ let {
+ isActive,
+ currentTime,
+ position,
+ generation,
+ totalSize
+ } = yield this.getStatus();
if (isActive) {
return { startTime: currentTime, position, generation, totalSize };
}
// Translate options from the recording model into profiler-specific
// options for the nsIProfiler
let profilerOptions = {
entries: options.bufferSize,
- interval: options.sampleFrequency ? (1000 / (options.sampleFrequency * 1000)) : void 0
+ interval: options.sampleFrequency
+ ? (1000 / (options.sampleFrequency * 1000))
+ : void 0
};
let startInfo = yield this.startProfiler(profilerOptions);
let startTime = 0;
if ("currentTime" in startInfo) {
startTime = startInfo.currentTime;
}
@@ -124,17 +133,17 @@ LegacyProfilerFront.prototype = {
/**
* Wrapper around `profiler.isActive()` to take profiler status data and emit.
*/
getStatus: Task.async(function* () {
let data = yield (CompatUtils.callFrontMethod("isActive").call(this));
// If no data, the last poll for `isActive()` was wrapping up, and the target.client
// is now null, so we no longer have data, so just abort here.
if (!data) {
- return;
+ return undefined;
}
// If TEST_PROFILER_FILTER_STATUS defined (via array of fields), filter
// out any field from isActive, used only in tests. Used to filter out
// buffer status fields to simulate older geckos.
if (this._target.TEST_PROFILER_FILTER_STATUS) {
data = Object.keys(data).reduce((acc, prop) => {
if (this._target.TEST_PROFILER_FILTER_STATUS.indexOf(prop) === -1) {
@@ -147,25 +156,26 @@ LegacyProfilerFront.prototype = {
this.emit("profiler-status", data);
return data;
}),
/**
* Returns profile data from now since `startTime`.
*/
getProfile: Task.async(function* (options) {
- let profilerData = yield (CompatUtils.callFrontMethod("getProfile").call(this, options));
+ let profilerData = yield (CompatUtils.callFrontMethod("getProfile")
+ .call(this, options));
// If the backend is not deduped, dedupe it ourselves, as rest of the code
// expects a deduped profile.
if (profilerData.profile.meta.version === 2) {
RecordingUtils.deflateProfile(profilerData.profile);
}
- // If the backend does not support filtering by start and endtime on platform (< Fx40),
- // do it on the client (much slower).
+ // If the backend does not support filtering by start and endtime on
+ // platform (< Fx40), do it on the client (much slower).
if (!this.traits.filterable) {
RecordingUtils.filterSamples(profilerData.profile, options.startTime || 0);
}
return profilerData;
}),
/**
@@ -237,13 +247,17 @@ LegacyTimelineFront.prototype = {
_onTimelineData: function (type, ...data) {
this.emit("timeline-data", type, ...data);
},
toString: () => "[object LegacyTimelineFront]"
};
// Bind all the methods that directly proxy to the actor
-PROFILER_ACTOR_METHODS.forEach(m => LegacyProfilerFront.prototype[m] = CompatUtils.callFrontMethod(m));
-TIMELINE_ACTOR_METHODS.forEach(m => LegacyTimelineFront.prototype[m] = CompatUtils.callFrontMethod(m));
+PROFILER_ACTOR_METHODS.forEach(m => {
+ LegacyProfilerFront.prototype[m] = CompatUtils.callFrontMethod(m);
+});
+TIMELINE_ACTOR_METHODS.forEach(m => {
+ LegacyTimelineFront.prototype[m] = CompatUtils.callFrontMethod(m);
+});
exports.LegacyProfilerFront = LegacyProfilerFront;
exports.LegacyTimelineFront = LegacyTimelineFront;
--- a/devtools/client/performance/legacy/compatibility.js
+++ b/devtools/client/performance/legacy/compatibility.js
@@ -1,14 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-const promise = require("promise");
const EventEmitter = require("devtools/shared/event-emitter");
/**
* A dummy front decorated with the provided methods.
*
* @param array blueprint
* A list of [funcName, retVal] describing the class.
*/
@@ -51,17 +50,17 @@ function timelineActorSupported(target)
*/
function callFrontMethod(method) {
return function () {
// If there's no target or client on this actor facade,
// abort silently -- this occurs in tests when polling occurs
// after the test ends, when tests do not wait for toolbox destruction
// (which will destroy the actor facade, turning off the polling).
if (!this._target || !this._target.client) {
- return;
+ return undefined;
}
return this._front[method].apply(this._front, arguments);
};
}
exports.MockTimelineFront = MockTimelineFront;
exports.timelineActorSupported = timelineActorSupported;
exports.callFrontMethod = callFrontMethod;
--- a/devtools/client/performance/legacy/front.js
+++ b/devtools/client/performance/legacy/front.js
@@ -1,14 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-const { Cu } = require("chrome");
const { Task } = require("devtools/shared/task");
const Services = require("Services");
const promise = require("promise");
const { extend } = require("sdk/util/object");
const Actors = require("devtools/client/performance/legacy/actors");
const { LegacyPerformanceRecording } = require("devtools/client/performance/legacy/recording");
@@ -78,16 +77,17 @@ const LegacyPerformanceFront = Class({
// Sets `this._profiler`, `this._timeline`.
// Only initialize the timeline fronts if the respective actors
// are available. Older Gecko versions don't have existing implementations,
// in which case all the methods we need can be easily mocked.
yield this._connectActors();
yield this._registerListeners();
this._connecting.resolve();
+ return this._connecting.promise;
}),
/**
* Destroys this connection.
*/
destroy: Task.async(function* () {
if (this._connecting) {
yield this._connecting.promise;
@@ -161,17 +161,18 @@ const LegacyPerformanceFront = Class({
* Invoked whenever `console.profile` is called.
*
* @param string profileLabel
* The provided string argument if available; undefined otherwise.
* @param number currentTime
* The time (in milliseconds) when the call was made, relative to when
* the nsIProfiler module was started.
*/
- _onConsoleProfileStart: Task.async(function* (_, { profileLabel, currentTime: startTime }) {
+ _onConsoleProfileStart: Task.async(function* (_, { profileLabel,
+ currentTime: startTime }) {
let recordings = this._recordings;
// Abort if a profile with this label already exists.
if (recordings.find(e => e.getLabel() === profileLabel)) {
return;
}
events.emit(this, "console-profile-start");
@@ -192,38 +193,38 @@ const LegacyPerformanceFront = Class({
* the nsIProfiler module was started.
*/
_onConsoleProfileStop: Task.async(function* (_, data) {
// If no data, abort; can occur if profiler isn't running and we get a surprise
// call to console.profileEnd()
if (!data) {
return;
}
- let { profileLabel, currentTime: endTime } = data;
+ let { profileLabel } = data;
let pending = this._recordings.filter(r => r.isConsole() && r.isRecording());
if (pending.length === 0) {
return;
}
let model;
// Try to find the corresponding `console.profile` call if
// a label was used in profileEnd(). If no matches, abort.
if (profileLabel) {
model = pending.find(e => e.getLabel() === profileLabel);
- }
- // If no label supplied, pop off the most recent pending console recording
- else {
+ } else {
+ // If no label supplied, pop off the most recent pending console recording
model = pending[pending.length - 1];
}
// If `profileEnd()` was called with a label, and there are no matching
// sessions, abort.
if (!model) {
- console.error("console.profileEnd() called with label that does not match a recording.");
+ console.error(
+ "console.profileEnd() called with label that does not match a recording.");
return;
}
yield this.stopRecording(model);
}),
/**
* TODO handle bug 1144438
@@ -259,22 +260,24 @@ const LegacyPerformanceFront = Class({
events.emit(this, "profiler-status", data);
},
/**
* Begins a recording session
*
* @param object options
* An options object to pass to the actors. Supported properties are
- * `withTicks`, `withMemory` and `withAllocations`, `probability`, and `maxLogLength`.
+ * `withTicks`, `withMemory` and `withAllocations`, `probability`, and
+ * `maxLogLength`.
* @return object
* A promise that is resolved once recording has started.
*/
startRecording: Task.async(function* (options = {}) {
- let model = new LegacyPerformanceRecording(normalizePerformanceFeatures(options, this.traits.features));
+ let model = new LegacyPerformanceRecording(
+ normalizePerformanceFeatures(options, this.traits.features));
// All actors are started asynchronously over the remote debugging protocol.
// Get the corresponding start times from each one of them.
// The timeline actors are target-dependent, so start those as well,
// even though these are mocked in older Geckos (FF < 35)
let profilerStart = this._profiler.start(options);
let timelineStart = this._timeline.start(options);
@@ -294,25 +297,26 @@ const LegacyPerformanceFront = Class({
events.emit(this, "recording-started", model);
return model;
}),
/**
* Manually ends the recording session for the corresponding LegacyPerformanceRecording.
*
* @param LegacyPerformanceRecording model
- * The corresponding LegacyPerformanceRecording that belongs to the recording session wished to stop.
+ * The corresponding LegacyPerformanceRecording that belongs to the recording
+ * session wished to stop.
* @return LegacyPerformanceRecording
* Returns the same model, populated with the profiling data.
*/
stopRecording: Task.async(function* (model) {
// If model isn't in the LegacyPerformanceFront internal store,
// then do nothing.
if (this._recordings.indexOf(model) === -1) {
- return;
+ return undefined;
}
// Flag the recording as no longer recording, so that `model.isRecording()`
// is false. Do this before we fetch all the data, and then subsequently
// the recording can be considered "completed".
let endTime = Date.now();
model._onStoppingRecording(endTime);
events.emit(this, "recording-stopping", model);
@@ -338,17 +342,16 @@ const LegacyPerformanceFront = Class({
// are only used in tests.
if (!this.isRecording()) {
// This doesn't stop the profiler, just turns off polling for
// events, and also turns off events on timeline actors.
yield this._profiler.stop();
timelineEndTime = yield this._timeline.stop(config);
}
- let systemDeferred = promise.defer();
let form = yield this._client.listTabs();
let systemHost = yield getDeviceFront(this._client, form).getDescription();
let systemClient = yield getSystemInfo();
// Set the results on the LegacyPerformanceRecording itself.
model._onStopRecording({
// Data available only at the end of a recording.
profile: profilerData.profile,
@@ -391,20 +394,28 @@ const LegacyPerformanceFront = Class({
*
* @param {PerformanceRecording} recording
* @return {number?}
*/
getBufferUsageForRecording: function (recording) {
if (!recording.isRecording() || !this._currentBufferStatus) {
return null;
}
- let { position: currentPosition, totalSize, generation: currentGeneration } = this._currentBufferStatus;
- let { position: origPosition, generation: origGeneration } = recording.getStartingBufferStatus();
+ let {
+ position: currentPosition,
+ totalSize,
+ generation: currentGeneration
+ } = this._currentBufferStatus;
+ let {
+ position: origPosition,
+ generation: origGeneration
+ } = recording.getStartingBufferStatus();
- let normalizedCurrent = (totalSize * (currentGeneration - origGeneration)) + currentPosition;
+ let normalizedCurrent = (totalSize * (currentGeneration - origGeneration))
+ + currentPosition;
let percent = (normalizedCurrent - origPosition) / totalSize;
return percent > 1 ? 1 : percent;
},
/**
* Returns the configurations set on underlying components, used in tests.
* Returns an object with `probability`, `maxLogLength` for allocations, and
* `entries` and `interval` for profiler.
@@ -446,22 +457,28 @@ const LegacyPerformanceFront = Class({
}
this._profiler._PROFILER_CHECK_TIMER = n;
},
toString: () => "[object LegacyPerformanceFront]"
});
/**
- * Creates an object of configurations based off of preferences for a LegacyPerformanceRecording.
+ * Creates an object of configurations based off of preferences for a
+ * LegacyPerformanceRecording.
*/
function getLegacyPerformanceRecordingPrefs() {
return {
withMarkers: true,
- withMemory: Services.prefs.getBoolPref("devtools.performance.ui.enable-memory"),
- withTicks: Services.prefs.getBoolPref("devtools.performance.ui.enable-framerate"),
- withAllocations: Services.prefs.getBoolPref("devtools.performance.ui.enable-allocations"),
- allocationsSampleProbability: +Services.prefs.getCharPref("devtools.performance.memory.sample-probability"),
- allocationsMaxLogLength: Services.prefs.getIntPref("devtools.performance.memory.max-log-length")
+ withMemory: Services.prefs.getBoolPref(
+ "devtools.performance.ui.enable-memory"),
+ withTicks: Services.prefs.getBoolPref(
+ "devtools.performance.ui.enable-framerate"),
+ withAllocations: Services.prefs.getBoolPref(
+ "devtools.performance.ui.enable-allocations"),
+ allocationsSampleProbability: +Services.prefs.getCharPref(
+ "devtools.performance.memory.sample-probability"),
+ allocationsMaxLogLength: Services.prefs.getIntPref(
+ "devtools.performance.memory.max-log-length")
};
}
exports.LegacyPerformanceFront = LegacyPerformanceFront;
--- a/devtools/client/performance/legacy/recording.js
+++ b/devtools/client/performance/legacy/recording.js
@@ -1,14 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-const { Cc, Ci, Cu, Cr } = require("chrome");
const { Task } = require("devtools/shared/task");
const PerformanceIO = require("devtools/client/performance/modules/io");
const RecordingUtils = require("devtools/shared/performance/recording-utils");
const { PerformanceRecordingCommon } = require("devtools/shared/performance/recording-common");
const { merge } = require("sdk/util/object");
/**
@@ -89,17 +88,18 @@ LegacyPerformanceRecording.prototype = m
this._duration = endTime - this._localStartTime;
this._recording = false;
},
/**
* Sets results available from stopping a recording from PerformanceFront.
* Should only be called by PerformanceFront.
*/
- _onStopRecording: Task.async(function* ({ profilerEndTime, profile, systemClient, systemHost }) {
+ _onStopRecording: Task.async(function* ({ profilerEndTime, profile, systemClient,
+ systemHost }) {
// Update the duration with the accurate profilerEndTime, so we don't have
// samples outside of the approximate duration set in `_onStoppingRecording`.
this._duration = profilerEndTime - this._profilerStartTime;
this._profile = profile;
this._completed = true;
// We filter out all samples that fall out of current profile's range
// since the profiler is continuously running. Because of this, sample
@@ -134,32 +134,38 @@ LegacyPerformanceRecording.prototype = m
}
let config = this.getConfiguration();
switch (eventName) {
// Accumulate timeline markers into an array. Furthermore, the timestamps
// do not have a zero epoch, so offset all of them by the start time.
case "markers": {
- if (!config.withMarkers) { break; }
+ if (!config.withMarkers) {
+ break;
+ }
let [markers] = data;
RecordingUtils.offsetMarkerTimes(markers, this._timelineStartTime);
RecordingUtils.pushAll(this._markers, markers);
break;
}
// Accumulate stack frames into an array.
case "frames": {
- if (!config.withMarkers) { break; }
+ if (!config.withMarkers) {
+ break;
+ }
let [, frames] = data;
RecordingUtils.pushAll(this._frames, frames);
break;
}
// Save the accumulated refresh driver ticks.
case "ticks": {
- if (!config.withTicks) { break; }
+ if (!config.withTicks) {
+ break;
+ }
let [, timestamps] = data;
this._ticks = timestamps;
break;
}
}
},
toString: () => "[object LegacyPerformanceRecording]"