Bug 1189942 - performanceEntriesWatcher race condition. r=jryans
authorRuss Nicoletti <rnicoletti@mozilla.com>
Wed, 04 Nov 2015 15:18:09 -0800
changeset 306849 9875f804994f1521d9d60bc3c34c0ac4fa4c667f
parent 306848 a740558de8a6c5f08c7ec93c0130c012debf4031
child 306850 0fcb7abf3523a32868dc0b66b5ef02432a304801
push id7204
push usercku@mozilla.com
push dateThu, 05 Nov 2015 15:38:26 +0000
reviewersjryans
bugs1189942
milestone45.0a1
Bug 1189942 - performanceEntriesWatcher race condition. r=jryans
b2g/chrome/content/devtools/hud.js
--- a/b2g/chrome/content/devtools/hud.js
+++ b/b2g/chrome/content/devtools/hud.js
@@ -740,29 +740,31 @@ var eventLoopLagWatcher = {
       fronts.delete(target);
     }
   }
 };
 developerHUD.registerWatcher(eventLoopLagWatcher);
 
 /*
  * The performanceEntriesWatcher determines the delta between the epoch
- * of an app's launch time and the app's performance entry marks.
+ * of an app's launch time and the epoch of the app's performance entry marks.
  * When it receives an "appLaunch" performance entry mark it records the
  * name of the app being launched and the epoch of when the launch ocurred.
  * When it receives subsequent performance entry events for the app being
  * launched, it records the delta of the performance entry opoch compared
  * to the app-launch epoch and emits an "app-start-time-<performance mark name>"
  * event containing the delta.
+ *
+ * Additionally, while recording the "app-start-time" for a performance mark,
+ * USS memory at the time of the performance mark is also recorded.
  */
 var performanceEntriesWatcher = {
   _client: null,
   _fronts: new Map(),
-  _appLaunchName: null,
-  _appLaunchStartTime: null,
+  _appLaunch: new Map(),
   _supported: [
     'contentInteractive',
     'navigationInteractive',
     'navigationLoaded',
     'visuallyLoaded',
     'fullyLoaded',
     'mediaEnumerated',
     'scanEnd'
@@ -795,45 +797,44 @@ var performanceEntriesWatcher = {
       // Only process performance marks.
       if (detail.type !== 'mark') {
         return;
       }
 
       let name = detail.name;
       let epoch = detail.epoch;
 
-      // FIXME There is a potential race condition that can result
-      // in some performance entries being disregarded. See bug 1189942.
-      //
       // If this is an "app launch" mark, record the app that was
       // launched and the epoch of when it was launched.
       if (name.indexOf('appLaunch') !== -1) {
         let CHARS_UNTIL_APP_NAME = 7; // '@app://'
         let startPos = name.indexOf('@app') + CHARS_UNTIL_APP_NAME;
         let endPos = name.indexOf('.');
-        this._appLaunchName = name.slice(startPos, endPos);
-        this._appLaunchStartTime = epoch;
+        let appName = name.slice(startPos, endPos);
+        this._appLaunch.set(appName, epoch);
         return;
       }
 
       // Only process supported performance marks
       if (this._supported.indexOf(name) === -1) {
         return;
       }
 
       let origin = detail.origin;
       origin = origin.slice(0, origin.indexOf('.'));
 
-      // Continue if the performance mark corresponds to the app
-      // for which we have recorded app launch information.
-      if (this._appLaunchName !== origin) {
+      let appLaunchTime = this._appLaunch.get(origin);
+
+      // Sanity check: ensure we have an app launch time for the app
+      // corresponding to this performance mark.
+      if (!appLaunchTime) {
         return;
       }
 
-      let time = epoch - this._appLaunchStartTime;
+      let time = epoch - appLaunchTime;
       let eventName = 'app_startup_time_' + name;
 
       // Events based on performance marks are for telemetry only, they are
       // not displayed in the HUD front end.
       target._logHistogram({name: eventName, value: time});
 
       memoryWatcher.front(target).residentUnique().then(value => {
         // bug 1215277, need 'v2' for app-memory histograms