1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/telemetry/gen-histogram-bucket-ranges.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +#!/usr/bin/env python 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 +# Write out detailed histogram information, including the ranges of the 1.10 +# buckets specified by each histogram. 1.11 + 1.12 +import sys 1.13 +import re 1.14 +import histogram_tools 1.15 +import json 1.16 + 1.17 +from collections import OrderedDict 1.18 + 1.19 +# Keep this in sync with TelemetryPing. 1.20 +startup_histogram_re = re.compile("SQLITE|HTTP|SPDY|CACHE|DNS") 1.21 + 1.22 +def main(argv): 1.23 + filename = argv[0] 1.24 + all_histograms = OrderedDict() 1.25 + 1.26 + for histogram in histogram_tools.from_file(filename): 1.27 + name = histogram.name() 1.28 + parameters = OrderedDict() 1.29 + table = { 1.30 + 'boolean': '2', 1.31 + 'flag': '3', 1.32 + 'enumerated': '1', 1.33 + 'linear': '1', 1.34 + 'exponential': '0' 1.35 + } 1.36 + # Use __setitem__ because Python lambdas are so limited. 1.37 + histogram_tools.table_dispatch(histogram.kind(), table, 1.38 + lambda k: parameters.__setitem__('kind', k)) 1.39 + if histogram.low() == 0: 1.40 + parameters['min'] = 1 1.41 + else: 1.42 + parameters['min'] = histogram.low() 1.43 + 1.44 + try: 1.45 + buckets = histogram.ranges() 1.46 + parameters['buckets'] = buckets 1.47 + parameters['max'] = buckets[-1] 1.48 + parameters['bucket_count'] = len(buckets) 1.49 + except histogram_tools.DefinitionException: 1.50 + continue 1.51 + 1.52 + all_histograms.update({ name: parameters }); 1.53 + 1.54 + if startup_histogram_re.search(name) is not None: 1.55 + all_histograms.update({ "STARTUP_" + name: parameters }) 1.56 + 1.57 + print json.dumps({ 'histograms': all_histograms}) 1.58 + 1.59 +main(sys.argv[1:])