Bug 1245891 - Changing Session Restore Talos tests to include the time to restore actual tabs;r=mconley
☠☠ backed out by 53bb059dd388 ☠ ☠
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Tue, 23 Feb 2016 13:40:39 +0100
changeset 285747 b88648a41ed26abcc1a9184d6c583f60c600014b
parent 285746 06a4669aaf8c8d7f76232b5eb19ff0cd6263cc0b
child 285748 fbcaba9e6b76349a6cd504c9762e7ed7e4b36397
push id72512
push userdteller@mozilla.com
push dateFri, 26 Feb 2016 17:45:24 +0000
treeherdermozilla-inbound@b88648a41ed2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1245891
milestone47.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 1245891 - Changing Session Restore Talos tests to include the time to restore actual tabs;r=mconley MozReview-Commit-ID: 3kjG6ixWNiO
browser/components/sessionstore/StartupPerformance.jsm
testing/talos/talos/startup_test/sessionrestore/addon/SessionRestoreTalosTest.js
--- a/browser/components/sessionstore/StartupPerformance.jsm
+++ b/browser/components/sessionstore/StartupPerformance.jsm
@@ -18,19 +18,24 @@ XPCOMUtils.defineLazyModuleGetter(this, 
   "resource://gre/modules/Timer.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "clearTimeout",
   "resource://gre/modules/Timer.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
   "resource://gre/modules/Promise.jsm");
 
 const COLLECT_RESULTS_AFTER_MS = 10000;
 
-const TOPICS = ["sessionstore-restoring-on-startup", "sessionstore-initiating-manual-restore"];
+const OBSERVED_TOPICS = ["sessionstore-restoring-on-startup", "sessionstore-initiating-manual-restore"];
 
 this.StartupPerformance = {
+  /**
+   * Once we have finished restoring initial tabs, we broadcast on this topic.
+   */
+  RESTORED_TOPIC: "sessionstore-finished-restoring-initial-tabs",
+
   // Instant at which we have started restoration (notification "sessionstore-restoring-on-startup")
   _startTimeStamp: null,
 
   // Latest instant at which we have finished restoring a tab (DOM event "SSTabRestored")
   _latestRestoredTimeStamp: null,
 
   // A promise resolved once we have finished restoring all the startup tabs.
   _promiseFinished: null,
@@ -45,62 +50,73 @@ this.StartupPerformance = {
   _hasFired: false,
 
   // Statistics on the session we need to restore.
   _totalNumberOfEagerTabs: 0,
   _totalNumberOfTabs: 0,
   _totalNumberOfWindows: 0,
 
   init: function() {
-    for (let topic of TOPICS) {
+    for (let topic of OBSERVED_TOPICS) {
       Services.obs.addObserver(this, topic, false);
     }
   },
 
+  /**
+   * Return the timestamp at which we finished restoring the latest tab.
+   *
+   * This information is not really interesting until we have finished restoring
+   * tabs.
+   */
+  get latestRestoredTimeStamp() {
+    return this._latestRestoredTimeStamp;
+  },
+
   // Called when restoration starts.
   // Record the start timestamp, setup the timer and `this._promiseFinished`.
   // Behavior is unspecified if there was already an ongoing measure.
   _onRestorationStarts: function(isAutoRestore) {
-    this._startTimeStamp = Date.now();
+    this._latestRestoredTimeStamp = this._startTimeStamp = Date.now();
     this._totalNumberOfEagerTabs = 0;
     this._totalNumberOfTabs = 0;
     this._totalNumberOfWindows = 0;
 
     // While we may restore several sessions in a single run of the browser,
     // that's a very unusual case, and not really worth measuring, so let's
     // stop listening for further restorations.
 
-    for (let topic of TOPICS) {
+    for (let topic of OBSERVED_TOPICS) {
       Services.obs.removeObserver(this, topic);
     }
 
     Services.obs.addObserver(this, "sessionstore-single-window-restored", false);
     this._promiseFinished = new Promise(resolve => {
       this._resolveFinished = resolve;
     });
     this._promiseFinished.then(() => {
       try {
-        if (!this._latestRestoredTimeStamp) {
+        Services.obs.notifyObservers(null, this.RESTORED_TOPIC, "");
+
+        if (this._latestRestoredTimeStamp == this._startTimeStamp) {
           // Apparently, we haven't restored any tab.
           return;
         }
 
         // Once we are done restoring tabs, update Telemetry.
         let histogramName = isAutoRestore ?
           "FX_SESSION_RESTORE_AUTO_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS" :
           "FX_SESSION_RESTORE_MANUAL_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS";
         let histogram = Services.telemetry.getHistogramById(histogramName);
         let delta = this._latestRestoredTimeStamp - this._startTimeStamp;
         histogram.add(delta);
 
         Services.telemetry.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED").add(this._totalNumberOfEagerTabs);
         Services.telemetry.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED").add(this._totalNumberOfTabs);
         Services.telemetry.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_WINDOWS_RESTORED").add(this._totalNumberOfWindows);
 
-
         // Reset
         this._startTimeStamp = null;
      } catch (ex) {
         console.error("StartupPerformance: error after resolving promise", ex);
       }
     });
   },
 
--- a/testing/talos/talos/startup_test/sessionrestore/addon/SessionRestoreTalosTest.js
+++ b/testing/talos/talos/startup_test/sessionrestore/addon/SessionRestoreTalosTest.js
@@ -11,20 +11,21 @@ const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
   "resource://gre/modules/Timer.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "StartupPerformance",
+  "resource://gre/modules/sessionstore/StartupPerformance.jsm");
 
 // Observer Service topics.
 const STARTUP_TOPIC = "profile-after-change";
-const RESTORED_TOPIC = "sessionstore-windows-restored";
 
 // Process Message Manager topics.
 const MSG_REQUEST = "session-restore-test?duration";
 const MSG_PROVIDE = "session-restore-test:duration";
 
 function nsSessionRestoreTalosTest() {}
 
 nsSessionRestoreTalosTest.prototype = {
@@ -40,39 +41,39 @@ nsSessionRestoreTalosTest.prototype = {
   //////////////////////////////////////////////////////////////////////////////
   //// nsIObserver
 
   observe: function DS_observe(aSubject, aTopic, aData) {
     switch (aTopic) {
       case STARTUP_TOPIC:
         this.init();
         break;
-      case RESTORED_TOPIC:
+      case StartupPerformance.RESTORED_TOPIC:
         this.onRestored();
         break;
       default:
         throw new Error(`Unknown topic ${aTopic}`);
     }
   },
 
   /**
    * Perform initialization on profile-after-change.
    */
   init: function() {
-    Services.obs.addObserver(this, RESTORED_TOPIC, false);
+    Services.obs.addObserver(this, StartupPerformance.RESTORED_TOPIC, false);
   },
 
   /**
    * Session Restore is complete, hurray.
    */
   onRestored: function() {
     setTimeout(function() {
-      // `sessionRestored` actually becomes available only on the next tick.
+      // `StartupPerformance.latestRestoredTimeStamp` actually becomes available only on the next tick.
       let startup_info = Services.startup.getStartupInfo();
-      let duration = startup_info.sessionRestored - startup_info.sessionRestoreInit;
+      let duration = StartupPerformance.latestRestoredTimeStamp - startup_info.sessionRestoreInit;
 
       // Broadcast startup duration information immediately, in case the talos
       // page is already loaded.
       Services.ppmm.broadcastAsyncMessage(MSG_PROVIDE, {duration});
 
       // Now, in case the talos page isn't loaded yet, prepare to respond if it
       // requestions the duration information.
       Services.ppmm.addMessageListener(MSG_REQUEST, function listener() {