diff --git a/testing/talos/talos/test.py b/testing/talos/talos/test.py index 80a2b4786c57..63e35bc03594 100644 --- a/testing/talos/talos/test.py +++ b/testing/talos/talos/test.py @@ -285,14 +285,13 @@ class cpstartup(PageloaderTest): initialize it to the point where it can start processing incoming URLs to load. """ - extensions = ['${talos}/tests/cpstartup', '${talos}/pageloader'] + extensions = ['${talos}/pageloader', '${talos}/tests/cpstartup/extension'] tpmanifest = '${talos}/tests/cpstartup/cpstartup.manifest' tppagecycles = 20 gecko_profile_entries = 1000000 tploadnocache = True unit = 'ms' preferences = { - 'addon.test.cpstartup.webserver': '${webserver}', # By default, Talos is configured to open links from # content in new windows. We're overriding them so that # they open in new tabs instead. diff --git a/testing/talos/talos/tests/cpstartup/chrome.manifest b/testing/talos/talos/tests/cpstartup/chrome.manifest deleted file mode 100644 index d349e6b2bf6f..000000000000 --- a/testing/talos/talos/tests/cpstartup/chrome.manifest +++ /dev/null @@ -1 +0,0 @@ -content cpstartup content/ remoteenabled=yes contentaccessible=yes \ No newline at end of file diff --git a/testing/talos/talos/tests/cpstartup/content/cpstartup.html b/testing/talos/talos/tests/cpstartup/content/cpstartup.html deleted file mode 100644 index 8fae4cfbaab5..000000000000 --- a/testing/talos/talos/tests/cpstartup/content/cpstartup.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Hello, Talos! - - I'll open a new tab - - diff --git a/testing/talos/talos/tests/cpstartup/cpstartup.html b/testing/talos/talos/tests/cpstartup/cpstartup.html new file mode 100644 index 000000000000..ddac3629bcb5 --- /dev/null +++ b/testing/talos/talos/tests/cpstartup/cpstartup.html @@ -0,0 +1,43 @@ + + + + + + + Hello, Talos! + + I'll open a new tab + + diff --git a/testing/talos/talos/tests/cpstartup/cpstartup.manifest b/testing/talos/talos/tests/cpstartup/cpstartup.manifest index f6f9e5258e4c..a686c45f8290 100644 --- a/testing/talos/talos/tests/cpstartup/cpstartup.manifest +++ b/testing/talos/talos/tests/cpstartup/cpstartup.manifest @@ -1 +1 @@ -% chrome://cpstartup/content/cpstartup.html#auto +% http://localhost/tests/cpstartup/cpstartup.html diff --git a/testing/talos/talos/tests/cpstartup/bootstrap.js b/testing/talos/talos/tests/cpstartup/extension/api.js similarity index 50% rename from testing/talos/talos/tests/cpstartup/bootstrap.js rename to testing/talos/talos/tests/cpstartup/extension/api.js index c0024a11a668..aec982092e17 100644 --- a/testing/talos/talos/tests/cpstartup/bootstrap.js +++ b/testing/talos/talos/tests/cpstartup/extension/api.js @@ -2,61 +2,61 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -ChromeUtils.import("resource://gre/modules/Services.jsm"); +ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -const PREALLOCATED_PREF = "dom.ipc.processPrelaunch.enabled"; - -const TARGET_PATH = "tests/cpstartup/content/target.html"; -const WEBSERVER = Services.prefs.getCharPref("addon.test.cpstartup.webserver"); -const TARGET_URI = `${WEBSERVER}/${TARGET_PATH}`; /** - * The purpose of this test it to measure the performance of a content process startup. + * The purpose of this test it to measure the performance of a + * content process startup. * - * In practice it measures a bit more than the content process startup. First the parent - * process starts the clock and requests a new tab with a simple page and then the child - * stops the clock in the frame script that will be able to process the URL to handle. - * So it does measure a few things pre process creation (browser element and tab creation - * on parent side) but does not measure the part where we actually parse and render the - * page on the content side, just the overhead of spawning a new content process. + * In practice it measures a bit more than the content process startup. First + * the parent process starts the clock and requests a new tab with a simple + * page and then the child stops the clock in the frame script that will be + * able to process the URL to handle. So it does measure a few things + * pre process creation (browser element and tab creation on parent side) but + * does not measure the part where we actually parse and render the page on + * the content side, just the overhead of spawning a new content process. */ -var CPStartup = { - MESSAGES: [ - "CPStartup:Go", - "Content:BrowserChildReady", - ], - readyCallback: null, +XPCOMUtils.defineLazyScriptGetter(this, "TalosParentProfiler", + "resource://talos-powers/TalosParentProfiler.js"); - startStamp: null, +ChromeUtils.defineModuleGetter(this, "Services", + "resource://gre/modules/Services.jsm"); - tab: null, - /** - * Shortcut to getting at the TalosParentProfiler. - */ - get Profiler() { - delete this.Profiler; - let context = {}; - Services.scriptloader.loadSubScript("resource://talos-powers/TalosParentProfiler.js", context); - return this.Profiler = context.TalosParentProfiler; - }, +const PREALLOCATED_PREF = "dom.ipc.processPrelaunch.enabled"; +const MESSAGES = [ + "CPStartup:Go", + "Content:BrowserChildReady", +]; - init() { - for (let msgName of this.MESSAGES) { +/* global ExtensionAPI */ + +this.cpstartup = class extends ExtensionAPI { + onStartup() { + for (let msgName of MESSAGES) { Services.mm.addMessageListener(msgName, this); } + this.framescriptURL = this.extension.baseURI.resolve("/framescript.js"); + Services.mm.loadFrameScript(this.framescriptURL, true); + this.originalPreallocatedEnabled = Services.prefs.getBoolPref(PREALLOCATED_PREF); Services.prefs.setBoolPref(PREALLOCATED_PREF, false); - }, - uninit() { - for (let msgName of this.MESSAGES) { + this.readyCallback = null; + this.startStamp = null; + this.tab = null; + } + + onShutdown() { + Services.prefs.setBoolPref(PREALLOCATED_PREF, this.originalPreallocatedEnabled); + Services.mm.removeDelayedFrameScript(this.framescriptURL); + + for (let msgName of MESSAGES) { Services.mm.removeMessageListener(msgName, this); } - - Services.prefs.setBoolPref(PREALLOCATED_PREF, this.originalPreallocatedEnabled); - }, + } receiveMessage(msg) { let browser = msg.target; @@ -64,7 +64,7 @@ var CPStartup = { switch (msg.name) { case "CPStartup:Go": { - this.openTab(gBrowser).then(results => + this.openTab(gBrowser, msg.data.target).then(results => this.reportResults(results)); break; } @@ -86,31 +86,25 @@ var CPStartup = { break; } } - }, + } - openTab(gBrowser) { - return new Promise((resolve) => { - // Start the timer and the profiler right before the tab open on the parent side. - this.Profiler.resume("tab opening starts"); - this.startStamp = Services.telemetry.msSystemNow(); - this.tab = gBrowser.selectedTab = gBrowser.addTab(TARGET_URI, { - triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), - }); + async openTab(gBrowser, url) { + // Start the timer and the profiler right before the tab open on the parent side. + TalosParentProfiler.resume("tab opening starts"); + this.startStamp = Services.telemetry.msSystemNow(); + this.tab = gBrowser.selectedTab = gBrowser.addTrustedTab(url); - this.whenTabReady().then(({tab, delta}) => { - this.Profiler.pause("tab opening end"); - this.removeTab(tab).then(() => { - resolve(delta); - }); - }); - }); - }, + let {tab, delta} = await this.whenTabReady(); + TalosParentProfiler.pause("tab opening end"); + await this.removeTab(tab); + return delta; + } whenTabReady() { return new Promise((resolve) => { this.readyCallback = resolve; }); - }, + } removeTab(tab) { return new Promise((resolve) => { @@ -124,21 +118,9 @@ var CPStartup = { tab.ownerGlobal.gBrowser.removeTab(tab); }); - }, + } reportResults(results) { Services.mm.broadcastAsyncMessage("CPStartup:FinalResults", results); - }, + } }; - -function install(aData, aReason) {} - -function startup(aData, aReason) { - CPStartup.init(); -} - -function shutdown(aData, aReason) { - CPStartup.uninit(); -} - -function uninstall(aData, aReason) {} diff --git a/testing/talos/talos/tests/cpstartup/extension/framescript.js b/testing/talos/talos/tests/cpstartup/extension/framescript.js new file mode 100644 index 000000000000..45029e20695f --- /dev/null +++ b/testing/talos/talos/tests/cpstartup/extension/framescript.js @@ -0,0 +1,19 @@ +(function() { + addEventListener("CPStartup:Ping", e => { + let evt = new content.CustomEvent("CPStartup:Pong", {bubbles: true}); + content.dispatchEvent(evt); + }, false, true); + + addEventListener("CPStartup:Go", e => { + sendAsyncMessage("CPStartup:Go", e.detail); + }, false, true); + + addMessageListener("CPStartup:FinalResults", msg => { + let evt = Cu.cloneInto({ + bubbles: true, + detail: msg.data, + }, content); + + content.dispatchEvent(new content.CustomEvent("CPStartup:FinalResults", evt)); + }); +})(); diff --git a/testing/talos/talos/tests/cpstartup/extension/manifest.json b/testing/talos/talos/tests/cpstartup/extension/manifest.json new file mode 100644 index 000000000000..b568ae4cf2fd --- /dev/null +++ b/testing/talos/talos/tests/cpstartup/extension/manifest.json @@ -0,0 +1,23 @@ +{ + "manifest_version": 2, + "name": "cpstartup test", + "description": "Measures the performance of starting and initializing new content processes", + "version": "1.1", + + "applications": { + "gecko": { + "id": "cpstartup-test@mozilla.org" + } + }, + + "experiment_apis": { + "cpstartup": { + "schema": "schema.json", + "parent": { + "scopes": ["addon_parent"], + "script": "api.js", + "events": ["startup"] + } + } + } +} diff --git a/testing/talos/talos/tests/cpstartup/extension/schema.json b/testing/talos/talos/tests/cpstartup/extension/schema.json new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/testing/talos/talos/tests/cpstartup/extension/schema.json @@ -0,0 +1 @@ +[] diff --git a/testing/talos/talos/tests/cpstartup/install.rdf b/testing/talos/talos/tests/cpstartup/install.rdf deleted file mode 100644 index fd6c24de11f1..000000000000 --- a/testing/talos/talos/tests/cpstartup/install.rdf +++ /dev/null @@ -1,24 +0,0 @@ - - - - cpstartup-test@mozilla.org - 2 - cpstartup test - 1.0.0 - true - Measures the performance of starting and initializing new content processes - Gabor Krizsanits - true - - - - - {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 55.0 - * - - - https://wiki.mozilla.org/Buildbot/Talos/Tests - https://wiki.mozilla.org/Buildbot/Talos/Tests - - diff --git a/testing/talos/talos/tests/cpstartup/content/target.html b/testing/talos/talos/tests/cpstartup/target.html similarity index 100% rename from testing/talos/talos/tests/cpstartup/content/target.html rename to testing/talos/talos/tests/cpstartup/target.html