Bug 1429705 - Enable ESLint rule mozilla/use-services for tools/profiler. r?mstange draft
authorMark Banner <standard8@mozilla.com>
Wed, 10 Jan 2018 19:16:17 +0000
changeset 718979 bd2ca6725cced8cdcaf057684240c806a3c64b3e
parent 718505 d5f42a23909eb181274731b07e4984bfbd18557d
child 745670 ddf82be94eb9f624ffa87dd98f207520a9d0f83f
push id95123
push userbmo:standard8@mozilla.com
push dateThu, 11 Jan 2018 09:00:20 +0000
reviewersmstange
bugs1429705
milestone59.0a1
Bug 1429705 - Enable ESLint rule mozilla/use-services for tools/profiler. r?mstange MozReview-Commit-ID: elODEiff9w
.eslintrc.js
tools/profiler/tests/head_profiler.js
tools/profiler/tests/test_asm.js
tools/profiler/tests/test_enterjit_osr.js
tools/profiler/tests/test_enterjit_osr_disabling.js
tools/profiler/tests/test_enterjit_osr_enabling.js
tools/profiler/tests/test_get_features.js
tools/profiler/tests/test_pause.js
tools/profiler/tests/test_run.js
tools/profiler/tests/test_shared_library.js
tools/profiler/tests/test_start.js
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -31,15 +31,14 @@ module.exports = {
       // Browser: Bug 1421379
       "browser/extensions/shield-recipe-client/test/browser/head.js",
       "browser/modules/offlineAppCache.jsm",
       "devtools/**",
       "dom/indexedDB/**",
       "extensions/pref/**",
       "mobile/android/**",
       "testing/**",
-      "tools/profiler/**",
     ],
     "rules": {
       "mozilla/use-services": "off",
     }
   }]
 };
--- a/tools/profiler/tests/head_profiler.js
+++ b/tools/profiler/tests/head_profiler.js
@@ -1,16 +1,19 @@
 /* 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/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
+
 function getInflatedStackLocations(thread, sample) {
   let stackTable = thread.stackTable;
   let frameTable = thread.frameTable;
   let stringTable = thread.stringTable;
   let SAMPLE_STACK_SLOT = thread.samples.schema.stack;
   let STACK_PREFIX_SLOT = stackTable.schema.prefix;
   let STACK_FRAME_SLOT = stackTable.schema.frame;
   let FRAME_LOCATION_SLOT = frameTable.schema.location;
--- a/tools/profiler/tests/test_asm.js
+++ b/tools/profiler/tests/test_asm.js
@@ -1,41 +1,37 @@
 // Check that asm.js code shows up on the stack.
 function run_test() {
-    let p = Cc["@mozilla.org/tools/profiler;1"];
-
     // Just skip the test if the profiler component isn't present.
-    if (!p)
-        return;
-    p = p.getService(Ci.nsIProfiler);
-    if (!p)
-        return;
+    if (!AppConstants.MOZ_GECKO_PROFILER) {
+      return;
+    }
 
     // This test assumes that it's starting on an empty profiler stack.
     // (Note that the other profiler tests also assume the profiler
     // isn't already started.)
-    Assert.ok(!p.IsActive());
+    Assert.ok(!Services.profiler.IsActive());
 
     let jsFuns = Cu.getJSTestingFunctions();
     if (!jsFuns.isAsmJSCompilationAvailable())
         return;
 
     const ms = 10;
-    p.StartProfiler(10000, ms, ["js"], 1);
+    Services.profiler.StartProfiler(10000, ms, ["js"], 1);
 
     let stack = null;
     function ffi_function() {
         var delayMS = 5;
         while (1) {
             let then = Date.now();
             do {
               // do nothing
             } while (Date.now() - then < delayMS);
 
-            var thread0 = p.getProfileData().threads[0];
+            var thread0 = Services.profiler.getProfileData().threads[0];
 
             if (delayMS > 30000)
                 return;
 
             delayMS *= 2;
 
             if (thread0.samples.data.length == 0)
                 continue;
@@ -72,10 +68,10 @@ function run_test() {
     var i3 = stack.indexOf("FFI trampoline");
     Assert.ok(i3 !== -1);
     var i4 = stack.indexOf("ffi_function");
     Assert.ok(i4 !== -1);
     Assert.ok(i1 < i2);
     Assert.ok(i2 < i3);
     Assert.ok(i3 < i4);
 
-    p.StopProfiler();
+    Services.profiler.StopProfiler();
 }
--- a/tools/profiler/tests/test_enterjit_osr.js
+++ b/tools/profiler/tests/test_enterjit_osr.js
@@ -1,41 +1,37 @@
 // Check that the EnterJIT frame, added by the JIT trampoline and
 // usable by a native unwinder to resume unwinding after encountering
 // JIT code, is pushed as expected.
 function run_test() {
-    let p = Cc["@mozilla.org/tools/profiler;1"];
-    // Just skip the test if the profiler component isn't present.
-    if (!p)
-        return;
-    p = p.getService(Ci.nsIProfiler);
-    if (!p)
-        return;
+    if (!AppConstants.MOZ_GECKO_PROFILER) {
+      return;
+    }
 
     // This test assumes that it's starting on an empty profiler stack.
     // (Note that the other profiler tests also assume the profiler
     // isn't already started.)
-    Assert.ok(!p.IsActive());
+    Assert.ok(!Services.profiler.IsActive());
 
     const ms = 5;
-    p.StartProfiler(100, ms, ["js"], 1);
+    Services.profiler.StartProfiler(100, ms, ["js"], 1);
 
     function arbitrary_name() {
         // A frame for |arbitrary_name| has been pushed.  Do a sequence of
         // increasingly long spins until we get a sample.
         var delayMS = 5;
         while (1) {
             info("loop: ms = " + delayMS);
             let then = Date.now();
             do {
                 let n = 10000;
                 while (--n); // OSR happens here
                 // Spin in the hope of getting a sample.
             } while (Date.now() - then < delayMS);
-            let pr = p.getProfileData().threads[0];
+            let pr = Services.profiler.getProfileData().threads[0];
             if (pr.samples.data.length > 0 || delayMS > 30000)
                 return pr;
             delayMS *= 2;
         }
     }
 
     var profile = arbitrary_name();
 
@@ -50,10 +46,10 @@ function run_test() {
     for (var i = 0; i < stack.length; i++) {
         if (stack[i].match(/arbitrary_name/)) {
             Assert.equal(gotName, false);
             gotName = true;
         }
     }
     Assert.equal(gotName, true);
 
-    p.StopProfiler();
+    Services.profiler.StopProfiler();
 }
--- a/tools/profiler/tests/test_enterjit_osr_disabling.js
+++ b/tools/profiler/tests/test_enterjit_osr_disabling.js
@@ -1,21 +1,18 @@
 function run_test() {
-    let p = Cc["@mozilla.org/tools/profiler;1"];
-    // Just skip the test if the profiler component isn't present.
-    if (!p)
-      return;
-    p = p.getService(Ci.nsIProfiler);
-    if (!p)
-      return;
+  // Just skip the test if the profiler component isn't present.
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
 
-    Assert.ok(!p.IsActive());
+  Assert.ok(!Services.profiler.IsActive());
 
-    p.StartProfiler(100, 10, ["js"], 1);
-    // The function is entered with the profiler enabled
-    (function() {
-      p.StopProfiler();
-      let n = 10000;
-      while (--n); // OSR happens here with the profiler disabled.
-      // An assertion will fail when this function returns, if the
-      // profiler stack was misbalanced.
-    })();
+  Services.profiler.StartProfiler(100, 10, ["js"], 1);
+  // The function is entered with the profiler enabled
+  (function() {
+    Services.profiler.StopProfiler();
+    let n = 10000;
+    while (--n); // OSR happens here with the profiler disabled.
+    // An assertion will fail when this function returns, if the
+    // profiler stack was misbalanced.
+  })();
 }
--- a/tools/profiler/tests/test_enterjit_osr_enabling.js
+++ b/tools/profiler/tests/test_enterjit_osr_enabling.js
@@ -1,21 +1,17 @@
 function run_test() {
-    let p = Cc["@mozilla.org/tools/profiler;1"];
-    // Just skip the test if the profiler component isn't present.
-    if (!p)
-      return;
-    p = p.getService(Ci.nsIProfiler);
-    if (!p)
-      return;
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
 
-    Assert.ok(!p.IsActive());
+  Assert.ok(!Services.profiler.IsActive());
 
-    // The function is entered with the profiler disabled.
-    (function() {
-      p.StartProfiler(100, 10, ["js"], 1);
-      let n = 10000;
-      while (--n); // OSR happens here with the profiler enabled.
-      // An assertion will fail when this function returns, if the
-      // profiler stack was misbalanced.
-    })();
-    p.StopProfiler();
+  // The function is entered with the profiler disabled.
+  (function() {
+    Services.profiler.StartProfiler(100, 10, ["js"], 1);
+    let n = 10000;
+    while (--n); // OSR happens here with the profiler enabled.
+    // An assertion will fail when this function returns, if the
+    // profiler stack was misbalanced.
+  })();
+  Services.profiler.StopProfiler();
 }
--- a/tools/profiler/tests/test_get_features.js
+++ b/tools/profiler/tests/test_get_features.js
@@ -1,18 +1,12 @@
 /* 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/. */
 
 function run_test() {
-  // If we can't get the profiler component then assume gecko was
-  // built without it and pass all the tests
-  var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
-  if (!profilerCc)
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
+  }
 
-  var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
-  if (!profiler)
-    return;
-
-  var profilerFeatures = profiler.GetFeatures([]);
+  var profilerFeatures = Services.profiler.GetFeatures([]);
   Assert.ok(profilerFeatures != null);
 }
--- a/tools/profiler/tests/test_pause.js
+++ b/tools/profiler/tests/test_pause.js
@@ -1,35 +1,29 @@
 /* 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/. */
 
 function run_test() {
-  // If we can't get the profiler component then assume gecko was
-  // built without it and pass all the tests
-  var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
-  if (!profilerCc)
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
+  }
 
-  var profiler = profilerCc.getService(Ci.nsIProfiler);
-  if (!profiler)
-    return;
+  Assert.ok(!Services.profiler.IsActive());
+  Assert.ok(!Services.profiler.IsPaused());
 
-  Assert.ok(!profiler.IsActive());
-  Assert.ok(!profiler.IsPaused());
+  Services.profiler.StartProfiler(1000, 10, [], 0);
+
+  Assert.ok(Services.profiler.IsActive());
 
-  profiler.StartProfiler(1000, 10, [], 0);
-
-  Assert.ok(profiler.IsActive());
+  Services.profiler.PauseSampling();
 
-  profiler.PauseSampling();
+  Assert.ok(Services.profiler.IsPaused());
 
-  Assert.ok(profiler.IsPaused());
+  Services.profiler.ResumeSampling();
 
-  profiler.ResumeSampling();
-
-  Assert.ok(!profiler.IsPaused());
+  Assert.ok(!Services.profiler.IsPaused());
 
-  profiler.StopProfiler();
-  Assert.ok(!profiler.IsActive());
-  Assert.ok(!profiler.IsPaused());
+  Services.profiler.StopProfiler();
+  Assert.ok(!Services.profiler.IsActive());
+  Assert.ok(!Services.profiler.IsPaused());
   do_test_finished();
 }
--- a/tools/profiler/tests/test_run.js
+++ b/tools/profiler/tests/test_run.js
@@ -1,44 +1,38 @@
 /* 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/. */
 
 function run_test() {
-  // If we can't get the profiler component then assume gecko was
-  // built without it and pass all the tests
-  var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
-  if (!profilerCc)
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
+  }
 
-  var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
-  if (!profiler)
-    return;
+  Assert.ok(!Services.profiler.IsActive());
 
-  Assert.ok(!profiler.IsActive());
+  Services.profiler.StartProfiler(1000, 10, [], 0);
 
-  profiler.StartProfiler(1000, 10, [], 0);
-
-  Assert.ok(profiler.IsActive());
+  Assert.ok(Services.profiler.IsActive());
 
   do_test_pending();
 
   do_timeout(1000, function wait() {
     // Check text profile format
-    var profileStr = profiler.GetProfile();
+    var profileStr = Services.profiler.GetProfile();
     Assert.ok(profileStr.length > 10);
 
     // check json profile format
-    var profileObj = profiler.getProfileData();
+    var profileObj = Services.profiler.getProfileData();
     Assert.notEqual(profileObj, null);
     Assert.notEqual(profileObj.threads, null);
     Assert.ok(profileObj.threads.length >= 1);
     Assert.notEqual(profileObj.threads[0].samples, null);
     // NOTE: The number of samples will be empty since we
     //       don't have any labels in the xpcshell code
 
-    profiler.StopProfiler();
-    Assert.ok(!profiler.IsActive());
+    Services.profiler.StopProfiler();
+    Assert.ok(!Services.profiler.IsActive());
     do_test_finished();
   });
 
 
 }
--- a/tools/profiler/tests/test_shared_library.js
+++ b/tools/profiler/tests/test_shared_library.js
@@ -1,24 +1,18 @@
 /* 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/. */
 
 function run_test() {
-  // If we can't get the profiler component then assume gecko was
-  // built without it and pass all the tests
-  var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
-  if (!profilerCc)
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
+  }
 
-  var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
-  if (!profiler)
-    return;
-
-  var libs = profiler.sharedLibraries;
+  var libs = Services.profiler.sharedLibraries;
 
   Assert.equal(typeof libs, "object");
   Assert.ok(Array.isArray(libs));
   Assert.equal(typeof libs, "object");
   Assert.ok(libs.length >= 1);
   Assert.equal(typeof libs[0], "object");
   Assert.equal(typeof libs[0].name, "string");
   Assert.equal(typeof libs[0].path, "string");
--- a/tools/profiler/tests/test_start.js
+++ b/tools/profiler/tests/test_start.js
@@ -1,25 +1,19 @@
 /* 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/. */
 
 function run_test() {
-  // If we can't get the profiler component then assume gecko was
-  // built without it and pass all the tests
-  var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
-  if (!profilerCc)
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
+  }
 
-  var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
-  if (!profiler)
-    return;
+  Assert.ok(!Services.profiler.IsActive());
 
-  Assert.ok(!profiler.IsActive());
+  Services.profiler.StartProfiler(10, 100, [], 0);
 
-  profiler.StartProfiler(10, 100, [], 0);
+  Assert.ok(Services.profiler.IsActive());
 
-  Assert.ok(profiler.IsActive());
+  Services.profiler.StopProfiler();
 
-  profiler.StopProfiler();
-
-  Assert.ok(!profiler.IsActive());
+  Assert.ok(!Services.profiler.IsActive());
 }