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 414223 6dedf019826a8b7ff4a616c2a145385ce9f91017
parent 414222 e9a5197a02e748a14b9411628db3cc2fa8d34530
child 414224 7ddea63224d27ffca46518e9625d36661927c8a9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [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;