Bug 1365400 - Add nsIProfiler::GetAllFeatures. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Jun 2017 00:20:35 -0400
changeset 595713 4300f755793c5bcc3488c8adb66296b5760fd213
parent 594149 da66c4a05fda49d457d9411a7092fed87cf9e53a
child 595714 16e4aa82033fe894f920e3b04886424b4a396845
push id64430
push userbmo:mstange@themasta.com
push dateFri, 16 Jun 2017 18:53:15 +0000
reviewersnjn
bugs1365400
milestone56.0a1
Bug 1365400 - Add nsIProfiler::GetAllFeatures. r?njn MozReview-Commit-ID: EfjiUYvfIgM
tools/profiler/gecko/nsIProfiler.idl
tools/profiler/gecko/nsProfiler.cpp
--- a/tools/profiler/gecko/nsIProfiler.idl
+++ b/tools/profiler/gecko/nsIProfiler.idl
@@ -60,19 +60,30 @@ interface nsIProfiler : nsISupports
 
   [implicit_jscontext]
   nsISupports getProfileDataAsArrayBuffer([optional] in double aSinceTime);
 
   void dumpProfileToFileAsync(in ACString aFilename,
                               [optional] in double aSinceTime);
 
   boolean IsActive();
+
+  /**
+   * 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);
 
   /**
+   * 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);
+
+  /**
    * The starting parameters that were sent to the profiler for sampling.
    * If the profiler is not currently sampling, this will return null.
    */
   [noscript] readonly attribute nsIProfilerStartParams startParams;
 
   void GetBufferInfo(out uint32_t aCurrentPosition, out uint32_t aTotalSize,
                      out uint32_t aGeneration);
 
--- a/tools/profiler/gecko/nsProfiler.cpp
+++ b/tools/profiler/gecko/nsProfiler.cpp
@@ -413,50 +413,63 @@ nsProfiler::GetElapsedTime(double* aElap
 
 NS_IMETHODIMP
 nsProfiler::IsActive(bool *aIsActive)
 {
   *aIsActive = profiler_is_active();
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList)
+static void
+GetArrayOfStringsForFeatures(uint32_t aFeatures,
+                             uint32_t* aCount, char*** aFeatureList)
 {
-  uint32_t features = profiler_get_available_features();
-
   #define COUNT_IF_SET(n_, str_, Name_) \
-    if (ProfilerFeature::Has##Name_(features)) { \
+    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*)));
 
   #define DUP_IF_SET(n_, str_, Name_) \
-    if (ProfilerFeature::Has##Name_(features)) { \
+    if (ProfilerFeature::Has##Name_(aFeatures)) { \
       size_t strLen = strlen(str_); \
       featureList[i] = static_cast<char*>( \
         nsMemory::Clone(str_, (strLen + 1) * sizeof(char))); \
       i++; \
     }
 
   // Insert the strings for the features in use.
   size_t i = 0;
   PROFILER_FOR_EACH_FEATURE(DUP_IF_SET)
 
-  #undef STRDUP_IF_SET
+  #undef DUP_IF_SET
 
   *aFeatureList = featureList;
   *aCount = len;
+}
+
+NS_IMETHODIMP
+nsProfiler::GetFeatures(uint32_t* aCount, char*** aFeatureList)
+{
+  uint32_t features = profiler_get_available_features();
+  GetArrayOfStringsForFeatures(features, aCount, aFeatureList);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsProfiler::GetAllFeatures(uint32_t* aCount, char*** aFeatureList)
+{
+  GetArrayOfStringsForFeatures((uint32_t)-1, aCount, aFeatureList);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProfiler::GetStartParams(nsIProfilerStartParams** aRetVal)
 {
   if (!profiler_is_active()) {
     *aRetVal = nullptr;