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 catapult_base import cloud_storage | 11 from catapult_base import cloud_storage |
12 from telemetry.core import util | 12 from telemetry.core import util |
13 from telemetry.internal.results import chart_json_output_formatter | 13 from telemetry.internal.results import chart_json_output_formatter |
14 from telemetry.internal.results import output_formatter | 14 from telemetry.internal.results import output_formatter |
15 from telemetry import value as value_module | 15 from telemetry import value as value_module |
16 | 16 |
17 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'util') | 17 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'util') |
18 import lastchange # pylint: disable=F0401 | |
19 | 18 |
20 | 19 |
21 _TEMPLATE_HTML_PATH = os.path.join( | 20 _TEMPLATE_HTML_PATH = os.path.join( |
22 util.GetTelemetryDir(), 'support', 'html_output', 'results-template.html') | 21 util.GetTelemetryDir(), 'support', 'html_output', 'results-template.html') |
23 _JS_PLUGINS = [os.path.join('flot', 'jquery.flot.min.js'), | 22 _JS_PLUGINS = [os.path.join('flot', 'jquery.flot.min.js'), |
24 os.path.join('WebKit', 'PerformanceTests', 'resources', | 23 os.path.join('WebKit', 'PerformanceTests', 'resources', |
25 'jquery.tablesorter.min.js'), | 24 'jquery.tablesorter.min.js'), |
26 os.path.join('WebKit', 'PerformanceTests', 'resources', | 25 os.path.join('WebKit', 'PerformanceTests', 'resources', |
27 'statistics.js')] | 26 'statistics.js')] |
28 _UNIT_JSON = ('tools', 'perf', 'unit-info.json') | 27 _UNIT_JSON = ('tools', 'perf', 'unit-info.json') |
29 | 28 |
30 | 29 |
| 30 def _DatetimeInEs5CompatibleFormat(dt): |
| 31 return dt.strftime('%Y-%m-%dT%H:%M:%S.%f') |
| 32 |
| 33 |
| 34 def _ShortDatetimeInEs5CompatibleFormat(dt): |
| 35 return dt.strftime('%Y-%m-%d %H:%M:%S') |
| 36 |
| 37 |
31 # TODO(eakuefner): rewrite template to use Telemetry JSON directly | 38 # TODO(eakuefner): rewrite template to use Telemetry JSON directly |
32 class HtmlOutputFormatter(output_formatter.OutputFormatter): | 39 class HtmlOutputFormatter(output_formatter.OutputFormatter): |
33 def __init__(self, output_stream, metadata, reset_results, upload_results, | 40 def __init__(self, output_stream, metadata, reset_results, upload_results, |
34 browser_type, results_label=None): | 41 browser_type, results_label=None): |
35 super(HtmlOutputFormatter, self).__init__(output_stream) | 42 super(HtmlOutputFormatter, self).__init__(output_stream) |
36 self._metadata = metadata | 43 self._metadata = metadata |
37 self._reset_results = reset_results | 44 self._reset_results = reset_results |
38 self._upload_results = upload_results | 45 self._upload_results = upload_results |
| 46 self._build_time = self._GetBuildTime() |
39 self._existing_results = self._ReadExistingResults(output_stream) | 47 self._existing_results = self._ReadExistingResults(output_stream) |
| 48 if results_label: |
| 49 self._results_label = results_label |
| 50 else: |
| 51 self._results_label = '%s (%s)' % ( |
| 52 metadata.name, _ShortDatetimeInEs5CompatibleFormat(self._build_time)) |
40 self._result = { | 53 self._result = { |
41 'buildTime': self._GetBuildTime(), | 54 'buildTime': _DatetimeInEs5CompatibleFormat(self._build_time), |
42 'revision': self._GetRevision(), | 55 'label': self._results_label, |
43 'label': results_label, | |
44 'platform': browser_type, | 56 'platform': browser_type, |
45 'tests': {} | 57 'tests': {} |
46 } | 58 } |
47 | 59 |
48 def _GetBuildTime(self): | 60 def _GetBuildTime(self): |
49 def _DatetimeInEs5CompatibleFormat(dt): | 61 return datetime.datetime.utcnow() |
50 return dt.strftime('%Y-%m-%dT%H:%M:%S.%f') | |
51 return _DatetimeInEs5CompatibleFormat(datetime.datetime.utcnow()) | |
52 | |
53 def _GetRevision(self): | |
54 return lastchange.FetchVersionInfo(None).revision | |
55 | 62 |
56 def _GetHtmlTemplate(self): | 63 def _GetHtmlTemplate(self): |
57 with open(_TEMPLATE_HTML_PATH) as f: | 64 with open(_TEMPLATE_HTML_PATH) as f: |
58 return f.read() | 65 return f.read() |
59 | 66 |
60 def _GetPlugins(self): | 67 def _GetPlugins(self): |
61 plugins = '' | 68 plugins = '' |
62 for p in _JS_PLUGINS: | 69 for p in _JS_PLUGINS: |
63 with open(os.path.join(util.GetTelemetryThirdPartyDir(), p)) as f: | 70 with open(os.path.join(util.GetTelemetryThirdPartyDir(), p)) as f: |
64 plugins += f.read() | 71 plugins += f.read() |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 print | 168 print |
162 print ('View online at ' | 169 print ('View online at ' |
163 'http://storage.googleapis.com/chromium-telemetry/%s' | 170 'http://storage.googleapis.com/chromium-telemetry/%s' |
164 % file_name) | 171 % file_name) |
165 except cloud_storage.PermissionError as e: | 172 except cloud_storage.PermissionError as e: |
166 logging.error('Cannot upload profiling files to cloud storage due to ' | 173 logging.error('Cannot upload profiling files to cloud storage due to ' |
167 ' permission error: %s' % e.message) | 174 ' permission error: %s' % e.message) |
168 print | 175 print |
169 print 'View result at file://%s' % os.path.abspath( | 176 print 'View result at file://%s' % os.path.abspath( |
170 self._output_stream.name) | 177 self._output_stream.name) |
OLD | NEW |