| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # Disable the line-too-long warning. |
| 6 # pylint: disable=C0301 |
| 7 """This module implements the Chromium Performance Dashboard JSON v1.0 data |
| 8 format. |
| 9 |
| 10 See http://www.chromium.org/developers/speed-infra/performance-dashboard/sending
-data-to-the-performance-dashboard. |
| 11 """ |
| 12 |
| 13 import json |
| 14 from collections import defaultdict |
| 15 |
| 16 class ChartDataRecorder(object): |
| 17 """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 performance dashboard. |
| 20 """ |
| 21 |
| 22 def __init__(self): |
| 23 self.charts = defaultdict(list) |
| 24 |
| 25 def record_scalar(self, chart_name, value_name, units, value): |
| 26 """Records a single measurement value of a scalar type.""" |
| 27 self.charts[chart_name].append({ |
| 28 'type': 'scalar', |
| 29 'name': value_name, |
| 30 'units': units, |
| 31 'value': value}) |
| 32 |
| 33 def get_json(self): |
| 34 """Returns the JSON string representing the recorded chart data.""" |
| 35 return json.dumps(self.charts) |
| OLD | NEW |