Bug 1540114 - Bail out if any of the MOZ_PROFILER_STARTUP_FEATURES is not recognized - r=mstange
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 30 Apr 2019 01:46:09 +0000
changeset 530678 efbefb8b495104c7574eae481a6a5d7fc31e9f7e
parent 530677 e9a5f9d75b144d8927e75c6f3a610efd96c169a2
child 530679 33b606ed4e09fc17d2d0d548dd7d627fc2a8ede7
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1540114
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 1540114 - Bail out if any of the MOZ_PROFILER_STARTUP_FEATURES is not recognized - r=mstange It is too easy to mistype a feature name, and be confused or misled by the results. This patch will catch such errors. The previous code was going through each possible feature, seeing if it was in MOZ_PROFILER_STARTUP_FEATURES -- Meaning unknown names would just be ignored. The new code is doing the reverse: Going through all names in MOZ_PROFILER_STARTUP_FEATURES, trying to match each one with possible features; if not found, we indicate the first name that is unknown, show the help and exit. Differential Revision: https://phabricator.services.mozilla.com/D25531
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2623,38 +2623,37 @@ GeckoProfilerReporter::CollectReports(ns
       "Memory used by LUL, a stack unwinder used by the Gecko Profiler.");
 #endif
 
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(GeckoProfilerReporter, nsIMemoryReporter)
 
-static bool HasFeature(const char** aFeatures, uint32_t aFeatureCount,
-                       const char* aFeature) {
-  for (size_t i = 0; i < aFeatureCount; i++) {
-    if (strcmp(aFeatures[i], aFeature) == 0) {
-      return true;
-    }
+static uint32_t ParseFeature(const char* aFeature) {
+#define PARSE_FEATURE_BIT(n_, str_, Name_, desc_) \
+  if (strcmp(aFeature, str_) == 0) {              \
+    return ProfilerFeature::Name_;                \
   }
-  return false;
+
+  PROFILER_FOR_EACH_FEATURE(PARSE_FEATURE_BIT)
+
+#undef PARSE_FEATURE_BIT
+
+  printf("\nUnrecognized feature \"%s\".\n\n", aFeature);
+  PrintUsageThenExit(1);
+  return 0;
 }
 
 uint32_t ParseFeaturesFromStringArray(const char** aFeatures,
                                       uint32_t aFeatureCount) {
-#define ADD_FEATURE_BIT(n_, str_, Name_, desc_)     \
-  if (HasFeature(aFeatures, aFeatureCount, str_)) { \
-    features |= ProfilerFeature::Name_;             \
+  uint32_t features = 0;
+  for (size_t i = 0; i < aFeatureCount; i++) {
+    features |= ParseFeature(aFeatures[i]);
   }
-
-  uint32_t features = 0;
-  PROFILER_FOR_EACH_FEATURE(ADD_FEATURE_BIT)
-
-#undef ADD_FEATURE_BIT
-
   return features;
 }
 
 // Find the RegisteredThread for the current thread. This should only be called
 // in places where TLSRegisteredThread can't be used.
 static RegisteredThread* FindCurrentThreadRegisteredThread(PSLockRef aLock) {
   int id = Thread::GetCurrentId();
   const Vector<UniquePtr<RegisteredThread>>& registeredThreads =