Bug 1544924 - Support filtering individual classes with MOZ_INSTRUMENT_CUSTOM_ELEMENTS;r=aswan
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 17 Apr 2019 01:12:41 +0000
changeset 469839 753a06be639a7a0c1d61458a76b4ff7662bed3de
parent 469838 63a585075956e9cc78f4fc145a4211ffe6381b06
child 469840 606bba3b09248942c5cdbfb44e119d40f9dd054c
push id35883
push userbtara@mozilla.com
push dateWed, 17 Apr 2019 21:47:29 +0000
treeherdermozilla-central@02b89c29412b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1544924
milestone68.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 1544924 - Support filtering individual classes with MOZ_INSTRUMENT_CUSTOM_ELEMENTS;r=aswan For example, you can do MOZ_INSTRUMENT_CUSTOM_ELEMENTS=MozXULElement,Button to limit output to classes containing those strings in their name Differential Revision: https://phabricator.services.mozilla.com/D27800
toolkit/content/customElements.js
--- a/toolkit/content/customElements.js
+++ b/toolkit/content/customElements.js
@@ -19,17 +19,17 @@ if (window.MozXULElement) {
 }
 
 const MozElements = {};
 window.MozElements = MozElements;
 
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-const instrumentClasses = !!env.get("MOZ_INSTRUMENT_CUSTOM_ELEMENTS");
+const instrumentClasses = env.get("MOZ_INSTRUMENT_CUSTOM_ELEMENTS");
 const instrumentedClasses = instrumentClasses ? new Set() : null;
 const instrumentedBaseClasses = instrumentClasses ? new WeakSet() : null;
 
 // If requested, wrap the normal customElements.define to give us a chance
 // to modify the class so we can instrument function calls in local development:
 if (instrumentClasses) {
   let define = window.customElements.define;
   window.customElements.define = function(name, c, opts) {
@@ -41,18 +41,21 @@ if (instrumentClasses) {
   }, { once: true, capture: true });
 }
 
 MozElements.printInstrumentation = function(collapsed) {
   let summaries = [];
   let totalCalls = 0;
   let totalTime = 0;
   for (let c of instrumentedClasses) {
+    // Allow passing in something like MOZ_INSTRUMENT_CUSTOM_ELEMENTS=MozXULElement,Button to filter
+    let includeClass = instrumentClasses == 1 ||
+        instrumentClasses.split(",").some(n => c.name.toLowerCase().includes(n.toLowerCase()));
     let summary = c.__instrumentation_summary;
-    if (summary) {
+    if (includeClass && summary) {
       summaries.push(summary);
       totalCalls += summary.totalCalls;
       totalTime += summary.totalTime;
     }
   }
   if (summaries.length) {
     let groupName = `Instrumentation data for custom elements in ${document.documentURI}`;
     console[collapsed ? "groupCollapsed" : "group"](groupName);
@@ -89,16 +92,17 @@ function instrumentCustomElementClass(c)
     }
   }
 }
 
 function instrumentIndividualClass(c) {
   if (instrumentedClasses.has((c))) {
     return;
   }
+
   instrumentedClasses.add((c));
   let data = { instances: 0 };
 
   function wrapFunction(name, fn) {
     return function() {
       if (!data[name]) {
         data[name] = {time: 0, calls: 0};
       }