Bug 1365400 - Add all profiler features to the enum list, and a test. r?kmag, r?njn draft
authorMarkus Stange <mstange@themasta.com>
Fri, 16 Jun 2017 14:52:30 -0400
changeset 595714 16e4aa82033fe894f920e3b04886424b4a396845
parent 595713 4300f755793c5bcc3488c8adb66296b5760fd213
child 633789 7adfcb804172054440bb1fbd6b06d1114d133b53
push id64430
push userbmo:mstange@themasta.com
push dateFri, 16 Jun 2017 18:53:15 +0000
reviewerskmag, njn
bugs1365400
milestone56.0a1
Bug 1365400 - Add all profiler features to the enum list, and a test. r?kmag, r?njn The source of truth for this list is in the PROFILER_FOR_EACH_FEATURE macro. MozReview-Commit-ID: 13qppZKVi1r
browser/components/extensions/schemas/geckoProfiler.json
browser/components/extensions/test/xpcshell/test_ext_geckoProfiler_schema.js
browser/components/extensions/test/xpcshell/xpcshell.ini
tools/profiler/public/GeckoProfiler.h
--- a/browser/components/extensions/schemas/geckoProfiler.json
+++ b/browser/components/extensions/schemas/geckoProfiler.json
@@ -13,16 +13,37 @@
       }
     ]
   },
   {
     "namespace": "geckoProfiler",
     "description": "Exposes the browser's profiler.",
 
     "permissions": ["geckoProfiler"],
+    "types": [
+      {
+        "id": "ProfilerFeature",
+        "type": "string",
+        "enum": [
+          "displaylistdump",
+          "gpu",
+          "java",
+          "js",
+          "layersdump",
+          "leaf",
+          "mainthreadio",
+          "memory",
+          "privacy",
+          "restyle",
+          "stackwalk",
+          "tasktracer",
+          "threads"
+        ]
+      }
+    ],
     "functions": [
       {
        "name": "start",
        "type": "function",
        "description": "Starts the profiler with the specified settings.",
        "async": true,
        "parameters": [
           {
@@ -37,24 +58,17 @@
               "interval": {
                 "type": "number",
                 "description": "Interval in milliseconds between samples of profiling data. A smaller value will increase the detail of the profiles captured."
               },
               "features": {
                 "type": "array",
                 "description": "A list of active features for the profiler.",
                 "items": {
-                  "type": "string",
-                  "enum": [
-                    "js",
-                    "stackwalk",
-                    "tasktracer",
-                    "leaf",
-                    "threads"
-                  ]
+                  "$ref": "ProfilerFeature"
                 }
               },
               "threads": {
                 "type": "array",
                 "description": "A list of thread names for which to capture profiles.",
                 "optional": true,
                 "items": {
                   "type": "string"
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/xpcshell/test_ext_geckoProfiler_schema.js
@@ -0,0 +1,42 @@
+"use strict";
+
+add_task(async function() {
+  const acceptedExtensionIdsPref = "extensions.geckoProfiler.acceptedExtensionIds";
+  Services.prefs.setCharPref(acceptedExtensionIdsPref, "profilertest@mozilla.com");
+
+  let extension = ExtensionTestUtils.loadExtension({
+    background: () => {
+      browser.test.sendMessage("features",
+        Object.values(browser.geckoProfiler.ProfilerFeature));
+    },
+    manifest: {
+      "permissions": ["geckoProfiler"],
+      "applications": {
+        "gecko": {
+          "id": "profilertest@mozilla.com",
+        },
+      },
+    },
+  });
+
+  await extension.startup();
+  let acceptedFeatures = await extension.awaitMessage("features");
+  await extension.unload();
+
+  Services.prefs.clearUserPref(acceptedExtensionIdsPref);
+
+  const allFeaturesAcceptedByProfiler = Services.profiler.GetAllFeatures([]);
+  ok(allFeaturesAcceptedByProfiler.length >= 2,
+    "Either we've massively reduced the profiler's feature set, or something is wrong.");
+
+  // Check that the list of available values in the ProfilerFeature enum
+  // matches the list of features supported by the profiler.
+  for (const feature of allFeaturesAcceptedByProfiler) {
+    ok(acceptedFeatures.includes(feature),
+      `The schema of the geckoProfiler.start() method should accept the "${feature}" feature.`);
+  }
+  for (const feature of acceptedFeatures) {
+    ok(allFeaturesAcceptedByProfiler.includes(feature),
+      `The schema of the geckoProfiler.start() method mentions a "${feature}" feature which is not supported by the profiler.`);
+  }
+});
--- a/browser/components/extensions/test/xpcshell/xpcshell.ini
+++ b/browser/components/extensions/test/xpcshell/xpcshell.ini
@@ -9,8 +9,9 @@ tags = webextensions
 [test_ext_browsingData_downloads.js]
 [test_ext_browsingData_passwords.js]
 [test_ext_browsingData_settings.js]
 [test_ext_history.js]
 [test_ext_manifest_commands.js]
 [test_ext_manifest_omnibox.js]
 [test_ext_manifest_permissions.js]
 [test_ext_geckoProfiler_control.js]
+[test_ext_geckoProfiler_schema.js]
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -148,16 +148,18 @@ using UniqueProfilerBacktrace =
 #define PROFILER_MARKER_PAYLOAD(marker_name, payload) \
   profiler_add_marker(marker_name, payload)
 
 #endif  // defined(MOZ_GECKO_PROFILER)
 
 // Higher-order macro containing all the feature info in one place. Define
 // |macro| appropriately to extract the relevant parts. Note that the number
 // values are used internally only and so can be changed without consequence.
+// Any changes to this list should also be applied to the feature list in
+// browser/components/extensions/schemas/geckoProfiler.json.
 #define PROFILER_FOR_EACH_FEATURE(macro) \
   /* Dump the display list with the textures. */ \
   macro(0, "displaylistdump", DisplayListDump) \
   \
   /* GPU Profiling (may not be supported by the GL). */ \
   macro(1, "gpu", GPU) \
   \
   /* Profile Java code (Android only). */ \