Bug 1500069 - Add metrics tests for the webconsole;r=ochameau,nchevobbe
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 12 Feb 2019 19:08:33 +0000
changeset 458778 a98671536694
parent 458777 c405d8906d7c
child 458779 c27aa490f40b
push id35548
push useropoprus@mozilla.com
push dateWed, 13 Feb 2019 09:48:26 +0000
treeherdermozilla-central@93e37c529818 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, nchevobbe
bugs1500069
milestone67.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 1500069 - Add metrics tests for the webconsole;r=ochameau,nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D19364
devtools/client/framework/moz.build
devtools/client/framework/test/metrics/browser_metrics_inspector.js
devtools/client/framework/test/metrics/browser_metrics_webconsole.ini
devtools/client/framework/test/metrics/browser_metrics_webconsole.js
devtools/client/framework/test/metrics/head.js
devtools/client/webconsole/main.js
--- a/devtools/client/framework/moz.build
+++ b/devtools/client/framework/moz.build
@@ -1,17 +1,18 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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/.
 
 BROWSER_CHROME_MANIFESTS += [
     'test/browser.ini',
-    'test/metrics/browser_metrics_inspector.ini'
+    'test/metrics/browser_metrics_inspector.ini',
+    'test/metrics/browser_metrics_webconsole.ini',
 ]
 XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 
 DIRS += [
     'components',
 ]
 
 DevToolsModules(
--- a/devtools/client/framework/test/metrics/browser_metrics_inspector.js
+++ b/devtools/client/framework/test/metrics/browser_metrics_inspector.js
@@ -13,18 +13,21 @@
  * by perfherder via logs.
  */
 
 const TEST_URL = "data:text/html;charset=UTF-8,<div>Inspector modules load test</div>";
 
 add_task(async function() {
   await openNewTabAndToolbox(TEST_URL, "inspector");
 
-  const allModules = getFilteredModules("");
-  const inspectorModules = getFilteredModules("devtools/client/inspector");
+  // The inspector does not use a dedicated browser loader.
+  const loaders = [loader.provider.loader];
+
+  const allModules = getFilteredModules("", loaders);
+  const inspectorModules = getFilteredModules("devtools/client/inspector", loaders);
 
   const allModulesCount = allModules.length;
   const inspectorModulesCount = inspectorModules.length;
 
   const allModulesChars = countCharsInModules(allModules);
   const inspectorModulesChars = countCharsInModules(inspectorModules);
 
   const PERFHERDER_DATA = {
@@ -57,24 +60,8 @@ add_task(async function() {
   info("PERFHERDER_DATA: " + JSON.stringify(PERFHERDER_DATA));
 
   // Simply check that we found valid values.
   ok(allModulesCount > inspectorModulesCount &&
      inspectorModulesCount > 0, "Successfully recorded module count for Inspector");
   ok(allModulesChars > inspectorModulesChars &&
      inspectorModulesChars > 0, "Successfully recorded char count for Inspector");
 });
-
-function getFilteredModules(filter) {
-  const modules = Object.keys(loader.provider.loader.modules);
-  return modules.filter(url => url.includes(filter));
-}
-
-function countCharsInModules(modules) {
-  return modules.reduce((sum, uri) => {
-    try {
-      return sum + require("raw!" + uri).length;
-    } catch (e) {
-      // Ignore failures
-      return sum;
-    }
-  }, 0);
-}
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/metrics/browser_metrics_webconsole.ini
@@ -0,0 +1,12 @@
+[DEFAULT]
+tags = devtools
+subsuite = devtools
+support-files =
+  head.js
+  !/devtools/client/shared/test/shared-head.js
+  !/devtools/client/shared/test/telemetry-test-helpers.js
+
+# Each metrics tests is loaded in a separate .ini file. This way the test is executed
+# individually, without any other test being executed before or after.
+[browser_metrics_webconsole.js]
+skip-if = os != 'linux' || debug || asan # Results should be platform agnostic - only run on linux64-opt
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/metrics/browser_metrics_webconsole.js
@@ -0,0 +1,69 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from ../../../shared/test/shared-head.js */
+
+/**
+ * This test records the number of modules loaded by DevTools, as well as the total count
+ * of characters in those modules, when opening the webconsole. These metrics are
+ * retrieved by perfherder via logs.
+ */
+
+const TEST_URL = "data:text/html;charset=UTF-8,<div>Webconsole modules load test</div>";
+
+add_task(async function() {
+  const toolbox = await openNewTabAndToolbox(TEST_URL, "webconsole");
+  const hud = toolbox.getCurrentPanel().hud;
+
+  // Retrieve the browser loader dedicated to the WebConsole.
+  const webconsoleLoader = hud.ui.browserLoader;
+  const loaders = [loader.provider.loader, webconsoleLoader.loader];
+
+  const allModules = getFilteredModules("", loaders);
+  const webconsoleModules = getFilteredModules("devtools/client/webconsole", loaders);
+
+  const allModulesCount = allModules.length;
+  const webconsoleModulesCount = webconsoleModules.length;
+
+  const allModulesChars = countCharsInModules(allModules);
+  const webconsoleModulesChars = countCharsInModules(webconsoleModules);
+
+  const PERFHERDER_DATA = {
+    framework: {
+      name: "devtools",
+    },
+    suites: [{
+      name: "webconsole-metrics",
+      value: allModulesChars,
+      subtests: [
+        {
+          name: "webconsole-modules",
+          value: webconsoleModulesCount,
+        },
+        {
+          name: "webconsole-chars",
+          value: webconsoleModulesChars,
+        },
+        {
+          name: "all-modules",
+          value: allModulesCount,
+        },
+        {
+          name: "all-chars",
+          value: allModulesChars,
+        },
+      ],
+    }],
+  };
+  info("PERFHERDER_DATA: " + JSON.stringify(PERFHERDER_DATA));
+
+  // Simply check that we found valid values.
+  ok(allModulesCount > webconsoleModulesCount &&
+     webconsoleModulesCount > 0, "Successfully recorded module count for WebConsole");
+  ok(allModulesChars > webconsoleModulesChars &&
+     webconsoleModulesChars > 0, "Successfully recorded char count for WebConsole");
+});
--- a/devtools/client/framework/test/metrics/head.js
+++ b/devtools/client/framework/test/metrics/head.js
@@ -4,8 +4,29 @@
 /* import-globals-from ../../../shared/test/shared-head.js */
 /* import-globals-from ../../../shared/test/telemetry-test-helpers.js */
 
 // shared-head.js handles imports, constants, and utility functions
 Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js", this);
 
 // So that PERFHERDER data can be extracted from the logs.
 SimpleTest.requestCompleteLog();
+
+function getFilteredModules(filter, loaders) {
+  let modules = [];
+  for (const l of loaders) {
+    const loaderModulesMap = l.modules;
+    const loaderModulesPaths = Object.keys(loaderModulesMap);
+    modules = modules.concat(loaderModulesPaths);
+  }
+  return modules.filter(url => url.includes(filter));
+}
+
+function countCharsInModules(modules) {
+  return modules.reduce((sum, uri) => {
+    try {
+      return sum + require("raw!" + uri).length;
+    } catch (e) {
+      // Ignore failures
+      return sum;
+    }
+  }, 0);
+}
--- a/devtools/client/webconsole/main.js
+++ b/devtools/client/webconsole/main.js
@@ -7,15 +7,19 @@
 "use strict";
 
 const { BrowserLoader } = ChromeUtils.import("resource://devtools/client/shared/browser-loader.js");
 
 this.WebConsoleWrapper = function(parentNode, hud, toolbox, owner, document) {
   // Initialize module loader and load all modules of the new inline
   // preview feature. The entire code-base doesn't need any extra
   // privileges and runs entirely in content scope.
-  const WebConsoleWrapper = BrowserLoader({
+  const browserLoader = BrowserLoader({
     baseURI: "resource://devtools/client/webconsole/",
     window,
-  }).require("./webconsole-wrapper");
+  });
 
+  // Expose the browserLoader instance on the webconsole hud for metrics tests.
+  hud.browserLoader = browserLoader;
+
+  const WebConsoleWrapper = browserLoader.require("./webconsole-wrapper");
   return new WebConsoleWrapper(parentNode, hud, toolbox, owner, document);
 };