diff --git a/devtools/server/performance/framerate.js b/devtools/server/performance/framerate.js index d775e10c8402..dc2287ef1529 100644 --- a/devtools/server/performance/framerate.js +++ b/devtools/server/performance/framerate.js @@ -4,30 +4,31 @@ "use strict"; const { on, off } = require("devtools/shared/event-emitter"); -const { Class } = require("sdk/core/heritage"); /** * A very simple utility for monitoring framerate. Takes a `tabActor` * and monitors framerate over time. The actor wrapper around this * can be found at devtools/server/actors/framerate.js */ -exports.Framerate = Class({ - initialize: function (tabActor) { +class Framerate { + constructor(tabActor) { this.tabActor = tabActor; this._contentWin = tabActor.window; this._onRefreshDriverTick = this._onRefreshDriverTick.bind(this); this._onGlobalCreated = this._onGlobalCreated.bind(this); + on(this.tabActor, "window-ready", this._onGlobalCreated); - }, - destroy: function (conn) { + } + + destroy(conn) { off(this.tabActor, "window-ready", this._onGlobalCreated); this.stopRecording(); - }, + } /** * Starts monitoring framerate, storing the frames per second. */ - startRecording: function () { + startRecording() { if (this._recording) { return; } @@ -35,65 +36,67 @@ exports.Framerate = Class({ this._ticks = []; this._startTime = this.tabActor.docShell.now(); this._rafID = this._contentWin.requestAnimationFrame(this._onRefreshDriverTick); - }, + } /** * Stops monitoring framerate, returning the recorded values. */ - stopRecording: function (beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) { + stopRecording(beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) { if (!this._recording) { return []; } let ticks = this.getPendingTicks(beginAt, endAt); this.cancelRecording(); return ticks; - }, + } /** * Stops monitoring framerate, without returning the recorded values. */ - cancelRecording: function () { + cancelRecording() { this._contentWin.cancelAnimationFrame(this._rafID); this._recording = false; this._ticks = null; this._rafID = -1; - }, + } /** * Returns whether this instance is currently recording. */ - isRecording: function () { + isRecording() { return !!this._recording; - }, + } /** * Gets the refresh driver ticks recorded so far. */ - getPendingTicks: function (beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) { + getPendingTicks(beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) { if (!this._ticks) { return []; } return this._ticks.filter(e => e >= beginAt && e <= endAt); - }, + } /** * Function invoked along with the refresh driver. */ - _onRefreshDriverTick: function () { + _onRefreshDriverTick() { if (!this._recording) { return; } this._rafID = this._contentWin.requestAnimationFrame(this._onRefreshDriverTick); this._ticks.push(this.tabActor.docShell.now() - this._startTime); - }, + } /** * When the content window for the tab actor is created. */ - _onGlobalCreated: function (win) { + _onGlobalCreated(win) { if (this._recording) { this._contentWin.cancelAnimationFrame(this._rafID); this._rafID = this._contentWin.requestAnimationFrame(this._onRefreshDriverTick); } } -}); +} + +exports.Framerate = Framerate; diff --git a/devtools/server/performance/memory.js b/devtools/server/performance/memory.js index ca0ebc420731..3f497ad9a4c6 100644 --- a/devtools/server/performance/memory.js +++ b/devtools/server/performance/memory.js @@ -6,8 +6,8 @@ const { Cc, Ci, Cu } = require("chrome"); const { reportException } = require("devtools/shared/DevToolsUtils"); -const { Class } = require("sdk/core/heritage"); const { expectState } = require("devtools/server/actors/common"); + loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter"); loader.lazyRequireGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm", true); @@ -31,27 +31,24 @@ loader.lazyRequireGetter(this, "ChildProcessActor", * send information over RDP, and TimelineActor for using more light-weight * utilities like GC events and measuring memory consumption. */ -exports.Memory = Class({ - extends: EventEmitter, +function Memory(parent, frameCache = new StackFrameCache()) { + EventEmitter.decorate(this); - /** - * Requires a root actor and a StackFrameCache. - */ - initialize: function (parent, frameCache = new StackFrameCache()) { - this.parent = parent; - this._mgr = Cc["@mozilla.org/memory-reporter-manager;1"] - .getService(Ci.nsIMemoryReporterManager); - this.state = "detached"; - this._dbg = null; - this._frameCache = frameCache; + this.parent = parent; + this._mgr = Cc["@mozilla.org/memory-reporter-manager;1"] + .getService(Ci.nsIMemoryReporterManager); + this.state = "detached"; + this._dbg = null; + this._frameCache = frameCache; - this._onGarbageCollection = this._onGarbageCollection.bind(this); - this._emitAllocations = this._emitAllocations.bind(this); - this._onWindowReady = this._onWindowReady.bind(this); + this._onGarbageCollection = this._onGarbageCollection.bind(this); + this._emitAllocations = this._emitAllocations.bind(this); + this._onWindowReady = this._onWindowReady.bind(this); - EventEmitter.on(this.parent, "window-ready", this._onWindowReady); - }, + EventEmitter.on(this.parent, "window-ready", this._onWindowReady); +} +Memory.prototype = { destroy: function () { EventEmitter.off(this.parent, "window-ready", this._onWindowReady); @@ -426,5 +423,6 @@ exports.Memory = Class({ return (this.parent.isRootActor ? this.parent.docShell : this.parent.originalDocShell).now(); }, +}; -}); +exports.Memory = Memory; diff --git a/devtools/server/performance/profiler.js b/devtools/server/performance/profiler.js index 3b9cf94c4d78..147ab884ed99 100644 --- a/devtools/server/performance/profiler.js +++ b/devtools/server/performance/profiler.js @@ -5,7 +5,7 @@ const { Cc, Ci, Cu } = require("chrome"); const Services = require("Services"); -const { Class } = require("sdk/core/heritage"); + loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter"); loader.lazyRequireGetter(this, "DevToolsUtils", "devtools/shared/DevToolsUtils"); loader.lazyRequireGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm", true); @@ -406,82 +406,83 @@ const ProfilerManager = (function () { /** * The profiler actor provides remote access to the built-in nsIProfiler module. */ -var Profiler = exports.Profiler = Class({ - extends: EventEmitter, +class Profiler { + constructor() { + EventEmitter.decorate(this); - initialize: function () { this.subscribedEvents = new Set(); ProfilerManager.addInstance(this); - }, + } - destroy: function () { + destroy() { this.unregisterEventNotifications({ events: Array.from(this.subscribedEvents) }); this.subscribedEvents = null; + ProfilerManager.removeInstance(this); - }, + } /** * @see ProfilerManager.start */ - start: function (options) { + start(options) { return ProfilerManager.start(options); - }, + } /** * @see ProfilerManager.stop */ - stop: function () { + stop() { return ProfilerManager.stop(); - }, + } /** * @see ProfilerManager.getProfile */ - getProfile: function (request = {}) { + getProfile(request = {}) { return ProfilerManager.getProfile(request); - }, + } /** * @see ProfilerManager.getFeatures */ - getFeatures: function () { + getFeatures() { return ProfilerManager.getFeatures(); - }, + } /** * @see ProfilerManager.getBufferInfo */ - getBufferInfo: function () { + getBufferInfo() { return ProfilerManager.getBufferInfo(); - }, + } /** * @see ProfilerManager.getStartOptions */ - getStartOptions: function () { + getStartOptions() { return ProfilerManager.getStartOptions(); - }, + } /** * @see ProfilerManager.isActive */ - isActive: function () { + isActive() { return ProfilerManager.isActive(); - }, + } /** * @see ProfilerManager.sharedLibraries */ - sharedLibraries: function () { + sharedLibraries() { return ProfilerManager.sharedLibraries; - }, + } /** * @see ProfilerManager.setProfilerStatusInterval */ - setProfilerStatusInterval: function (interval) { + setProfilerStatusInterval(interval) { return ProfilerManager.setProfilerStatusInterval(interval); - }, + } /** * Subscribes this instance to one of several events defined in @@ -494,7 +495,7 @@ var Profiler = exports.Profiler = Class({ * @param {Array} data.event * @return {object} */ - registerEventNotifications: function (data = {}) { + registerEventNotifications(data = {}) { let response = []; (data.events || []).forEach(e => { if (!this.subscribedEvents.has(e)) { @@ -506,7 +507,7 @@ var Profiler = exports.Profiler = Class({ } }); return { registered: response }; - }, + } /** * Unsubscribes this instance to one of several events defined in @@ -515,7 +516,7 @@ var Profiler = exports.Profiler = Class({ * @param {Array} data.event * @return {object} */ - unregisterEventNotifications: function (data = {}) { + unregisterEventNotifications(data = {}) { let response = []; (data.events || []).forEach(e => { if (this.subscribedEvents.has(e)) { @@ -527,16 +528,16 @@ var Profiler = exports.Profiler = Class({ } }); return { registered: response }; - }, -}); + } -/** - * Checks whether or not the profiler module can currently run. - * @return boolean - */ -Profiler.canProfile = function () { - return nsIProfilerModule.CanProfile(); -}; + /** + * Checks whether or not the profiler module can currently run. + * @return boolean + */ + static canProfile() { + return nsIProfilerModule.CanProfile(); + } +} /** * JSON.stringify callback used in Profiler.prototype.observe. @@ -572,3 +573,5 @@ function sanitizeHandler(handler, identifier) { return handler.call(this, subject, topic, data); }, identifier); } + +exports.Profiler = Profiler; diff --git a/devtools/server/performance/recorder.js b/devtools/server/performance/recorder.js index 09addcf71d0c..24c37741a6e8 100644 --- a/devtools/server/performance/recorder.js +++ b/devtools/server/performance/recorder.js @@ -47,20 +47,20 @@ const DRAIN_ALLOCATIONS_TIMEOUT = 2000; * @param Target target * The target owning this connection. */ -exports.PerformanceRecorder = Class({ - extends: EventEmitter, +function PerformanceRecorder(conn, tabActor) { + EventEmitter.decorate(this); - initialize: function (conn, tabActor) { - this.conn = conn; - this.tabActor = tabActor; + this.conn = conn; + this.tabActor = tabActor; - this._pendingConsoleRecordings = []; - this._recordings = []; + this._pendingConsoleRecordings = []; + this._recordings = []; - this._onTimelineData = this._onTimelineData.bind(this); - this._onProfilerEvent = this._onProfilerEvent.bind(this); - }, + this._onTimelineData = this._onTimelineData.bind(this); + this._onProfilerEvent = this._onProfilerEvent.bind(this); +} +PerformanceRecorder.prototype = { /** * Initializes a connection to the profiler and other miscellaneous actors. * If in the process of opening, or already open, nothing happens. @@ -479,7 +479,7 @@ exports.PerformanceRecorder = Class({ }, toString: () => "[object PerformanceRecorder]" -}); +}; /** * Creates an object of configurations based off of @@ -498,3 +498,5 @@ function getPerformanceRecordingPrefs() { Services.prefs.getIntPref("devtools.performance.memory.max-log-length") }; } + +exports.PerformanceRecorder = PerformanceRecorder; diff --git a/devtools/server/performance/timeline.js b/devtools/server/performance/timeline.js index ad65088394e8..27b1b04435cd 100644 --- a/devtools/server/performance/timeline.js +++ b/devtools/server/performance/timeline.js @@ -21,7 +21,7 @@ */ const { Ci, Cu } = require("chrome"); -const { Class } = require("sdk/core/heritage"); + // Be aggressive about lazy loading, as this will run on every // toolbox startup loader.lazyRequireGetter(this, "Task", "devtools/shared/task", true); @@ -38,25 +38,23 @@ const DEFAULT_TIMELINE_DATA_PULL_TIMEOUT = 200; /** * The timeline actor pops and forwards timeline markers registered in docshells. */ -exports.Timeline = Class({ - extends: EventEmitter, - /** - * Initializes this actor with the provided connection and tab actor. - */ - initialize: function (tabActor) { - this.tabActor = tabActor; +function Timeline(tabActor) { + EventEmitter.decorate(this); - this._isRecording = false; - this._stackFrames = null; - this._memory = null; - this._framerate = null; + this.tabActor = tabActor; - // Make sure to get markers from new windows as they become available - this._onWindowReady = this._onWindowReady.bind(this); - this._onGarbageCollection = this._onGarbageCollection.bind(this); - EventEmitter.on(this.tabActor, "window-ready", this._onWindowReady); - }, + this._isRecording = false; + this._stackFrames = null; + this._memory = null; + this._framerate = null; + // Make sure to get markers from new windows as they become available + this._onWindowReady = this._onWindowReady.bind(this); + this._onGarbageCollection = this._onGarbageCollection.bind(this); + EventEmitter.on(this.tabActor, "window-ready", this._onWindowReady); +} + +Timeline.prototype = { /** * Destroys this actor, stopping recording first. */ @@ -357,4 +355,6 @@ exports.Timeline = Class({ }; }), endTime); }, -}); +}; + +exports.Timeline = Timeline;