Bug 1419761 - Rename 'histogram_tools.py' to 'parse_histograms.py'. r=Dexter

MozReview-Commit-ID: J8wM1OZbMxd

--HG--
rename : toolkit/components/telemetry/histogram_tools.py => toolkit/components/telemetry/parse_histograms.py
extra : rebase_source : 5f81b85e097194c12d6c91057cc24057b52a337d
This commit is contained in:
Ryan Leake 2017-11-23 20:21:09 +00:00
Родитель 4fbb9a4ad1
Коммит b388f89fe4
5 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -7,7 +7,7 @@
# buckets specified by each histogram. # buckets specified by each histogram.
import sys import sys
import histogram_tools import parse_histograms
import json import json
from collections import OrderedDict from collections import OrderedDict
@ -18,7 +18,7 @@ def main(argv):
all_histograms = OrderedDict() all_histograms = OrderedDict()
for histogram in histogram_tools.from_files(filenames): for histogram in parse_histograms.from_files(filenames):
name = histogram.name() name = histogram.name()
parameters = OrderedDict() parameters = OrderedDict()
table = { table = {
@ -30,8 +30,8 @@ def main(argv):
'count': '4', 'count': '4',
} }
# Use __setitem__ because Python lambdas are so limited. # Use __setitem__ because Python lambdas are so limited.
histogram_tools.table_dispatch(histogram.kind(), table, parse_histograms.table_dispatch(histogram.kind(), table,
lambda k: parameters.__setitem__('kind', k)) lambda k: parameters.__setitem__('kind', k))
if histogram.low() == 0: if histogram.low() == 0:
parameters['min'] = 1 parameters['min'] = 1
else: else:
@ -42,7 +42,7 @@ def main(argv):
parameters['buckets'] = buckets parameters['buckets'] = buckets
parameters['max'] = buckets[-1] parameters['max'] = buckets[-1]
parameters['bucket_count'] = len(buckets) parameters['bucket_count'] = len(buckets)
except histogram_tools.DefinitionException: except parse_histograms.DefinitionException:
continue continue
all_histograms.update({name: parameters}) all_histograms.update({name: parameters})

Просмотреть файл

@ -9,7 +9,7 @@ from __future__ import print_function
from shared_telemetry_utils import StringTable, static_assert, ParserError from shared_telemetry_utils import StringTable, static_assert, ParserError
import sys import sys
import histogram_tools import parse_histograms
banner = """/* This file is auto-generated, see gen_histogram_data.py. */ banner = """/* This file is auto-generated, see gen_histogram_data.py. */
""" """
@ -193,7 +193,7 @@ def write_histogram_ranges(output, histograms):
def main(output, *filenames): def main(output, *filenames):
try: try:
histograms = list(histogram_tools.from_files(filenames)) histograms = list(parse_histograms.from_files(filenames))
except ParserError as ex: except ParserError as ex:
print("\nError processing histograms:\n" + str(ex) + "\n") print("\nError processing histograms:\n" + str(ex) + "\n")
sys.exit(1) sys.exit(1)

Просмотреть файл

@ -15,7 +15,7 @@
from __future__ import print_function from __future__ import print_function
from shared_telemetry_utils import ParserError from shared_telemetry_utils import ParserError
import histogram_tools import parse_histograms
import itertools import itertools
import sys import sys
@ -46,7 +46,7 @@ def main(output, *filenames):
# Load the histograms. # Load the histograms.
try: try:
all_histograms = list(histogram_tools.from_files(filenames)) all_histograms = list(parse_histograms.from_files(filenames))
except ParserError as ex: except ParserError as ex:
print("\nError processing histograms:\n" + str(ex) + "\n") print("\nError processing histograms:\n" + str(ex) + "\n")
sys.exit(1) sys.exit(1)
@ -55,7 +55,7 @@ def main(output, *filenames):
lambda h: h.name().startswith("USE_COUNTER2_")) lambda h: h.name().startswith("USE_COUNTER2_"))
# Print the histogram enums. # 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 # histograms are defined in a contiguous block. We therefore assume
# that there's at most one group for which use_counter_group is true. # that there's at most one group for which use_counter_group is true.
print("enum HistogramID : uint32_t {", file=output) print("enum HistogramID : uint32_t {", file=output)

Просмотреть файл

@ -40,7 +40,7 @@ BASE_DOC_URL = ("https://firefox-source-docs.mozilla.org/toolkit/components/"
HISTOGRAMS_DOC_URL = (BASE_DOC_URL + "collection/histograms.html") HISTOGRAMS_DOC_URL = (BASE_DOC_URL + "collection/histograms.html")
SCALARS_DOC_URL = (BASE_DOC_URL + "collection/scalars.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 # and also by outside consumers, such as the telemetry server. We need
# to ensure that importing things works in both contexts. Therefore, # to ensure that importing things works in both contexts. Therefore,
# unconditionally importing things that are local to the build tree, such # unconditionally importing things that are local to the build tree, such

Просмотреть файл

@ -10,7 +10,7 @@ from os import path
TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir)) TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir))
sys.path.append(TELEMETRY_ROOT_PATH) sys.path.append(TELEMETRY_ROOT_PATH)
import histogram_tools # noqa: E402 import parse_histograms # noqa: E402
def load_histogram(histograms): def load_histogram(histograms):
@ -21,7 +21,7 @@ def load_histogram(histograms):
:returns: Parsed Histogram dictionary mapping histogram names to histogram parameters :returns: Parsed Histogram dictionary mapping histogram names to histogram parameters
""" """
def hook(ps): 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) return json.loads(json.dumps(histograms), object_pairs_hook=hook)
@ -37,9 +37,9 @@ class TestParser(unittest.TestCase):
}} }}
histograms = load_histogram(SAMPLE_HISTOGRAM) histograms = load_histogram(SAMPLE_HISTOGRAM)
hist = histogram_tools.Histogram('A11Y_INSTANTIATED_FLAG', hist = parse_histograms.Histogram('A11Y_INSTANTIATED_FLAG',
histograms['A11Y_INSTANTIATED_FLAG'], histograms['A11Y_INSTANTIATED_FLAG'],
strict_type_checks=False) strict_type_checks=False)
self.assertEqual(hist.expiration(), 'never') self.assertEqual(hist.expiration(), 'never')
self.assertEqual(hist.kind(), 'flag') self.assertEqual(hist.kind(), 'flag')
self.assertEqual(hist.record_in_processes(), ["main", "content"]) self.assertEqual(hist.record_in_processes(), ["main", "content"])
@ -54,18 +54,18 @@ class TestParser(unittest.TestCase):
}} }}
histograms = load_histogram(SAMPLE_HISTOGRAM) histograms = load_histogram(SAMPLE_HISTOGRAM)
hist = histogram_tools.Histogram('TEST_NON_NUMERIC_HISTOGRAM', hist = parse_histograms.Histogram('TEST_NON_NUMERIC_HISTOGRAM',
histograms['TEST_NON_NUMERIC_HISTOGRAM'], histograms['TEST_NON_NUMERIC_HISTOGRAM'],
strict_type_checks=False) 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.n_buckets(), 101)
self.assertEqual(hist.high(), 12) self.assertEqual(hist.high(), 12)
def test_current_histogram(self): def test_current_histogram(self):
HISTOGRAMS_PATH = path.join(TELEMETRY_ROOT_PATH, "Histograms.json") HISTOGRAMS_PATH = path.join(TELEMETRY_ROOT_PATH, "Histograms.json")
all_histograms = list(histogram_tools.from_files([HISTOGRAMS_PATH], all_histograms = list(parse_histograms.from_files([HISTOGRAMS_PATH],
strict_type_checks=False)) strict_type_checks=False))
test_histogram = [i for i in all_histograms if i.name() == 'TELEMETRY_TEST_FLAG'][0] 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.expiration(), 'never')