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 datetime | 5 import datetime |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 | 10 |
11 from py_utils import cloud_storage # pylint: disable=import-error | 11 from py_utils import cloud_storage # pylint: disable=import-error |
12 | 12 |
13 from telemetry.core import util | 13 from telemetry.core import util |
14 from telemetry.internal.results import chart_json_output_formatter | 14 from telemetry.internal.results import chart_json_output_formatter |
| 15 from telemetry.internal.results import html2_output_formatter |
15 from telemetry.internal.results import output_formatter | 16 from telemetry.internal.results import output_formatter |
16 from telemetry import value as value_module | 17 from telemetry import value as value_module |
17 from telemetry.value import list_of_scalar_values | 18 from telemetry.value import list_of_scalar_values |
18 | 19 |
19 | 20 |
20 _TEMPLATE_HTML_PATH = os.path.join( | 21 _TEMPLATE_HTML_PATH = os.path.join( |
21 util.GetTelemetryDir(), 'support', 'html_output', 'results-template.html') | 22 util.GetTelemetryDir(), 'support', 'html_output', 'results-template.html') |
22 _JS_PLUGINS = [os.path.join('flot', 'jquery.flot.min.js'), | 23 _JS_PLUGINS = [os.path.join('flot', 'jquery.flot.min.js'), |
23 os.path.join('WebKit', 'PerformanceTests', 'resources', | 24 os.path.join('WebKit', 'PerformanceTests', 'resources', |
24 'jquery.tablesorter.min.js'), | 25 'jquery.tablesorter.min.js'), |
(...skipping 13 matching lines...) Expand all Loading... |
38 | 39 |
39 # TODO(eakuefner): rewrite template to use Telemetry JSON directly | 40 # TODO(eakuefner): rewrite template to use Telemetry JSON directly |
40 class HtmlOutputFormatter(output_formatter.OutputFormatter): | 41 class HtmlOutputFormatter(output_formatter.OutputFormatter): |
41 def __init__(self, output_stream, metadata, reset_results, upload_results, | 42 def __init__(self, output_stream, metadata, reset_results, upload_results, |
42 browser_type, results_label=None): | 43 browser_type, results_label=None): |
43 super(HtmlOutputFormatter, self).__init__(output_stream) | 44 super(HtmlOutputFormatter, self).__init__(output_stream) |
44 self._metadata = metadata | 45 self._metadata = metadata |
45 self._reset_results = reset_results | 46 self._reset_results = reset_results |
46 self._upload_results = upload_results | 47 self._upload_results = upload_results |
47 self._build_time = self._GetBuildTime() | 48 self._build_time = self._GetBuildTime() |
48 self._existing_results = self._ReadExistingResults(output_stream) | 49 self._combined_results = [] |
49 if results_label: | 50 if results_label: |
50 self._results_label = results_label | 51 self._results_label = results_label |
51 else: | 52 else: |
52 self._results_label = '%s (%s)' % ( | 53 self._results_label = '%s (%s)' % ( |
53 metadata.name, _ShortDatetimeInEs5CompatibleFormat(self._build_time)) | 54 metadata.name, _ShortDatetimeInEs5CompatibleFormat(self._build_time)) |
54 self._result = { | 55 self._result = { |
55 'buildTime': _DatetimeInEs5CompatibleFormat(self._build_time), | 56 'buildTime': _DatetimeInEs5CompatibleFormat(self._build_time), |
56 'label': self._results_label, | 57 'label': self._results_label, |
57 'platform': browser_type, | 58 'platform': browser_type, |
58 'tests': {} | 59 'tests': {} |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 value.units, result_type, std) | 146 value.units, result_type, std) |
146 | 147 |
147 @property | 148 @property |
148 def _test_name(self): | 149 def _test_name(self): |
149 return self._metadata.name | 150 return self._metadata.name |
150 | 151 |
151 def GetResults(self): | 152 def GetResults(self): |
152 return self._result | 153 return self._result |
153 | 154 |
154 def GetCombinedResults(self): | 155 def GetCombinedResults(self): |
155 all_results = list(self._existing_results) | 156 return self._combined_results |
156 all_results.append(self.GetResults()) | |
157 return all_results | |
158 | 157 |
159 def Format(self, page_test_results): | 158 def Format(self, page_test_results): |
| 159 if page_test_results.value_set: |
| 160 html2_formatter = html2_output_formatter.Html2OutputFormatter( |
| 161 self._output_stream, self._reset_results, self._upload_results) |
| 162 html2_formatter.Format(page_test_results) |
| 163 return |
| 164 |
160 chart_json_dict = chart_json_output_formatter.ResultsAsChartDict( | 165 chart_json_dict = chart_json_output_formatter.ResultsAsChartDict( |
161 self._metadata, page_test_results.all_page_specific_values, | 166 self._metadata, page_test_results.all_page_specific_values, |
162 page_test_results.all_summary_values) | 167 page_test_results.all_summary_values) |
163 | 168 |
164 self._TranslateChartJson(chart_json_dict) | 169 self._TranslateChartJson(chart_json_dict) |
165 self._PrintPerfResult('telemetry_page_measurement_results', 'num_failed', | 170 self._PrintPerfResult('telemetry_page_measurement_results', 'num_failed', |
166 [len(page_test_results.failures)], 'count', | 171 [len(page_test_results.failures)], 'count', |
167 'unimportant') | 172 'unimportant') |
168 | 173 |
| 174 self._combined_results = self._ReadExistingResults(self._output_stream) |
| 175 self._combined_results.append(self._result) |
| 176 |
169 html = self._GetHtmlTemplate() | 177 html = self._GetHtmlTemplate() |
170 html = html.replace('%json_results%', json.dumps(self.GetCombinedResults())) | 178 html = html.replace('%json_results%', json.dumps(self.GetCombinedResults())) |
171 html = html.replace('%json_units%', self._GetUnitJson()) | 179 html = html.replace('%json_units%', self._GetUnitJson()) |
172 html = html.replace('%plugins%', self._GetPlugins()) | 180 html = html.replace('%plugins%', self._GetPlugins()) |
173 self._SaveResults(html) | 181 self._SaveResults(html) |
174 | 182 |
175 if self._upload_results: | 183 if self._upload_results: |
176 file_path = os.path.abspath(self._output_stream.name) | 184 file_path = os.path.abspath(self._output_stream.name) |
177 file_name = 'html-results/results-%s' % datetime.datetime.now().strftime( | 185 file_name = 'html-results/results-%s' % datetime.datetime.now().strftime( |
178 '%Y-%m-%d_%H-%M-%S') | 186 '%Y-%m-%d_%H-%M-%S') |
179 try: | 187 try: |
180 cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name, file_path) | 188 cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name, file_path) |
181 print | 189 print |
182 print ('View online at ' | 190 print ('View online at ' |
183 'http://storage.googleapis.com/chromium-telemetry/%s' | 191 'http://storage.googleapis.com/chromium-telemetry/%s' |
184 % file_name) | 192 % file_name) |
185 except cloud_storage.PermissionError as e: | 193 except cloud_storage.PermissionError as e: |
186 logging.error('Cannot upload profiling files to cloud storage due to ' | 194 logging.error('Cannot upload profiling files to cloud storage due to ' |
187 ' permission error: %s' % e.message) | 195 ' permission error: %s' % e.message) |
188 print | 196 print |
189 print 'View result at file://%s' % os.path.abspath( | 197 print 'View result at file://%s' % os.path.abspath( |
190 self._output_stream.name) | 198 self._output_stream.name) |
OLD | NEW |