mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Bug 968220 - Make B2G devtools overlay metrics configurable with prefs. r=vingtetun
This commit is contained in:
parent
1cbc513fd3
commit
c9164cdbb4
@ -203,18 +203,41 @@ App.prototype = {
|
||||
|
||||
|
||||
/**
|
||||
* The Console Watcher tracks the following metrics in apps: errors, warnings,
|
||||
* and reflows.
|
||||
* The Console Watcher tracks the following metrics in apps: reflows, warnings,
|
||||
* and errors.
|
||||
*/
|
||||
let consoleWatcher = {
|
||||
|
||||
_apps: new Map(),
|
||||
_watching: {
|
||||
reflows: false,
|
||||
warnings: false,
|
||||
errors: false
|
||||
},
|
||||
_client: null,
|
||||
|
||||
init: function cw_init(client) {
|
||||
this._client = client;
|
||||
this.consoleListener = this.consoleListener.bind(this);
|
||||
|
||||
let watching = this._watching;
|
||||
|
||||
for (let key in watching) {
|
||||
let metric = key;
|
||||
SettingsListener.observe('devtools.hud.' + metric, false, value => {
|
||||
// Watch or unwatch the metric.
|
||||
if (watching[metric] = value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If unwatched, remove any existing widgets for that metric.
|
||||
for (let app of this._apps.values()) {
|
||||
app.metrics.set(metric, 0);
|
||||
app.display();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
client.addListener('logMessage', this.consoleListener);
|
||||
client.addListener('pageError', this.consoleListener);
|
||||
client.addListener('consoleAPICall', this.consoleListener);
|
||||
@ -246,8 +269,13 @@ let consoleWatcher = {
|
||||
},
|
||||
|
||||
bump: function cw_bump(app, metric) {
|
||||
if (!this._watching[metric]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let metrics = app.metrics;
|
||||
metrics.set(metric, metrics.get(metric) + 1);
|
||||
return true;
|
||||
},
|
||||
|
||||
consoleListener: function cw_consoleListener(type, packet) {
|
||||
@ -258,13 +286,19 @@ let consoleWatcher = {
|
||||
|
||||
case 'pageError':
|
||||
let pageError = packet.pageError;
|
||||
|
||||
if (pageError.warning || pageError.strict) {
|
||||
this.bump(app, 'warnings');
|
||||
if (!this.bump(app, 'warnings')) {
|
||||
return;
|
||||
}
|
||||
output = 'warning (';
|
||||
} else {
|
||||
this.bump(app, 'errors');
|
||||
if (!this.bump(app, 'errors')) {
|
||||
return;
|
||||
}
|
||||
output += 'error (';
|
||||
}
|
||||
|
||||
let {errorMessage, sourceName, category, lineNumber, columnNumber} = pageError;
|
||||
output += category + '): "' + (errorMessage.initial || errorMessage) +
|
||||
'" in ' + sourceName + ':' + lineNumber + ':' + columnNumber;
|
||||
@ -272,21 +306,31 @@ let consoleWatcher = {
|
||||
|
||||
case 'consoleAPICall':
|
||||
switch (packet.message.level) {
|
||||
|
||||
case 'error':
|
||||
this.bump(app, 'errors');
|
||||
if (!this.bump(app, 'errors')) {
|
||||
return;
|
||||
}
|
||||
output = 'error (console)';
|
||||
break;
|
||||
|
||||
case 'warn':
|
||||
this.bump(app, 'warnings');
|
||||
if (!this.bump(app, 'warnings')) {
|
||||
return;
|
||||
}
|
||||
output = 'warning (console)';
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'reflowActivity':
|
||||
this.bump(app, 'reflows');
|
||||
if (!this.bump(app, 'reflows')) {
|
||||
return;
|
||||
}
|
||||
|
||||
let {start, end, sourceURL} = packet;
|
||||
let duration = Math.round((end - start) * 100) / 100;
|
||||
output = 'reflow: ' + duration + 'ms';
|
||||
|
Loading…
Reference in New Issue
Block a user