Bug 1353678 - Made duplicate Histograms.json keys build errors. r=gfritzsche
authordjmdev <djmdeveloper060796@gmail.com>
Wed, 12 Apr 2017 00:14:39 +0530
changeset 352510 0c63f689efc7e53bde45b64ed7f4017867475781
parent 352509 003d697d668654326489080a3a621c599f0bc0d9
child 352511 35a62ecf447561cfb74dbbb8781d97ad91953b20
push id89096
push usercbook@mozilla.com
push dateWed, 12 Apr 2017 06:58:32 +0000
treeherdermozilla-inbound@35a62ecf4475 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1353678
milestone55.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 1353678 - Made duplicate Histograms.json keys build errors. r=gfritzsche If duplicate keys are present in Histograms.json then histogram_tools.py will raise error.
toolkit/components/telemetry/histogram_tools.py
--- a/toolkit/components/telemetry/histogram_tools.py
+++ b/toolkit/components/telemetry/histogram_tools.py
@@ -448,24 +448,35 @@ associated with the histogram.  Returns 
 
     @staticmethod
     def exponential_bucket_parameters(definition):
         return (definition.get('low', 1),
                 definition['high'],
                 definition['n_buckets'])
 
 
+# This hook function loads the histograms into an OrderedDict.
+# It will raise a ValueError if duplicate keys are found.
+def load_histograms_into_dict(ordered_pairs):
+    d = collections.OrderedDict()
+    for key, value in ordered_pairs:
+        if key in d:
+            raise ValueError("Found duplicate key in Histograms file: %s" % key)
+        d[key] = value
+    return d
+
+
 # We support generating histograms from multiple different input files, not
 # just Histograms.json.  For each file's basename, we have a specific
 # routine to parse that file, and return a dictionary mapping histogram
 # names to histogram parameters.
 def from_Histograms_json(filename):
     with open(filename, 'r') as f:
         try:
-            histograms = json.load(f, object_pairs_hook=OrderedDict)
+            histograms = json.load(f, object_pairs_hook=load_histograms_into_dict)
         except ValueError, e:
             raise BaseException("error parsing histograms in %s: %s" % (filename, e.message))
     return histograms
 
 
 def from_UseCounters_conf(filename):
     return usecounters.generate_histograms(filename)