michael@0: #!/usr/bin/env python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # Write out detailed histogram information, including the ranges of the michael@0: # buckets specified by each histogram. michael@0: michael@0: import sys michael@0: import re michael@0: import histogram_tools michael@0: import json michael@0: michael@0: from collections import OrderedDict michael@0: michael@0: # Keep this in sync with TelemetryPing. michael@0: startup_histogram_re = re.compile("SQLITE|HTTP|SPDY|CACHE|DNS") michael@0: michael@0: def main(argv): michael@0: filename = argv[0] michael@0: all_histograms = OrderedDict() michael@0: michael@0: for histogram in histogram_tools.from_file(filename): michael@0: name = histogram.name() michael@0: parameters = OrderedDict() michael@0: table = { michael@0: 'boolean': '2', michael@0: 'flag': '3', michael@0: 'enumerated': '1', michael@0: 'linear': '1', michael@0: 'exponential': '0' michael@0: } michael@0: # Use __setitem__ because Python lambdas are so limited. michael@0: histogram_tools.table_dispatch(histogram.kind(), table, michael@0: lambda k: parameters.__setitem__('kind', k)) michael@0: if histogram.low() == 0: michael@0: parameters['min'] = 1 michael@0: else: michael@0: parameters['min'] = histogram.low() michael@0: michael@0: try: michael@0: buckets = histogram.ranges() michael@0: parameters['buckets'] = buckets michael@0: parameters['max'] = buckets[-1] michael@0: parameters['bucket_count'] = len(buckets) michael@0: except histogram_tools.DefinitionException: michael@0: continue michael@0: michael@0: all_histograms.update({ name: parameters }); michael@0: michael@0: if startup_histogram_re.search(name) is not None: michael@0: all_histograms.update({ "STARTUP_" + name: parameters }) michael@0: michael@0: print json.dumps({ 'histograms': all_histograms}) michael@0: michael@0: main(sys.argv[1:])