Bug 1357682 - Part 1, helper function for keyed categorical histogram. r=gfritzsche draft
authorShih-Chiang Chien <schien@mozilla.com>
Tue, 11 Jul 2017 16:51:07 +0800
changeset 608270 446543601e9234da25d292018d8a6e8a7ac7ba22
parent 602698 0b5603017c25e943ba3ab97cb46d88adf1e6a3e4
child 608271 3cce84331920e285ec3f045a4e836bc9e1ff5ade
push id68223
push userschien@mozilla.com
push dateThu, 13 Jul 2017 10:51:36 +0000
reviewersgfritzsche
bugs1357682
milestone56.0a1
Bug 1357682 - Part 1, helper function for keyed categorical histogram. r=gfritzsche Create AccumulateCategoricalKeyed() to specify both key and value for the categorical histogram, sinc AccumulateCategorical() only support non-keyed histogram. MozReview-Commit-ID: qYMnL9P6Ik
toolkit/components/telemetry/Telemetry.h
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -108,16 +108,33 @@ template<class E>
 void AccumulateCategorical(E enumValue) {
   static_assert(IsCategoricalLabelEnum<E>::value,
                 "Only categorical label enum types are supported.");
   Accumulate(static_cast<HistogramID>(CategoricalLabelId<E>::value),
              static_cast<uint32_t>(enumValue));
 };
 
 /**
+ * Adds sample to a keyed categorical histogram defined in TelemetryHistogramEnums.h
+ * This is the typesafe - and preferred - way to use the keyed categorical histograms
+ * by passing values from the corresponding Telemetry::LABELS_* enum.
+ *
+ * @param key - the string key
+ * @param enumValue - Label value from one of the Telemetry::LABELS_* enums.
+ */
+template<class E>
+void AccumulateCategoricalKeyed(const nsCString& key, E enumValue) {
+  static_assert(IsCategoricalLabelEnum<E>::value,
+                "Only categorical label enum types are supported.");
+  Accumulate(static_cast<HistogramID>(CategoricalLabelId<E>::value),
+             key,
+             static_cast<uint32_t>(enumValue));
+};
+
+/**
  * Adds sample to a categorical histogram defined in TelemetryHistogramEnums.h
  * This string will be matched against the labels defined in Histograms.json.
  * If the string does not match a label defined for the histogram, nothing will
  * be recorded.
  *
  * @param id - The histogram id.
  * @param label - A string label value that is defined in Histograms.json for this histogram.
  */