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