mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1245891 - Changing Session Restore Talos tests to include the time to restore actual tabs;r=mconley
MozReview-Commit-ID: 3kjG6ixWNiO MozReview-Commit-ID: ITPYkv6Jj4t --HG-- extra : rebase_source : 30c63c6d3a4235f2ee4b9f05780bdca94d43e38c
This commit is contained in:
parent
81113c32fa
commit
ed5e37d27c
@ -23,9 +23,14 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
|
||||
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,
|
||||
|
||||
@ -44,22 +49,42 @@ this.StartupPerformance = {
|
||||
// `true` once the timer has fired
|
||||
_hasFired: false,
|
||||
|
||||
// `true` once we are restored
|
||||
_isRestored: 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;
|
||||
},
|
||||
|
||||
/**
|
||||
* `true` once we have finished restoring startup tabs.
|
||||
*/
|
||||
get isRestored() {
|
||||
return this._isRestored;
|
||||
},
|
||||
|
||||
// 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;
|
||||
@ -68,7 +93,7 @@ this.StartupPerformance = {
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -78,7 +103,10 @@ this.StartupPerformance = {
|
||||
});
|
||||
this._promiseFinished.then(() => {
|
||||
try {
|
||||
if (!this._latestRestoredTimeStamp) {
|
||||
this._isRestored = true;
|
||||
Services.obs.notifyObservers(null, this.RESTORED_TOPIC, "");
|
||||
|
||||
if (this._latestRestoredTimeStamp == this._startTimeStamp) {
|
||||
// Apparently, we haven't restored any tab.
|
||||
return;
|
||||
}
|
||||
@ -95,7 +123,6 @@ this.StartupPerformance = {
|
||||
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) {
|
||||
|
@ -16,16 +16,17 @@ XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
|
||||
"resource://gre/modules/Timer.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "StartupPerformance",
|
||||
"resource:///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() {}
|
||||
function nsSessionRestoreTalosTest() { }
|
||||
|
||||
nsSessionRestoreTalosTest.prototype = {
|
||||
classID: Components.ID("{716346e5-0c45-4aa2-b601-da36f3c74bd8}"),
|
||||
@ -45,8 +46,8 @@ nsSessionRestoreTalosTest.prototype = {
|
||||
case STARTUP_TOPIC:
|
||||
this.init();
|
||||
break;
|
||||
case RESTORED_TOPIC:
|
||||
this.onRestored();
|
||||
case StartupPerformance.RESTORED_TOPIC:
|
||||
this.onReady(true);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown topic ${aTopic}`);
|
||||
@ -57,29 +58,54 @@ nsSessionRestoreTalosTest.prototype = {
|
||||
* Perform initialization on profile-after-change.
|
||||
*/
|
||||
init: function() {
|
||||
Services.obs.addObserver(this, RESTORED_TOPIC, false);
|
||||
if (StartupPerformance.isRestored) {
|
||||
this.onReady(true);
|
||||
} else {
|
||||
let sessionStartup = Cc["@mozilla.org/browser/sessionstartup;1"]
|
||||
.getService(Ci.nsISessionStartup);
|
||||
sessionStartup.onceInitialized.then(() => {
|
||||
if (sessionStartup.sessionType == Ci.nsISessionStartup.NO_SESSION
|
||||
|| sessionStartup.sessionType == Ci.nsISessionStartup.DEFER_SESSION) {
|
||||
this.onReady(false);
|
||||
} else {
|
||||
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.
|
||||
let startup_info = Services.startup.getStartupInfo();
|
||||
let duration = startup_info.sessionRestored - startup_info.sessionRestoreInit;
|
||||
onReady: function(hasRestoredTabs) {
|
||||
if (hasRestoredTabs) {
|
||||
Services.obs.removeObserver(this, StartupPerformance.RESTORED_TOPIC);
|
||||
}
|
||||
try {
|
||||
setTimeout(function() {
|
||||
// `StartupPerformance.latestRestoredTimeStamp` actually becomes available only on the next tick.
|
||||
let startup_info = Services.startup.getStartupInfo();
|
||||
let duration =
|
||||
hasRestoredTabs
|
||||
? StartupPerformance.latestRestoredTimeStamp - startup_info.sessionRestoreInit
|
||||
: startup_info.sessionRestored - 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() {
|
||||
Services.ppmm.removeMessageListener(MSG_REQUEST, listener);
|
||||
// Broadcast startup duration information immediately, in case the talos
|
||||
// page is already loaded.
|
||||
Services.ppmm.broadcastAsyncMessage(MSG_PROVIDE, {duration});
|
||||
});
|
||||
}, 0);
|
||||
|
||||
// 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() {
|
||||
Services.ppmm.removeMessageListener(MSG_REQUEST, listener);
|
||||
Services.ppmm.broadcastAsyncMessage(MSG_PROVIDE, {duration});
|
||||
});
|
||||
}, 0);
|
||||
} catch (ex) {
|
||||
dump(`SessionRestoreTalosTest: error ${ex}\n`);
|
||||
dump(ex.stack);
|
||||
dump("\n");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"><Description about="urn:mozilla:install-manifest">
|
||||
|
||||
<!-- Required Items -->
|
||||
<em:id>session-restore-test@mozilla.org</em:id>
|
||||
<em:id>session-restore-test-2@mozilla.org</em:id>
|
||||
<em:name>Session Restore Startup Performance Test</em:name>
|
||||
<em:version>1.2.0</em:version>
|
||||
<em:version>2.0.9</em:version>
|
||||
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user