OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 5 import collections |
6 import itertools | 6 import itertools |
7 import json | 7 import json |
8 | 8 |
9 from telemetry.internal.results import output_formatter | 9 from telemetry.internal.results import output_formatter |
10 from telemetry.value import trace | 10 from telemetry.value import trace |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 'format_version': '0.1', | 61 'format_version': '0.1', |
62 'next_version': '0.2', | 62 'next_version': '0.2', |
63 # TODO(sullivan): benchmark_name, benchmark_description, and | 63 # TODO(sullivan): benchmark_name, benchmark_description, and |
64 # trace_rerun_options should be removed when incrementing format_version | 64 # trace_rerun_options should be removed when incrementing format_version |
65 # to 0.1. | 65 # to 0.1. |
66 'benchmark_name': benchmark_metadata.name, | 66 'benchmark_name': benchmark_metadata.name, |
67 'benchmark_description': benchmark_metadata.description, | 67 'benchmark_description': benchmark_metadata.description, |
68 'trace_rerun_options': benchmark_metadata.rerun_options, | 68 'trace_rerun_options': benchmark_metadata.rerun_options, |
69 'benchmark_metadata': benchmark_metadata.AsDict(), | 69 'benchmark_metadata': benchmark_metadata.AsDict(), |
70 'charts': charts, | 70 'charts': charts, |
| 71 # Need to add this in for compatibility with disabled chartjson results. |
| 72 'enabled': True |
71 } | 73 } |
72 | 74 |
73 return result_dict | 75 return result_dict |
74 | 76 |
| 77 |
| 78 def DisabledResultsDict(benchmark_name): |
| 79 """Produces a dict for serialization to Chart JSON when a benchmark is |
| 80 disabled. |
| 81 |
| 82 Args: |
| 83 benchmark_name: name of the disabled benchmark |
| 84 |
| 85 Returns: |
| 86 A Chart JSON dict corresponding to a disabled benchmark. |
| 87 """ |
| 88 result_dict = { |
| 89 'benchmark_name': benchmark_name, |
| 90 'enabled': False |
| 91 } |
| 92 |
| 93 return result_dict |
| 94 |
| 95 |
75 # TODO(eakuefner): Transition this to translate Telemetry JSON. | 96 # TODO(eakuefner): Transition this to translate Telemetry JSON. |
76 class ChartJsonOutputFormatter(output_formatter.OutputFormatter): | 97 class ChartJsonOutputFormatter(output_formatter.OutputFormatter): |
77 def __init__(self, output_stream, benchmark_metadata): | 98 def __init__(self, output_stream, benchmark_metadata): |
78 super(ChartJsonOutputFormatter, self).__init__(output_stream) | 99 super(ChartJsonOutputFormatter, self).__init__(output_stream) |
79 self._benchmark_metadata = benchmark_metadata | 100 self._benchmark_metadata = benchmark_metadata |
80 | 101 |
| 102 def FormatDisabled(self): |
| 103 self._Dump(DisabledResultsDict(self._benchmark_metadata.name)) |
| 104 |
81 def Format(self, page_test_results): | 105 def Format(self, page_test_results): |
82 json.dump(ResultsAsChartDict( | 106 self._Dump(ResultsAsChartDict( |
83 self._benchmark_metadata, | 107 self._benchmark_metadata, |
84 page_test_results.all_page_specific_values, | 108 page_test_results.all_page_specific_values, |
85 page_test_results.all_summary_values), | 109 page_test_results.all_summary_values)) |
86 self.output_stream, indent=2) | 110 |
| 111 def _Dump(self, results): |
| 112 json.dump(results, self.output_stream, indent=2, |
| 113 separators=(',', ': ')) |
87 self.output_stream.write('\n') | 114 self.output_stream.write('\n') |
OLD | NEW |