Bug 1374628 - Improve static_asserts in TelemetryHistogram.cpp. r=gfritzsche
authorIgor Timofeev <igor.timofeev@timodan.net>
Wed, 21 Jun 2017 14:02:36 +0100
changeset 365517 6dedf019826a
parent 365516 e9a5197a02e7
child 365518 7ddea63224d2
push id32077
push userkwierso@gmail.com
push dateThu, 22 Jun 2017 21:02:06 +0000
treeherdermozilla-central@4c6668cbaccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1374628, 1374419
milestone56.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 1374628 - Improve static_asserts in TelemetryHistogram.cpp. r=gfritzsche With bug 1374419 solved, static asserts in TelemetryHistogram.cpp can be improved. Specifically, JS::gcreason::NUM_TELEMETRY_REASONS can now be compared against GC_MINOR_REASON, GC_MINOR_REASON_LONG, and GC_REASON_2 in the now constexpr gHistograms. Likewise, mozilla::StartupTimeline::MAX_EVENT_ID can be compared against STARTUP_MEASUREMENT_ERRORS. This commit modifies the static asserts to perform these comparisons in place of ones against hardcoded values and modifies the accompanying comment to remove the TODO section.
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -1878,32 +1878,37 @@ void TelemetryHistogram::InitializeGloba
       nsCString extensionId(id);
       extensionId.AppendLiteral(EXTENSION_HISTOGRAM_SUFFIX);
       gKeyedHistograms.Put(extensionId,
                            new KeyedHistogram(id, expiration, h.histogramType,
                                               h.min, h.max, h.bucketCount, h.dataset));
     }
   }
 
-  // Some Telemetry histograms depend on the value of C++ constants and hardcode
-  // their values in Histograms.json.
-  // We add static asserts here for those values to match so that future changes
-  // don't go unnoticed.
-  // TODO: Compare explicitly with gHistograms[<histogram id>].bucketCount here
-  // once we can make gHistograms constexpr (requires VS2015).
-  static_assert((JS::gcreason::NUM_TELEMETRY_REASONS == 100),
-      "NUM_TELEMETRY_REASONS is assumed to be a fixed value in Histograms.json."
-      " If this was an intentional change, update this assert with its value "
-      "and update the n_values for the following in Histograms.json: "
-      "GC_MINOR_REASON, GC_MINOR_REASON_LONG, GC_REASON_2");
-  static_assert((mozilla::StartupTimeline::MAX_EVENT_ID == 16),
-      "MAX_EVENT_ID is assumed to be a fixed value in Histograms.json.  If this"
-      " was an intentional change, update this assert with its value and update"
-      " the n_values for the following in Histograms.json:"
-      " STARTUP_MEASUREMENT_ERRORS");
+    // Some Telemetry histograms depend on the value of C++ constants and hardcode
+    // their values in Histograms.json.
+    // We add static asserts here for those values to match so that future changes
+    // don't go unnoticed.
+    static_assert((JS::gcreason::NUM_TELEMETRY_REASONS + 1) ==
+                        gHistograms[mozilla::Telemetry::GC_MINOR_REASON].bucketCount &&
+                  (JS::gcreason::NUM_TELEMETRY_REASONS + 1) ==
+                        gHistograms[mozilla::Telemetry::GC_MINOR_REASON_LONG].bucketCount &&
+                  (JS::gcreason::NUM_TELEMETRY_REASONS + 1) ==
+                        gHistograms[mozilla::Telemetry::GC_REASON_2].bucketCount,
+                  "NUM_TELEMETRY_REASONS is assumed to be a fixed value in Histograms.json."
+                  " If this was an intentional change, update the n_values for the "
+                  "following in Histograms.json: GC_MINOR_REASON, GC_MINOR_REASON_LONG, "
+                  "GC_REASON_2");
+
+    static_assert((mozilla::StartupTimeline::MAX_EVENT_ID + 1) ==
+                        gHistograms[mozilla::Telemetry::STARTUP_MEASUREMENT_ERRORS].bucketCount,
+                  "MAX_EVENT_ID is assumed to be a fixed value in Histograms.json.  If this"
+                  " was an intentional change, update the n_values for the following in "
+                  "Histograms.json: STARTUP_MEASUREMENT_ERRORS");
+
 
   gInitDone = true;
 }
 
 void TelemetryHistogram::DeInitializeGlobalState()
 {
   StaticMutexAutoLock locker(gTelemetryHistogramMutex);
   gCanRecordBase = false;