Bug 963499 - Implement a jank watcher to display event loop lags in Firefox OS's Developer HUD. r=vingtetun
authorJan Keromnes <janx@linux.com>
Fri, 14 Feb 2014 11:52:14 -0500
changeset 185989 40c7df94ad772cca03d23fd76308d8c28927a96c
parent 185988 b969f8b35464ebe94db0ad663dcd440ef41afbcb
child 185990 ecf14acd56bec0afe6839f4943cbfee07c534a4d
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs963499
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963499 - Implement a jank watcher to display event loop lags in Firefox OS's Developer HUD. r=vingtetun
b2g/chrome/content/devtools.js
--- a/b2g/chrome/content/devtools.js
+++ b/b2g/chrome/content/devtools.js
@@ -10,16 +10,22 @@ XPCOMUtils.defineLazyGetter(this, 'Debug
   return Cu.import('resource://gre/modules/devtools/dbg-client.jsm', {}).DebuggerClient;
 });
 
 XPCOMUtils.defineLazyGetter(this, 'WebConsoleUtils', function() {
   let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
   return devtools.require("devtools/toolkit/webconsole/utils").Utils;
 });
 
+XPCOMUtils.defineLazyGetter(this, 'EventLoopLagFront', function() {
+  const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
+  return devtools.require("devtools/server/actors/eventlooplag").EventLoopLagFront;
+});
+
+
 /**
  * The Widget Panel is an on-device developer tool that displays widgets,
  * showing visual debug information about apps. Each widget corresponds to a
  * metric as tracked by a metric watcher (e.g. consoleWatcher).
  */
 let devtoolsWidgetPanel = {
 
   _apps: new Map(),
@@ -353,9 +359,72 @@ let consoleWatcher = {
     // Add function name and line number
     let {functionName, sourceLine} = packet;
     source = 'in ' + (functionName || '<anonymousFunction>') +
       ', ' + source + ':' + sourceLine;
 
     return source;
   }
 };
+
 devtoolsWidgetPanel.registerWatcher(consoleWatcher);
+
+
+let jankWatcher = {
+  _client: null,
+  _fronts: new Map(),
+  _active: false,
+
+  init: function(client) {
+    this._client = client;
+
+    SettingsListener.observe('devtools.hud.jank', false,
+      this.settingsListener.bind(this));
+  },
+
+  settingsListener: function(value) {
+    if (this._active == value) {
+      return;
+    }
+    this._active = value;
+
+    // Toggle the state of existing fronts.
+    let fronts = this._fronts;
+    for (let app of fronts.keys()) {
+      if (value) {
+        fronts.get(app).start();
+      } else {
+        fronts.get(app).stop();
+        app.metrics.set('jank', 0);
+        app.display();
+      }
+    }
+  },
+
+  trackApp: function(app) {
+    app.metrics.set('jank', 0);
+
+    let front = new EventLoopLagFront(this._client, app.actor);
+    this._fronts.set(app, front);
+
+    front.on('event-loop-lag', time => {
+      app.metrics.set('jank', time);
+
+      if (!app.display()) {
+        devtoolsWidgetPanel.log('jank: ' + time + 'ms');
+      }
+    });
+
+    if (this._active) {
+      front.start();
+    }
+  },
+
+  untrackApp: function(app) {
+    let fronts = this._fronts;
+    if (fronts.has(app)) {
+      fronts.get(app).destroy();
+      fronts.delete(app);
+    }
+  }
+};
+
+devtoolsWidgetPanel.registerWatcher(jankWatcher);