OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Disable the line-too-long warning. | 5 # Disable the line-too-long warning. |
6 # pylint: disable=C0301 | 6 # pylint: disable=C0301 |
7 """This module implements the Chromium Performance Dashboard JSON v1.0 data | 7 """This module implements the Chromium Performance Dashboard JSON v1.0 data |
8 format. | 8 format. |
9 | 9 |
10 See http://www.chromium.org/developers/speed-infra/performance-dashboard/sending
-data-to-the-performance-dashboard. | 10 See http://www.chromium.org/developers/speed-infra/performance-dashboard/sending
-data-to-the-performance-dashboard. |
11 """ | 11 """ |
12 | 12 |
13 import json | 13 import json |
14 from collections import defaultdict | 14 from collections import defaultdict |
15 | 15 |
| 16 |
16 class ChartDataRecorder(object): | 17 class ChartDataRecorder(object): |
17 """Allows one to record measurement values one by one and then generate the | 18 """Allows one to record measurement values one by one and then generate the |
18 JSON string that represents them in the 'chart_data' format expected by the | 19 JSON string that represents them in the 'chart_data' format expected by the |
19 performance dashboard. | 20 performance dashboard. |
20 """ | 21 """ |
21 | 22 |
22 def __init__(self): | 23 def __init__(self, benchmark_name): |
23 self.charts = defaultdict(list) | 24 self.charts = defaultdict(list) |
| 25 self.benchmark_name = benchmark_name |
24 | 26 |
25 def record_scalar(self, chart_name, value_name, units, value): | 27 def record_scalar(self, chart_name, value_name, units, value): |
26 """Records a single measurement value of a scalar type.""" | 28 """Records a single measurement value of a scalar type.""" |
27 self.charts[chart_name].append({ | 29 self.charts[chart_name].append({ |
28 'type': 'scalar', | 30 'type': 'scalar', |
29 'name': value_name, | 31 'name': value_name, |
30 'units': units, | 32 'units': units, |
31 'value': value}) | 33 'value': value}) |
32 | 34 |
33 def get_json(self): | 35 def get_json(self): |
34 """Returns the JSON string representing the recorded chart data.""" | 36 """Returns the JSON string representing the recorded chart data, wrapping |
35 return json.dumps(self.charts) | 37 it with the required meta data.""" |
| 38 chart_data = { |
| 39 'format_version': '1.0', |
| 40 'benchmark_name': self.benchmark_name, |
| 41 'charts': self.charts |
| 42 } |
| 43 return json.dumps(chart_data) |
OLD | NEW |