toolkit/components/telemetry/gen-histogram-bucket-ranges.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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:])

mercurial