Bug 1353172 - Add telemetry for background page load time time, r=bsmedberg,kmag
authorBob Silverberg <bsilverberg@mozilla.com>
Tue, 18 Apr 2017 15:35:21 -0400
changeset 361121 9975e1fd9faab198bc5243ee5d8cac36b30cc6c5
parent 361120 88d6ec3ac48c4c778a7a93f1c3d36d392f8e793d
child 361122 d594a107a7ad24657a31ed0ccf66498136c17db0
push id31917
push usercbook@mozilla.com
push dateTue, 30 May 2017 09:14:52 +0000
treeherdermozilla-central@0c712d76d598 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, kmag
bugs1353172
milestone55.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 1353172 - Add telemetry for background page load time time, r=bsmedberg,kmag Add WEBEXT_BACKGROUND_PAGE_LOAD_MS histogram that measures the time from initiating the build() function to when the page is loaded. MozReview-Commit-ID: 4duZuIlZnXk
toolkit/components/extensions/ext-backgroundPage.js
toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
toolkit/components/telemetry/Histograms.json
--- a/toolkit/components/extensions/ext-backgroundPage.js
+++ b/toolkit/components/extensions/ext-backgroundPage.js
@@ -1,14 +1,16 @@
 "use strict";
 
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
                                   "resource://gre/modules/AddonManager.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
+                                  "resource://gre/modules/TelemetryStopwatch.jsm");
 
 Cu.import("resource://gre/modules/ExtensionParent.jsm");
 var {
   HiddenExtensionPage,
   promiseExtensionViewLoaded,
 } = ExtensionParent;
 
 // Responsible for the background_page section of the manifest.
@@ -27,23 +29,25 @@ class BackgroundPage extends HiddenExten
 
     if (!this.extension.isExtensionURL(this.url)) {
       this.extension.manifestError("Background page must be a file within the extension");
       this.url = this.extension.baseURI.resolve("_blank.html");
     }
   }
 
   async build() {
+    TelemetryStopwatch.start("WEBEXT_BACKGROUND_PAGE_LOAD_MS", this);
     await this.createBrowserElement();
 
     extensions.emit("extension-browser-inserted", this.browser);
 
     this.browser.loadURI(this.url);
 
     let context = await promiseExtensionViewLoaded(this.browser);
+    TelemetryStopwatch.finish("WEBEXT_BACKGROUND_PAGE_LOAD_MS", this);
 
     if (context) {
       // Wait until all event listeners registered by the script so far
       // to be handled.
       await Promise.all(context.listenerPromises);
       context.listenerPromises = null;
     }
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
@@ -0,0 +1,40 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+const HISTOGRAM = "WEBEXT_BACKGROUND_PAGE_LOAD_MS";
+
+add_task(async function test_telemetry() {
+  let extension1 = ExtensionTestUtils.loadExtension({
+    background() {
+      browser.test.sendMessage("loaded");
+    },
+  });
+
+  let extension2 = ExtensionTestUtils.loadExtension({
+    background() {
+      browser.test.sendMessage("loaded");
+    },
+  });
+
+  let histogram = Services.telemetry.getHistogramById(HISTOGRAM);
+  histogram.clear();
+  equal(histogram.snapshot().sum, 0,
+        `No data recorded for histogram: ${HISTOGRAM}.`);
+
+  await extension1.startup();
+  await extension1.awaitMessage("loaded");
+
+  let histogramSum = histogram.snapshot().sum;
+  ok(histogramSum > 0,
+     `Data recorded for first extension for histogram: ${HISTOGRAM}.`);
+
+  await extension2.startup();
+  await extension2.awaitMessage("loaded");
+
+  ok(histogram.snapshot().sum > histogramSum,
+     `Data recorded for second extension for histogram: ${HISTOGRAM}.`);
+
+  await extension1.unload();
+  await extension2.unload();
+});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -18,16 +18,17 @@ tags = webextensions
 [test_ext_api_permissions.js]
 [test_ext_background_generated_load_events.js]
 [test_ext_background_generated_reload.js]
 [test_ext_background_global_history.js]
 skip-if = os == "android" # Android does not use Places for history.
 [test_ext_background_private_browsing.js]
 [test_ext_background_runtime_connect_params.js]
 [test_ext_background_sub_windows.js]
+[test_ext_background_telemetry.js]
 [test_ext_background_window_properties.js]
 skip-if = os == "android"
 [test_ext_contexts.js]
 [test_ext_contextual_identities.js]
 skip-if = os == "android" # Containers are not exposed to android.
 [test_ext_debugging_utils.js]
 [test_ext_downloads.js]
 [test_ext_downloads_download.js]
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -13240,10 +13240,21 @@
     "bug_numbers": [1365719],
     "expires_in_version": "60",
     "kind": "exponential",
     "low": 32,
     "high": 750,
     "n_buckets": 40,
     "keyed": true,
     "description": "Measures the number of milliseconds we spend processing sync IPC messages in the receiving process, keyed by message name. Note: only messages that take over 500 microseconds are included in this probe."
+  },
+  "WEBEXT_BACKGROUND_PAGE_LOAD_MS": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["addons-dev-internal@mozilla.com"],
+    "bug_numbers": [1353172],
+    "expires_in_version": "60",
+    "kind": "exponential",
+    "releaseChannelCollection": "opt-out",
+    "high": 60000,
+    "n_buckets": 100,
+    "description": "The amount of time it takes to load a WebExtensions background page, from when the build function is called to when the page has finished processing the onload event."
   }
 }