Skip to content

Commit

Permalink
Bug 1265727 - Decouple EventLoopLagFront from EventLoopActor. r=fitzgen
Browse files Browse the repository at this point in the history
  • Loading branch information
ejpbruel committed Jul 21, 2016
1 parent 55401c8 commit 34cdf87
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 31 deletions.
2 changes: 1 addition & 1 deletion b2g/chrome/content/devtools/hud.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ XPCOMUtils.defineLazyGetter(this, 'WebConsoleUtils', function() {
});

XPCOMUtils.defineLazyGetter(this, 'EventLoopLagFront', function() {
return devtools.require('devtools/server/actors/eventlooplag').EventLoopLagFront;
return devtools.require('devtools/shared/fronts/eventlooplag').EventLoopLagFront;
});

XPCOMUtils.defineLazyGetter(this, 'PerformanceEntriesFront', function() {
Expand Down
37 changes: 8 additions & 29 deletions devtools/server/actors/eventlooplag.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,38 @@
const {Ci} = require("chrome");
const Services = require("Services");
const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
const protocol = require("devtools/shared/protocol");
const {method, Arg, RetVal} = protocol;
const {Actor, ActorClassWithSpec} = require("devtools/shared/protocol");
const events = require("sdk/event/core");
const {eventLoopLagSpec} = require("devtools/shared/specs/eventlooplag");

var EventLoopLagActor = exports.EventLoopLagActor = protocol.ActorClass({

typeName: "eventLoopLag",

var EventLoopLagActor = exports.EventLoopLagActor = ActorClassWithSpec(eventLoopLagSpec, {
_observerAdded: false,

events: {
"event-loop-lag" : {
type: "event-loop-lag",
time: Arg(0, "number") // duration of the lag in milliseconds.
}
},

/**
* Start tracking the event loop lags.
*/
start: method(function () {
start: function () {
if (!this._observerAdded) {
Services.obs.addObserver(this, "event-loop-lag", false);
this._observerAdded = true;
}
return Services.appShell.startEventLoopLagTracking();
}, {
request: {},
response: {success: RetVal("number")}
}),
},

/**
* Stop tracking the event loop lags.
*/
stop: method(function () {
stop: function () {
if (this._observerAdded) {
Services.obs.removeObserver(this, "event-loop-lag");
this._observerAdded = false;
}
Services.appShell.stopEventLoopLagTracking();
}, {request: {}, response: {}}),
},

destroy: function () {
this.stop();
protocol.Actor.prototype.destroy.call(this);
Actor.prototype.destroy.call(this);
},

// nsIObserver
Expand All @@ -71,11 +58,3 @@ var EventLoopLagActor = exports.EventLoopLagActor = protocol.ActorClass({

QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
});

exports.EventLoopLagFront = protocol.FrontClass(EventLoopLagActor, {
initialize: function (client, form) {
protocol.Front.prototype.initialize.call(this, client);
this.actorID = form.eventLoopLagActor;
this.manage(this);
},
});
2 changes: 1 addition & 1 deletion devtools/server/tests/unit/test_eventlooplag_actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

function run_test()
{
let {EventLoopLagFront} = require("devtools/server/actors/eventlooplag");
let {EventLoopLagFront} = require("devtools/shared/fronts/eventlooplag");

DebuggerServer.init();
DebuggerServer.addBrowserActors();
Expand Down
15 changes: 15 additions & 0 deletions devtools/shared/fronts/eventlooplag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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 { Front, FrontClassWithSpec } = require("devtools/shared/protocol");
const { eventLoopLagSpec } = require("devtools/shared/specs/eventlooplag");

exports.EventLoopLagFront = FrontClassWithSpec(eventLoopLagSpec, {
initialize: function (client, form) {
Front.prototype.initialize.call(this, client);
this.actorID = form.eventLoopLagActor;
this.manage(this);
},
});
1 change: 1 addition & 0 deletions devtools/shared/fronts/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DevToolsModules(
'device.js',
'director-manager.js',
'director-registry.js',
'eventlooplag.js',
'framerate.js',
'gcli.js',
'highlighters.js',
Expand Down
31 changes: 31 additions & 0 deletions devtools/shared/specs/eventlooplag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* 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 { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol");

const eventLoopLagSpec = generateActorSpec({
typeName: "eventLoopLag",

events: {
"event-loop-lag": {
type: "event-loop-lag",
// duration of the lag in milliseconds.
time: Arg(0, "number")
}
},

methods: {
start: {
request: {},
response: {success: RetVal("number")}
},
stop: {
request: {},
response: {}
}
}
});

exports.eventLoopLagSpec = eventLoopLagSpec;
1 change: 1 addition & 0 deletions devtools/shared/specs/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DevToolsModules(
'director-manager.js',
'director-registry.js',
'environment.js',
'eventlooplag.js',
'frame.js',
'framerate.js',
'gcli.js',
Expand Down

0 comments on commit 34cdf87

Please sign in to comment.