Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 5 | |
michael@0 | 6 | # Write out detailed histogram information, including the ranges of the |
michael@0 | 7 | # buckets specified by each histogram. |
michael@0 | 8 | |
michael@0 | 9 | import sys |
michael@0 | 10 | import re |
michael@0 | 11 | import histogram_tools |
michael@0 | 12 | import json |
michael@0 | 13 | |
michael@0 | 14 | from collections import OrderedDict |
michael@0 | 15 | |
michael@0 | 16 | # Keep this in sync with TelemetryPing. |
michael@0 | 17 | startup_histogram_re = re.compile("SQLITE|HTTP|SPDY|CACHE|DNS") |
michael@0 | 18 | |
michael@0 | 19 | def main(argv): |
michael@0 | 20 | filename = argv[0] |
michael@0 | 21 | all_histograms = OrderedDict() |
michael@0 | 22 | |
michael@0 | 23 | for histogram in histogram_tools.from_file(filename): |
michael@0 | 24 | name = histogram.name() |
michael@0 | 25 | parameters = OrderedDict() |
michael@0 | 26 | table = { |
michael@0 | 27 | 'boolean': '2', |
michael@0 | 28 | 'flag': '3', |
michael@0 | 29 | 'enumerated': '1', |
michael@0 | 30 | 'linear': '1', |
michael@0 | 31 | 'exponential': '0' |
michael@0 | 32 | } |
michael@0 | 33 | # Use __setitem__ because Python lambdas are so limited. |
michael@0 | 34 | histogram_tools.table_dispatch(histogram.kind(), table, |
michael@0 | 35 | lambda k: parameters.__setitem__('kind', k)) |
michael@0 | 36 | if histogram.low() == 0: |
michael@0 | 37 | parameters['min'] = 1 |
michael@0 | 38 | else: |
michael@0 | 39 | parameters['min'] = histogram.low() |
michael@0 | 40 | |
michael@0 | 41 | try: |
michael@0 | 42 | buckets = histogram.ranges() |
michael@0 | 43 | parameters['buckets'] = buckets |
michael@0 | 44 | parameters['max'] = buckets[-1] |
michael@0 | 45 | parameters['bucket_count'] = len(buckets) |
michael@0 | 46 | except histogram_tools.DefinitionException: |
michael@0 | 47 | continue |
michael@0 | 48 | |
michael@0 | 49 | all_histograms.update({ name: parameters }); |
michael@0 | 50 | |
michael@0 | 51 | if startup_histogram_re.search(name) is not None: |
michael@0 | 52 | all_histograms.update({ "STARTUP_" + name: parameters }) |
michael@0 | 53 | |
michael@0 | 54 | print json.dumps({ 'histograms': all_histograms}) |
michael@0 | 55 | |
michael@0 | 56 | main(sys.argv[1:]) |