Bug 1198898 - Determining number of tabs/windows restored by Session Restore;r=mconley
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Thu, 26 Nov 2015 18:13:20 +0100
changeset 320908 d6be256910404ebf4c4104d0c4bdb68a34b7d19e
parent 320907 a447e705ccc54ffc04d26c9ec8e63d3e7f1dcef0
child 320909 7bda46f8121539b2970666e61d609a8907300e59
push id9315
push useratolfsen@mozilla.com
push dateTue, 12 Jan 2016 19:08:25 +0000
reviewersmconley
bugs1198898
milestone46.0a1
Bug 1198898 - Determining number of tabs/windows restored by Session Restore;r=mconley
browser/components/sessionstore/StartupPerformance.jsm
toolkit/components/telemetry/Histograms.json
--- a/browser/components/sessionstore/StartupPerformance.jsm
+++ b/browser/components/sessionstore/StartupPerformance.jsm
@@ -39,27 +39,35 @@ this.StartupPerformance = {
   _resolveFinished: null,
 
   // A timer
   _deadlineTimer: null,
 
   // `true` once the timer has fired
   _hasFired: false,
 
+  // Statistics on the session we need to restore.
+  _totalNumberOfEagerTabs: 0,
+  _totalNumberOfTabs: 0,
+  _totalNumberOfWindows: 0,
+
   init: function() {
     for (let topic of TOPICS) {
       Services.obs.addObserver(this, topic, false);
     }
   },
 
   // 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._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) {
       Services.obs.removeObserver(this, topic);
     }
@@ -78,19 +86,24 @@ this.StartupPerformance = {
         // 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) {
+     } catch (ex) {
         console.error("StartupPerformance: error after resolving promise", ex);
       }
     });
   },
 
   _startTimer: function() {
     if (this._hasFired) {
       return;
@@ -146,26 +159,30 @@ this.StartupPerformance = {
           // Note that this heuristic may be inaccurate if a user clicks
           // immediately on a restore-on-demand tab before the end of
           // `COLLECT_RESULTS_AFTER_MS`. We assume that this will not
           // affect too much the results.
           //
           // Reset the delay, to give the tabs a little (more) time to restore.
           this._startTimer();
 
+          this._totalNumberOfWindows += 1;
+
           // Observe the restoration of all tabs. We assume that all tabs of this
           // window will have been restored before `COLLECT_RESULTS_AFTER_MS`.
           // The last call to `observer` will let us determine how long it took
           // to reach that point.
           let win = subject;
 
           let observer = () => {
             this._latestRestoredTimeStamp = Date.now();
+            this._totalNumberOfEagerTabs += 1;
           };
           win.gBrowser.tabContainer.addEventListener("SSTabRestored", observer);
+          this._totalNumberOfTabs += win.gBrowser.tabContainer.itemCount;
 
           // Once we have finished collecting the results, clean up the observers.
           this._promiseFinished.then(() => {
             if (!win.gBrowser.tabContainer) {
               // May be undefined during shutdown and/or some tests.
               return;
             }
             win.gBrowser.tabContainer.removeEventListener("SSTabRestored", observer);
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4237,16 +4237,35 @@
     "alert_emails": ["session-restore-telemetry-alerts@mozilla.com"],
     "expires_in_version": "default",
     "kind": "exponential",
     "low": "100",
     "high": "100000",
     "n_buckets": 20,
     "description": "Session restore: If a session is restored by the user clicking on 'Restore Session', this probe measures the time elapsed between the instant the user has clicked and the instant we have finished restoring tabs eagerly. At this stage, the tabs that are restored on demand are not restored yet."
   },
+  "FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED": {
+    "expires_in_version": "default",
+    "kind": "exponential",
+    "high": "500",
+    "n_buckets": 20,
+    "description": "Session restore: Number of tabs in the session that has just been restored."
+  },
+  "FX_SESSION_RESTORE_NUMBER_OF_WINDOWS_RESTORED": {
+    "expires_in_version": "default",
+    "kind": "enumerated",
+    "n_values": "50",
+    "description": "Session restore: Number of windows in the session that has just been restored."
+  },
+  "FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED": {
+    "expires_in_version": "default",
+    "kind": "enumerated",
+    "n_values": "50",
+    "description": "Session restore: Number of tabs restored eagerly in the session that has just been restored."
+  },
   "FX_TABLETMODE_PAGE_LOAD": {
     "expires_in_version": "47",
     "kind": "exponential",
     "high": 100000,
     "n_buckets": 30,
     "keyed": true,
     "description": "Number of toplevel location changes in tablet and desktop mode (only used on win10 where tablet mode is available)"
   },