Bug 1419761 - Rename 'histogram_tools.py' to 'parse_histograms.py'. r=Dexter draft
authorRyan Leake <leaker2@uni.coventry.ac.uk>
Thu, 23 Nov 2017 20:21:09 +0000
changeset 703225 5f81b85e097194c12d6c91057cc24057b52a337d
parent 699660 45e764dbfd4eb7a0b27417e446eb3502b5782a27
child 741715 6ede8d400e3d00ac53bc2c9da315c2d4b682c6ea
push id90758
push userbmo:leakey94@gmail.com
push dateFri, 24 Nov 2017 16:45:24 +0000
reviewersDexter
bugs1419761
milestone59.0a1
Bug 1419761 - Rename 'histogram_tools.py' to 'parse_histograms.py'. r=Dexter MozReview-Commit-ID: J8wM1OZbMxd
toolkit/components/telemetry/gen-histogram-bucket-ranges.py
toolkit/components/telemetry/gen-histogram-data.py
toolkit/components/telemetry/gen-histogram-enum.py
toolkit/components/telemetry/histogram_tools.py
toolkit/components/telemetry/parse_histograms.py
toolkit/components/telemetry/tests/python/test_histogramtools_non_strict.py
--- a/toolkit/components/telemetry/gen-histogram-bucket-ranges.py
+++ b/toolkit/components/telemetry/gen-histogram-bucket-ranges.py
@@ -2,52 +2,52 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Write out detailed histogram information, including the ranges of the
 # buckets specified by each histogram.
 
 import sys
-import histogram_tools
+import parse_histograms
 import json
 
 from collections import OrderedDict
 
 
 def main(argv):
     filenames = argv
 
     all_histograms = OrderedDict()
 
-    for histogram in histogram_tools.from_files(filenames):
+    for histogram in parse_histograms.from_files(filenames):
         name = histogram.name()
         parameters = OrderedDict()
         table = {
             'boolean': '2',
             'flag': '3',
             'enumerated': '1',
             'linear': '1',
             'exponential': '0',
             'count': '4',
         }
         # Use __setitem__ because Python lambdas are so limited.
-        histogram_tools.table_dispatch(histogram.kind(), table,
-                                       lambda k: parameters.__setitem__('kind', k))
+        parse_histograms.table_dispatch(histogram.kind(), table,
+                                        lambda k: parameters.__setitem__('kind', k))
         if histogram.low() == 0:
             parameters['min'] = 1
         else:
             parameters['min'] = histogram.low()
 
         try:
             buckets = histogram.ranges()
             parameters['buckets'] = buckets
             parameters['max'] = buckets[-1]
             parameters['bucket_count'] = len(buckets)
-        except histogram_tools.DefinitionException:
+        except parse_histograms.DefinitionException:
             continue
 
         all_histograms.update({name: parameters})
 
     print json.dumps({'histograms': all_histograms})
 
 
 main(sys.argv[1:])
--- a/toolkit/components/telemetry/gen-histogram-data.py
+++ b/toolkit/components/telemetry/gen-histogram-data.py
@@ -4,17 +4,17 @@
 
 # Write out histogram information for C++.  The histograms are defined
 # in a file provided as a command-line argument.
 
 from __future__ import print_function
 from shared_telemetry_utils import StringTable, static_assert, ParserError
 
 import sys
-import histogram_tools
+import parse_histograms
 
 banner = """/* This file is auto-generated, see gen-histogram-data.py.  */
 """
 
 
 def print_array_entry(output, histogram, name_index, exp_index, label_index,
                       label_count, key_index, key_count):
     cpp_guard = histogram.cpp_guard()
@@ -188,17 +188,17 @@ def write_histogram_ranges(output, histo
 
         if cpp_guard:
             print("#endif", file=output)
     print("};", file=output)
 
 
 def main(output, *filenames):
     try:
-        histograms = list(histogram_tools.from_files(filenames))
+        histograms = list(parse_histograms.from_files(filenames))
     except ParserError as ex:
         print("\nError processing histograms:\n" + str(ex) + "\n")
         sys.exit(1)
 
     print(banner, file=output)
     write_histogram_table(output, histograms)
     write_histogram_ranges(output, histograms)
     write_histogram_static_asserts(output, histograms)
--- a/toolkit/components/telemetry/gen-histogram-enum.py
+++ b/toolkit/components/telemetry/gen-histogram-enum.py
@@ -10,17 +10,17 @@
 #   - HistogramLastUseCounter
 #   - HistogramUseCounterCount
 #
 # The histograms are defined in files provided as command-line arguments.
 
 from __future__ import print_function
 from shared_telemetry_utils import ParserError
 
-import histogram_tools
+import parse_histograms
 import itertools
 import sys
 
 
 banner = """/* This file is auto-generated, see gen-histogram-enum.py.  */
 """
 
 header = """
@@ -41,26 +41,26 @@ footer = """
 
 def main(output, *filenames):
     # Print header.
     print(banner, file=output)
     print(header, file=output)
 
     # Load the histograms.
     try:
-        all_histograms = list(histogram_tools.from_files(filenames))
+        all_histograms = list(parse_histograms.from_files(filenames))
     except ParserError as ex:
         print("\nError processing histograms:\n" + str(ex) + "\n")
         sys.exit(1)
 
     groups = itertools.groupby(all_histograms,
                                lambda h: h.name().startswith("USE_COUNTER2_"))
 
     # Print the histogram enums.
-    # Note that histogram_tools.py guarantees that all of the USE_COUNTER2_*
+    # Note that parse_histograms.py guarantees that all of the USE_COUNTER2_*
     # histograms are defined in a contiguous block.  We therefore assume
     # that there's at most one group for which use_counter_group is true.
     print("enum HistogramID : uint32_t {", file=output)
     seen_use_counters = False
     for (use_counter_group, histograms) in groups:
         if use_counter_group:
             seen_use_counters = True
 
rename from toolkit/components/telemetry/histogram_tools.py
rename to toolkit/components/telemetry/parse_histograms.py
--- a/toolkit/components/telemetry/histogram_tools.py
+++ b/toolkit/components/telemetry/parse_histograms.py
@@ -35,17 +35,17 @@ ALWAYS_ALLOWED_KEYS = [
     'record_in_processes',
 ]
 
 BASE_DOC_URL = ("https://firefox-source-docs.mozilla.org/toolkit/components/"
                 "telemetry/telemetry/")
 HISTOGRAMS_DOC_URL = (BASE_DOC_URL + "collection/histograms.html")
 SCALARS_DOC_URL = (BASE_DOC_URL + "collection/scalars.html")
 
-# histogram_tools.py is used by scripts from a mozilla-central build tree
+# parse_histograms.py is used by scripts from a mozilla-central build tree
 # and also by outside consumers, such as the telemetry server.  We need
 # to ensure that importing things works in both contexts.  Therefore,
 # unconditionally importing things that are local to the build tree, such
 # as buildconfig, is a no-no.
 try:
     import buildconfig
 
     # Need to update sys.path to be able to find usecounters.
--- a/toolkit/components/telemetry/tests/python/test_histogramtools_non_strict.py
+++ b/toolkit/components/telemetry/tests/python/test_histogramtools_non_strict.py
@@ -5,72 +5,72 @@
 import json
 import mozunit
 import sys
 import unittest
 from os import path
 
 TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir))
 sys.path.append(TELEMETRY_ROOT_PATH)
-import histogram_tools   # noqa: E402
+import parse_histograms   # noqa: E402
 
 
 def load_histogram(histograms):
     """Parse the passed Histogram and return a dictionary mapping histogram
     names to histogram parameters.
 
     :param histogram: Histogram as a python dictionary
     :returns: Parsed Histogram dictionary mapping histogram names to histogram parameters
     """
     def hook(ps):
-        return histogram_tools.load_histograms_into_dict(ps, strict_type_checks=False)
+        return parse_histograms.load_histograms_into_dict(ps, strict_type_checks=False)
     return json.loads(json.dumps(histograms), object_pairs_hook=hook)
 
 
 class TestParser(unittest.TestCase):
     def test_unknown_field(self):
         SAMPLE_HISTOGRAM = {
             "A11Y_INSTANTIATED_FLAG": {
                 "record_in_processes": ["main", "content"],
                 "expires_in_version": "never",
                 "kind": "flag",
                 "description": "has accessibility support been instantiated",
                 "new_field": "Its a new field"
                 }}
         histograms = load_histogram(SAMPLE_HISTOGRAM)
 
-        hist = histogram_tools.Histogram('A11Y_INSTANTIATED_FLAG',
-                                         histograms['A11Y_INSTANTIATED_FLAG'],
-                                         strict_type_checks=False)
+        hist = parse_histograms.Histogram('A11Y_INSTANTIATED_FLAG',
+                                          histograms['A11Y_INSTANTIATED_FLAG'],
+                                          strict_type_checks=False)
         self.assertEqual(hist.expiration(), 'never')
         self.assertEqual(hist.kind(), 'flag')
         self.assertEqual(hist.record_in_processes(), ["main", "content"])
 
     def test_non_numeric_expressions(self):
         SAMPLE_HISTOGRAM = {
             "TEST_NON_NUMERIC_HISTOGRAM": {
                 "kind": "linear",
                 "description": "sample",
                 "n_buckets": "JS::gcreason::NUM_TELEMETRY_REASONS",
                 "high": "mozilla::StartupTimeline::MAX_EVENT_ID"
                 }}
 
         histograms = load_histogram(SAMPLE_HISTOGRAM)
-        hist = histogram_tools.Histogram('TEST_NON_NUMERIC_HISTOGRAM',
-                                         histograms['TEST_NON_NUMERIC_HISTOGRAM'],
-                                         strict_type_checks=False)
+        hist = parse_histograms.Histogram('TEST_NON_NUMERIC_HISTOGRAM',
+                                          histograms['TEST_NON_NUMERIC_HISTOGRAM'],
+                                          strict_type_checks=False)
 
-        # expected values come off histogram_tools.py
+        # expected values come off parse_histograms.py
         self.assertEqual(hist.n_buckets(), 101)
         self.assertEqual(hist.high(), 12)
 
     def test_current_histogram(self):
         HISTOGRAMS_PATH = path.join(TELEMETRY_ROOT_PATH, "Histograms.json")
-        all_histograms = list(histogram_tools.from_files([HISTOGRAMS_PATH],
-                                                         strict_type_checks=False))
+        all_histograms = list(parse_histograms.from_files([HISTOGRAMS_PATH],
+                                                          strict_type_checks=False))
         test_histogram = [i for i in all_histograms if i.name() == 'TELEMETRY_TEST_FLAG'][0]
 
         self.assertEqual(test_histogram.expiration(), 'never')
         self.assertEqual(test_histogram.kind(), 'flag')
         self.assertEqual(test_histogram.record_in_processes(), ["main", "content"])
         self.assertEqual(test_histogram.keyed(), False)