Bug 1551106 part 2. Stop using [array] in profiler's GetFeatures/GetAllFeatures. r=gerald
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 21 May 2019 14:43:10 +0000
changeset 474757 09369fc85b211379428243a53c1e5d00d95f99fb
parent 474756 f454d7e7502cdade0993677166911085b231963d
child 474758 2180deaa2c68afd96ad39b6a0cba9c3d45a49c62
push id36046
push useraiakab@mozilla.com
push dateTue, 21 May 2019 21:45:52 +0000
treeherdermozilla-central@257f2c96cef5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1551106
milestone69.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 1551106 part 2. Stop using [array] in profiler's GetFeatures/GetAllFeatures. r=gerald Differential Revision: https://phabricator.services.mozilla.com/D30968
devtools/server/performance/profiler.js
toolkit/components/extensions/test/xpcshell/test_ext_geckoProfiler_schema.js
tools/profiler/gecko/nsIProfiler.idl
tools/profiler/gecko/nsProfiler.cpp
tools/profiler/tests/xpcshell/test_get_features.js
--- a/devtools/server/performance/profiler.js
+++ b/devtools/server/performance/profiler.js
@@ -193,17 +193,17 @@ const ProfilerManager = (function() {
     /**
      * Returns an array of feature strings, describing the profiler features
      * that are available on this platform. Can be called while the profiler
      * is stopped.
      *
      * @return {object}
      */
     getFeatures: function() {
-      return { features: Services.profiler.GetFeatures([]) };
+      return { features: Services.profiler.GetFeatures() };
     },
 
     /**
      * Returns an object with the values of the current status of the
      * circular buffer in the profiler, returning `position`, `totalSize`,
      * and the current `generation` of the buffer.
      *
      * @return {object}
--- a/toolkit/components/extensions/test/xpcshell/test_ext_geckoProfiler_schema.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_geckoProfiler_schema.js
@@ -21,17 +21,17 @@ add_task(async function() {
   });
 
   await extension.startup();
   let acceptedFeatures = await extension.awaitMessage("features");
   await extension.unload();
 
   Services.prefs.clearUserPref(acceptedExtensionIdsPref);
 
-  const allFeaturesAcceptedByProfiler = Services.profiler.GetAllFeatures([]);
+  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.`);
--- a/tools/profiler/gecko/nsIProfiler.idl
+++ b/tools/profiler/gecko/nsIProfiler.idl
@@ -75,23 +75,23 @@ interface nsIProfiler : nsISupports
    * Clear all registered and unregistered page information in prifiler.
    */
   void ClearAllPages();
 
   /**
    * Returns an array of the features that are supported in this build.
    * Features may vary depending on platform and build flags.
    */
-  void GetFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures);
+  Array<AUTF8String> GetFeatures();
 
   /**
    * Returns an array of all features that are supported by the profiler.
    * The array may contain features that are not supported in this build.
    */
-  void GetAllFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures);
+  Array<AUTF8String> GetAllFeatures();
 
   void GetBufferInfo(out uint32_t aCurrentPosition, out uint32_t aTotalSize,
                      out uint32_t aGeneration);
 
   /**
    * Returns the elapsed time, in milliseconds, since the profiler's epoch.
    * The epoch is guaranteed to be constant for the duration of the
    * process, but is otherwise arbitrary.
--- a/tools/profiler/gecko/nsProfiler.cpp
+++ b/tools/profiler/gecko/nsProfiler.cpp
@@ -494,57 +494,52 @@ nsProfiler::GetElapsedTime(double* aElap
 }
 
 NS_IMETHODIMP
 nsProfiler::IsActive(bool* aIsActive) {
   *aIsActive = profiler_is_active();
   return NS_OK;
 }
 
-static void GetArrayOfStringsForFeatures(uint32_t aFeatures, uint32_t* aCount,
-                                         char*** aFeatureList) {
+static void GetArrayOfStringsForFeatures(uint32_t aFeatures,
+                                         nsTArray<nsCString>& aFeatureList) {
 #define COUNT_IF_SET(n_, str_, Name_, desc_)    \
   if (ProfilerFeature::Has##Name_(aFeatures)) { \
     len++;                                      \
   }
 
   // Count the number of features in use.
   uint32_t len = 0;
   PROFILER_FOR_EACH_FEATURE(COUNT_IF_SET)
 
 #undef COUNT_IF_SET
 
-  auto featureList = static_cast<char**>(moz_xmalloc(len * sizeof(char*)));
+  aFeatureList.SetCapacity(len);
 
 #define DUP_IF_SET(n_, str_, Name_, desc_)      \
   if (ProfilerFeature::Has##Name_(aFeatures)) { \
-    featureList[i] = moz_xstrdup(str_);         \
-    i++;                                        \
+    aFeatureList.AppendElement(str_);           \
   }
 
   // Insert the strings for the features in use.
-  size_t i = 0;
   PROFILER_FOR_EACH_FEATURE(DUP_IF_SET)
 
 #undef DUP_IF_SET
-
-  *aFeatureList = featureList;
-  *aCount = len;
 }
 
 NS_IMETHODIMP
-nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList) {
+nsProfiler::GetFeatures(nsTArray<nsCString>& aFeatureList) {
   uint32_t features = profiler_get_available_features();
-  GetArrayOfStringsForFeatures(features, aCount, aFeatureList);
+  GetArrayOfStringsForFeatures(features, aFeatureList);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsProfiler::GetAllFeatures(uint32_t* aCount, char*** aFeatureList) {
-  GetArrayOfStringsForFeatures((uint32_t)-1, aCount, aFeatureList);
+nsProfiler::GetAllFeatures(nsTArray<nsCString>& aFeatureList) {
+  GetArrayOfStringsForFeatures((uint32_t)-1, aFeatureList);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProfiler::GetBufferInfo(uint32_t* aCurrentPosition, uint32_t* aTotalSize,
                           uint32_t* aGeneration) {
   MOZ_ASSERT(aCurrentPosition);
   MOZ_ASSERT(aTotalSize);
--- a/tools/profiler/tests/xpcshell/test_get_features.js
+++ b/tools/profiler/tests/xpcshell/test_get_features.js
@@ -2,11 +2,11 @@
  * 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 (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
   }
 
-  var profilerFeatures = Services.profiler.GetFeatures([]);
+  var profilerFeatures = Services.profiler.GetFeatures();
   Assert.ok(profilerFeatures != null);
 }