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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:016ff9cc4ec5
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/.
5
6 # Write out detailed histogram information, including the ranges of the
7 # buckets specified by each histogram.
8
9 import sys
10 import re
11 import histogram_tools
12 import json
13
14 from collections import OrderedDict
15
16 # Keep this in sync with TelemetryPing.
17 startup_histogram_re = re.compile("SQLITE|HTTP|SPDY|CACHE|DNS")
18
19 def main(argv):
20 filename = argv[0]
21 all_histograms = OrderedDict()
22
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()
40
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
48
49 all_histograms.update({ name: parameters });
50
51 if startup_histogram_re.search(name) is not None:
52 all_histograms.update({ "STARTUP_" + name: parameters })
53
54 print json.dumps({ 'histograms': all_histograms})
55
56 main(sys.argv[1:])

mercurial