2014-01-31 10:01:58 -08:00
|
|
|
/* 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';
|
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
const DEVELOPER_HUD_LOG_PREFIX = 'DeveloperHUD';
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, 'devtools', function() {
|
|
|
|
const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
|
|
|
return devtools;
|
|
|
|
});
|
2014-01-31 10:01:58 -08:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, 'DebuggerClient', function() {
|
|
|
|
return Cu.import('resource://gre/modules/devtools/dbg-client.jsm', {}).DebuggerClient;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, 'WebConsoleUtils', function() {
|
|
|
|
return devtools.require("devtools/toolkit/webconsole/utils").Utils;
|
|
|
|
});
|
|
|
|
|
2014-02-14 08:52:14 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, 'EventLoopLagFront', function() {
|
|
|
|
return devtools.require("devtools/server/actors/eventlooplag").EventLoopLagFront;
|
|
|
|
});
|
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, 'MemoryFront', function() {
|
|
|
|
return devtools.require("devtools/server/actors/memory").MemoryFront;
|
|
|
|
});
|
|
|
|
|
2014-02-14 08:52:14 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
/**
|
2014-02-26 13:58:37 -08:00
|
|
|
* The Developer HUD is an on-device developer tool that displays widgets,
|
2014-01-31 10:01:58 -08:00
|
|
|
* showing visual debug information about apps. Each widget corresponds to a
|
|
|
|
* metric as tracked by a metric watcher (e.g. consoleWatcher).
|
|
|
|
*/
|
2014-02-26 13:58:37 -08:00
|
|
|
let developerHUD = {
|
2014-01-31 10:01:58 -08:00
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
_targets: new Map(),
|
|
|
|
_frames: new Map(),
|
2014-01-31 10:01:58 -08:00
|
|
|
_client: null,
|
|
|
|
_webappsActor: null,
|
|
|
|
_watchers: [],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method registers a metric watcher that will watch one or more metrics
|
|
|
|
* of apps that are being tracked. A watcher must implement the trackApp(app)
|
|
|
|
* and untrackApp(app) methods, add entries to the app.metrics map, keep them
|
|
|
|
* up-to-date, and call app.display() when values were changed.
|
|
|
|
*/
|
|
|
|
registerWatcher: function dwp_registerWatcher(watcher) {
|
|
|
|
this._watchers.unshift(watcher);
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function dwp_init() {
|
|
|
|
if (this._client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
RemoteDebugger.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._client = new DebuggerClient(DebuggerServer.connectPipe());
|
|
|
|
this._client.connect((type, traits) => {
|
|
|
|
|
|
|
|
// FIXME(Bug 962577) see below.
|
|
|
|
this._client.listTabs((res) => {
|
|
|
|
this._webappsActor = res.webappsActor;
|
|
|
|
|
|
|
|
for (let w of this._watchers) {
|
|
|
|
if (w.init) {
|
|
|
|
w.init(this._client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
Services.obs.addObserver(this, 'remote-browser-shown', false);
|
2014-02-20 14:19:18 -08:00
|
|
|
Services.obs.addObserver(this, 'inprocess-browser-shown', false);
|
2014-01-31 10:01:58 -08:00
|
|
|
Services.obs.addObserver(this, 'message-manager-disconnect', false);
|
2014-02-06 07:06:25 -08:00
|
|
|
|
2014-02-14 16:45:45 -08:00
|
|
|
let systemapp = document.querySelector('#systemapp');
|
2014-03-03 11:50:56 -08:00
|
|
|
this.trackFrame(systemapp);
|
2014-02-14 16:45:45 -08:00
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
let frames = systemapp.contentWindow.document.querySelectorAll('iframe[mozapp]');
|
2014-02-06 07:06:25 -08:00
|
|
|
for (let frame of frames) {
|
2014-03-03 11:50:56 -08:00
|
|
|
this.trackFrame(frame);
|
2014-02-06 07:06:25 -08:00
|
|
|
}
|
2014-01-31 10:01:58 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function dwp_uninit() {
|
|
|
|
if (!this._client)
|
|
|
|
return;
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
for (let frame of this._targets.keys()) {
|
|
|
|
this.untrackFrame(frame);
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
Services.obs.removeObserver(this, 'remote-browser-shown');
|
2014-02-20 14:19:18 -08:00
|
|
|
Services.obs.removeObserver(this, 'inprocess-browser-shown');
|
2014-01-31 10:01:58 -08:00
|
|
|
Services.obs.removeObserver(this, 'message-manager-disconnect');
|
|
|
|
|
|
|
|
this._client.close();
|
|
|
|
delete this._client;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method will ask all registered watchers to track and update metrics
|
2014-03-03 11:50:56 -08:00
|
|
|
* on an app frame.
|
2014-01-31 10:01:58 -08:00
|
|
|
*/
|
2014-03-03 11:50:56 -08:00
|
|
|
trackFrame: function dwp_trackFrame(frame) {
|
|
|
|
if (this._targets.has(frame))
|
2014-01-31 10:01:58 -08:00
|
|
|
return;
|
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
// FIXME(Bug 962577) Factor getAppActor out of webappsActor.
|
2014-01-31 10:01:58 -08:00
|
|
|
this._client.request({
|
|
|
|
to: this._webappsActor,
|
|
|
|
type: 'getAppActor',
|
2014-03-03 11:50:56 -08:00
|
|
|
manifestURL: frame.appManifestURL
|
2014-01-31 10:01:58 -08:00
|
|
|
}, (res) => {
|
|
|
|
if (res.error) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
let target = new Target(frame, res.actor);
|
|
|
|
this._targets.set(frame, target);
|
2014-01-31 10:01:58 -08:00
|
|
|
|
|
|
|
for (let w of this._watchers) {
|
2014-03-03 11:50:56 -08:00
|
|
|
w.trackTarget(target);
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
untrackFrame: function dwp_untrackFrame(frame) {
|
|
|
|
let target = this._targets.get(frame);
|
|
|
|
if (target) {
|
2014-01-31 10:01:58 -08:00
|
|
|
for (let w of this._watchers) {
|
2014-03-03 11:50:56 -08:00
|
|
|
w.untrackTarget(target);
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the metrics and call display() to clean up the front-end.
|
2014-03-03 11:50:56 -08:00
|
|
|
delete target.metrics;
|
|
|
|
target.display();
|
2014-01-31 10:01:58 -08:00
|
|
|
|
2014-03-04 06:51:34 -08:00
|
|
|
this._targets.delete(frame);
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function dwp_observe(subject, topic, data) {
|
|
|
|
if (!this._client)
|
|
|
|
return;
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
let frame;
|
2014-01-31 10:01:58 -08:00
|
|
|
|
|
|
|
switch(topic) {
|
|
|
|
|
|
|
|
// listen for frame creation in OOP (device) as well as in parent process (b2g desktop)
|
2014-03-03 11:50:56 -08:00
|
|
|
case 'remote-browser-shown':
|
2014-02-20 14:19:18 -08:00
|
|
|
case 'inprocess-browser-shown':
|
2014-01-31 10:01:58 -08:00
|
|
|
let frameLoader = subject;
|
|
|
|
// get a ref to the app <iframe>
|
|
|
|
frameLoader.QueryInterface(Ci.nsIFrameLoader);
|
2014-02-20 14:19:18 -08:00
|
|
|
// Ignore notifications that aren't from a BrowserOrApp
|
|
|
|
if (!frameLoader.ownerIsBrowserOrAppFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-03 11:50:56 -08:00
|
|
|
frame = frameLoader.ownerElement;
|
|
|
|
if (!frame.appManifestURL) // Ignore all frames but app frames
|
2014-01-31 10:01:58 -08:00
|
|
|
return;
|
2014-03-03 11:50:56 -08:00
|
|
|
this.trackFrame(frame);
|
|
|
|
this._frames.set(frameLoader.messageManager, frame);
|
2014-01-31 10:01:58 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Every time an iframe is destroyed, its message manager also is
|
|
|
|
case 'message-manager-disconnect':
|
|
|
|
let mm = subject;
|
2014-03-03 11:50:56 -08:00
|
|
|
frame = this._frames.get(mm);
|
|
|
|
if (!frame)
|
2014-01-31 10:01:58 -08:00
|
|
|
return;
|
2014-03-03 11:50:56 -08:00
|
|
|
this.untrackFrame(frame);
|
|
|
|
this._frames.delete(mm);
|
2014-01-31 10:01:58 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
log: function dwp_log(message) {
|
2014-02-26 13:58:37 -08:00
|
|
|
dump(DEVELOPER_HUD_LOG_PREFIX + ': ' + message + '\n');
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An App object represents all there is to know about a Firefox OS app that is
|
|
|
|
* being tracked, e.g. its manifest information, current values of watched
|
|
|
|
* metrics, and how to update these values on the front-end.
|
|
|
|
*/
|
2014-03-03 11:50:56 -08:00
|
|
|
function Target(frame, actor) {
|
|
|
|
this.frame = frame;
|
2014-01-31 10:01:58 -08:00
|
|
|
this.actor = actor;
|
|
|
|
this.metrics = new Map();
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
Target.prototype = {
|
|
|
|
display: function target_display() {
|
|
|
|
let data = {
|
|
|
|
metrics: []
|
|
|
|
};
|
2014-01-31 10:01:58 -08:00
|
|
|
|
|
|
|
let metrics = this.metrics;
|
|
|
|
if (metrics && metrics.size > 0) {
|
|
|
|
for (let name of metrics.keys()) {
|
|
|
|
data.metrics.push({name: name, value: metrics.get(name)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
shell.sendEvent(this.frame, 'developer-hud-update', Cu.cloneInto(data, this.frame));
|
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
// FIXME(after bug 963239 lands) return event.isDefaultPrevented();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-12 06:54:09 -08:00
|
|
|
* The Console Watcher tracks the following metrics in apps: reflows, warnings,
|
|
|
|
* and errors.
|
2014-01-31 10:01:58 -08:00
|
|
|
*/
|
|
|
|
let consoleWatcher = {
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
_targets: new Map(),
|
2014-02-12 06:54:09 -08:00
|
|
|
_watching: {
|
|
|
|
reflows: false,
|
|
|
|
warnings: false,
|
|
|
|
errors: false
|
|
|
|
},
|
2014-01-31 10:01:58 -08:00
|
|
|
_client: null,
|
|
|
|
|
|
|
|
init: function cw_init(client) {
|
|
|
|
this._client = client;
|
|
|
|
this.consoleListener = this.consoleListener.bind(this);
|
|
|
|
|
2014-02-12 06:54:09 -08:00
|
|
|
let watching = this._watching;
|
|
|
|
|
|
|
|
for (let key in watching) {
|
|
|
|
let metric = key;
|
2014-02-26 13:58:37 -08:00
|
|
|
SettingsListener.observe('hud.' + metric, false, watch => {
|
2014-02-12 06:54:09 -08:00
|
|
|
// Watch or unwatch the metric.
|
2014-02-26 13:58:37 -08:00
|
|
|
if (watching[metric] = watch) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If unwatched, remove any existing widgets for that metric.
|
2014-03-03 11:50:56 -08:00
|
|
|
for (let target of this._targets.values()) {
|
|
|
|
target.metrics.set(metric, 0);
|
|
|
|
target.display();
|
2014-02-12 06:54:09 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
client.addListener('logMessage', this.consoleListener);
|
|
|
|
client.addListener('pageError', this.consoleListener);
|
|
|
|
client.addListener('consoleAPICall', this.consoleListener);
|
|
|
|
client.addListener('reflowActivity', this.consoleListener);
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
trackTarget: function cw_trackTarget(target) {
|
|
|
|
target.metrics.set('reflows', 0);
|
|
|
|
target.metrics.set('warnings', 0);
|
|
|
|
target.metrics.set('errors', 0);
|
2014-01-31 10:01:58 -08:00
|
|
|
|
|
|
|
this._client.request({
|
2014-03-03 11:50:56 -08:00
|
|
|
to: target.actor.consoleActor,
|
2014-01-31 10:01:58 -08:00
|
|
|
type: 'startListeners',
|
|
|
|
listeners: ['LogMessage', 'PageError', 'ConsoleAPI', 'ReflowActivity']
|
|
|
|
}, (res) => {
|
2014-03-03 11:50:56 -08:00
|
|
|
this._targets.set(target.actor.consoleActor, target);
|
2014-01-31 10:01:58 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
untrackTarget: function cw_untrackTarget(target) {
|
2014-01-31 10:01:58 -08:00
|
|
|
this._client.request({
|
2014-03-03 11:50:56 -08:00
|
|
|
to: target.actor.consoleActor,
|
2014-01-31 10:01:58 -08:00
|
|
|
type: 'stopListeners',
|
|
|
|
listeners: ['LogMessage', 'PageError', 'ConsoleAPI', 'ReflowActivity']
|
|
|
|
}, (res) => { });
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
this._targets.delete(target.actor.consoleActor);
|
2014-01-31 10:01:58 -08:00
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
bump: function cw_bump(target, metric) {
|
2014-02-12 06:54:09 -08:00
|
|
|
if (!this._watching[metric]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
let metrics = target.metrics;
|
2014-01-31 10:01:58 -08:00
|
|
|
metrics.set(metric, metrics.get(metric) + 1);
|
2014-02-12 06:54:09 -08:00
|
|
|
return true;
|
2014-01-31 10:01:58 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
consoleListener: function cw_consoleListener(type, packet) {
|
2014-03-03 11:50:56 -08:00
|
|
|
let target = this._targets.get(packet.from);
|
2014-01-31 10:01:58 -08:00
|
|
|
let output = '';
|
|
|
|
|
|
|
|
switch (packet.type) {
|
|
|
|
|
|
|
|
case 'pageError':
|
|
|
|
let pageError = packet.pageError;
|
2014-02-12 06:54:09 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
if (pageError.warning || pageError.strict) {
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!this.bump(target, 'warnings')) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-31 10:01:58 -08:00
|
|
|
output = 'warning (';
|
|
|
|
} else {
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!this.bump(target, 'errors')) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-31 10:01:58 -08:00
|
|
|
output += 'error (';
|
|
|
|
}
|
2014-02-12 06:54:09 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
let {errorMessage, sourceName, category, lineNumber, columnNumber} = pageError;
|
|
|
|
output += category + '): "' + (errorMessage.initial || errorMessage) +
|
|
|
|
'" in ' + sourceName + ':' + lineNumber + ':' + columnNumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'consoleAPICall':
|
|
|
|
switch (packet.message.level) {
|
2014-02-12 06:54:09 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
case 'error':
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!this.bump(target, 'errors')) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-31 10:01:58 -08:00
|
|
|
output = 'error (console)';
|
|
|
|
break;
|
2014-02-12 06:54:09 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
case 'warn':
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!this.bump(target, 'warnings')) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-31 10:01:58 -08:00
|
|
|
output = 'warning (console)';
|
|
|
|
break;
|
2014-02-12 06:54:09 -08:00
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'reflowActivity':
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!this.bump(target, 'reflows')) {
|
2014-02-12 06:54:09 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-31 10:01:58 -08:00
|
|
|
let {start, end, sourceURL} = packet;
|
|
|
|
let duration = Math.round((end - start) * 100) / 100;
|
|
|
|
output = 'reflow: ' + duration + 'ms';
|
|
|
|
if (sourceURL) {
|
|
|
|
output += ' ' + this.formatSourceURL(packet);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!target.display()) {
|
2014-01-31 10:01:58 -08:00
|
|
|
// If the information was not displayed, log it.
|
2014-02-26 13:58:37 -08:00
|
|
|
developerHUD.log(output);
|
2014-01-31 10:01:58 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
formatSourceURL: function cw_formatSourceURL(packet) {
|
|
|
|
// Abbreviate source URL
|
|
|
|
let source = WebConsoleUtils.abbreviateSourceURL(packet.sourceURL);
|
|
|
|
|
|
|
|
// Add function name and line number
|
|
|
|
let {functionName, sourceLine} = packet;
|
|
|
|
source = 'in ' + (functionName || '<anonymousFunction>') +
|
|
|
|
', ' + source + ':' + sourceLine;
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
};
|
2014-02-26 13:58:37 -08:00
|
|
|
developerHUD.registerWatcher(consoleWatcher);
|
2014-02-14 08:52:14 -08:00
|
|
|
|
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
let eventLoopLagWatcher = {
|
2014-02-14 08:52:14 -08:00
|
|
|
_client: null,
|
|
|
|
_fronts: new Map(),
|
|
|
|
_active: false,
|
|
|
|
|
|
|
|
init: function(client) {
|
|
|
|
this._client = client;
|
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
SettingsListener.observe('hud.jank', false, this.settingsListener.bind(this));
|
2014-02-14 08:52:14 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
settingsListener: function(value) {
|
|
|
|
if (this._active == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._active = value;
|
|
|
|
|
|
|
|
// Toggle the state of existing fronts.
|
|
|
|
let fronts = this._fronts;
|
2014-03-03 11:50:56 -08:00
|
|
|
for (let target of fronts.keys()) {
|
2014-02-14 08:52:14 -08:00
|
|
|
if (value) {
|
2014-03-03 11:50:56 -08:00
|
|
|
fronts.get(target).start();
|
2014-02-14 08:52:14 -08:00
|
|
|
} else {
|
2014-03-03 11:50:56 -08:00
|
|
|
fronts.get(target).stop();
|
|
|
|
target.metrics.set('jank', 0);
|
|
|
|
target.display();
|
2014-02-14 08:52:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
trackTarget: function(target) {
|
|
|
|
target.metrics.set('jank', 0);
|
2014-02-14 08:52:14 -08:00
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
let front = new EventLoopLagFront(this._client, target.actor);
|
|
|
|
this._fronts.set(target, front);
|
2014-02-14 08:52:14 -08:00
|
|
|
|
|
|
|
front.on('event-loop-lag', time => {
|
2014-03-03 11:50:56 -08:00
|
|
|
target.metrics.set('jank', time);
|
2014-02-14 08:52:14 -08:00
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
if (!target.display()) {
|
2014-02-26 13:58:37 -08:00
|
|
|
developerHUD.log('jank: ' + time + 'ms');
|
2014-02-14 08:52:14 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this._active) {
|
|
|
|
front.start();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
untrackTarget: function(target) {
|
2014-02-14 08:52:14 -08:00
|
|
|
let fronts = this._fronts;
|
2014-03-03 11:50:56 -08:00
|
|
|
if (fronts.has(target)) {
|
|
|
|
fronts.get(target).destroy();
|
|
|
|
fronts.delete(target);
|
2014-02-14 08:52:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-02-26 13:58:37 -08:00
|
|
|
developerHUD.registerWatcher(eventLoopLagWatcher);
|
2014-02-14 08:52:14 -08:00
|
|
|
|
2014-02-26 13:58:37 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Memory Watcher uses devtools actors to track memory usage.
|
|
|
|
*/
|
|
|
|
let memoryWatcher = {
|
|
|
|
|
|
|
|
_client: null,
|
|
|
|
_fronts: new Map(),
|
|
|
|
_timers: new Map(),
|
|
|
|
_watching: {
|
|
|
|
jsobjects: false,
|
|
|
|
jsstrings: false,
|
|
|
|
jsother: false,
|
|
|
|
dom: false,
|
|
|
|
style: false,
|
|
|
|
other: false
|
|
|
|
},
|
|
|
|
_active: false,
|
|
|
|
|
|
|
|
init: function mw_init(client) {
|
|
|
|
this._client = client;
|
|
|
|
let watching = this._watching;
|
|
|
|
|
|
|
|
for (let key in watching) {
|
|
|
|
let category = key;
|
|
|
|
SettingsListener.observe('hud.' + category, false, watch => {
|
|
|
|
watching[category] = watch;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsListener.observe('hud.appmemory', false, enabled => {
|
|
|
|
if (this._active = enabled) {
|
2014-03-03 11:50:56 -08:00
|
|
|
for (let target of this._fronts.keys()) {
|
|
|
|
this.measure(target);
|
2014-02-26 13:58:37 -08:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-03 11:50:56 -08:00
|
|
|
for (let target of this._fronts.keys()) {
|
|
|
|
clearTimeout(this._timers.get(target));
|
|
|
|
target.metrics.set('memory', 0);
|
|
|
|
target.display();
|
2014-02-26 13:58:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
measure: function mw_measure(target) {
|
2014-02-26 13:58:37 -08:00
|
|
|
|
|
|
|
// TODO Also track USS (bug #976024).
|
|
|
|
|
|
|
|
let watch = this._watching;
|
2014-03-03 11:50:56 -08:00
|
|
|
let front = this._fronts.get(target);
|
2014-02-26 13:58:37 -08:00
|
|
|
|
|
|
|
front.measure().then((data) => {
|
|
|
|
|
|
|
|
let total = 0;
|
|
|
|
if (watch.jsobjects) {
|
|
|
|
total += parseInt(data.jsObjectsSize);
|
|
|
|
}
|
|
|
|
if (watch.jsstrings) {
|
|
|
|
total += parseInt(data.jsStringsSize);
|
|
|
|
}
|
|
|
|
if (watch.jsother) {
|
|
|
|
total += parseInt(data.jsOtherSize);
|
|
|
|
}
|
|
|
|
if (watch.dom) {
|
|
|
|
total += parseInt(data.domSize);
|
|
|
|
}
|
|
|
|
if (watch.style) {
|
|
|
|
total += parseInt(data.styleSize);
|
|
|
|
}
|
|
|
|
if (watch.other) {
|
|
|
|
total += parseInt(data.otherSize);
|
|
|
|
}
|
|
|
|
// TODO Also count images size (bug #976007).
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
target.metrics.set('memory', total);
|
|
|
|
target.display();
|
2014-02-26 13:58:37 -08:00
|
|
|
let duration = parseInt(data.jsMilliseconds) + parseInt(data.nonJSMilliseconds);
|
2014-03-03 11:50:56 -08:00
|
|
|
let timer = setTimeout(() => this.measure(target), 100 * duration);
|
|
|
|
this._timers.set(target, timer);
|
2014-02-26 13:58:37 -08:00
|
|
|
}, (err) => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
trackTarget: function mw_trackTarget(target) {
|
|
|
|
target.metrics.set('uss', 0);
|
|
|
|
target.metrics.set('memory', 0);
|
|
|
|
this._fronts.set(target, MemoryFront(this._client, target.actor));
|
2014-02-26 13:58:37 -08:00
|
|
|
if (this._active) {
|
2014-03-03 11:50:56 -08:00
|
|
|
this.measure(target);
|
2014-02-26 13:58:37 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-03 11:50:56 -08:00
|
|
|
untrackTarget: function mw_untrackTarget(target) {
|
|
|
|
let front = this._fronts.get(target);
|
2014-02-26 13:58:37 -08:00
|
|
|
if (front) {
|
|
|
|
front.destroy();
|
2014-03-03 11:50:56 -08:00
|
|
|
clearTimeout(this._timers.get(target));
|
|
|
|
this._fronts.delete(target);
|
|
|
|
this._timers.delete(target);
|
2014-02-26 13:58:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
developerHUD.registerWatcher(memoryWatcher);
|