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 codecs |
5 import optparse | 6 import optparse |
6 import os | 7 import os |
7 import sys | 8 import sys |
8 | 9 |
9 from catapult_base import cloud_storage # pylint: disable=import-error | 10 from catapult_base import cloud_storage # pylint: disable=import-error |
10 | 11 |
11 from telemetry.core import util | 12 from telemetry.core import util |
12 from telemetry.internal.results import buildbot_output_formatter | 13 from telemetry.internal.results import buildbot_output_formatter |
13 from telemetry.internal.results import chart_json_output_formatter | 14 from telemetry.internal.results import chart_json_output_formatter |
14 from telemetry.internal.results import csv_pivot_table_output_formatter | 15 from telemetry.internal.results import csv_pivot_table_output_formatter |
15 from telemetry.internal.results import gtest_progress_reporter | 16 from telemetry.internal.results import gtest_progress_reporter |
16 from telemetry.internal.results import html_output_formatter | 17 from telemetry.internal.results import html_output_formatter |
| 18 from telemetry.internal.results import html2_output_formatter |
17 from telemetry.internal.results import json_output_formatter | 19 from telemetry.internal.results import json_output_formatter |
18 from telemetry.internal.results import page_test_results | 20 from telemetry.internal.results import page_test_results |
19 from telemetry.internal.results import progress_reporter | 21 from telemetry.internal.results import progress_reporter |
20 | 22 |
21 # Allowed output formats. The default is the first item in the list. | 23 # Allowed output formats. The default is the first item in the list. |
22 _OUTPUT_FORMAT_CHOICES = ('html', 'buildbot', 'gtest', 'json', | 24 _OUTPUT_FORMAT_CHOICES = ('html', 'html2', 'buildbot', 'gtest', 'json', |
23 'chartjson', 'csv-pivot-table', 'none') | 25 'chartjson', 'csv-pivot-table', 'none') |
24 | 26 |
25 | 27 |
26 # Filenames to use for given output formats. | 28 # Filenames to use for given output formats. |
27 _OUTPUT_FILENAME_LOOKUP = { | 29 _OUTPUT_FILENAME_LOOKUP = { |
28 'html': 'results.html', | 30 'html': 'results.html', |
| 31 'html2': 'results2.html', |
29 'json': 'results.json', | 32 'json': 'results.json', |
30 'chartjson': 'results-chart.json', | 33 'chartjson': 'results-chart.json', |
31 'csv-pivot-table': 'results-pivot-table.csv' | 34 'csv-pivot-table': 'results-pivot-table.csv' |
32 } | 35 } |
33 | 36 |
34 | 37 |
35 def AddResultsOptions(parser): | 38 def AddResultsOptions(parser): |
36 group = optparse.OptionGroup(parser, 'Results options') | 39 group = optparse.OptionGroup(parser, 'Results options') |
37 group.add_option('--output-format', action='append', dest='output_formats', | 40 group.add_option('--output-format', action='append', dest='output_formats', |
38 choices=_OUTPUT_FORMAT_CHOICES, default=[], | 41 choices=_OUTPUT_FORMAT_CHOICES, default=[], |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 'Cannot set stream for \'gtest\' or \'none\' output formats.') | 91 'Cannot set stream for \'gtest\' or \'none\' output formats.') |
89 | 92 |
90 if output_format == 'buildbot': | 93 if output_format == 'buildbot': |
91 return sys.stdout | 94 return sys.stdout |
92 | 95 |
93 assert output_format in _OUTPUT_FILENAME_LOOKUP, ( | 96 assert output_format in _OUTPUT_FILENAME_LOOKUP, ( |
94 'No known filename for the \'%s\' output format' % output_format) | 97 'No known filename for the \'%s\' output format' % output_format) |
95 output_file = os.path.join(output_dir, _OUTPUT_FILENAME_LOOKUP[output_format]) | 98 output_file = os.path.join(output_dir, _OUTPUT_FILENAME_LOOKUP[output_format]) |
96 | 99 |
97 # TODO(eakuefner): Factor this hack out after we rewrite HTMLOutputFormatter. | 100 # TODO(eakuefner): Factor this hack out after we rewrite HTMLOutputFormatter. |
98 if output_format == 'html': | 101 if output_format == 'html' or output_format == 'html2': |
99 open(output_file, 'a').close() # Create file if it doesn't exist. | 102 open(output_file, 'a').close() # Create file if it doesn't exist. |
100 return open(output_file, 'r+') | 103 return codecs.open(output_file, 'r+', 'utf-8') |
101 else: | 104 else: |
102 return open(output_file, 'w+') | 105 return codecs.open(output_file, 'w+', 'utf-8') |
103 | 106 |
104 | 107 |
105 def _GetProgressReporter(output_skipped_tests_summary, suppress_gtest_report): | 108 def _GetProgressReporter(output_skipped_tests_summary, suppress_gtest_report): |
106 if suppress_gtest_report: | 109 if suppress_gtest_report: |
107 return progress_reporter.ProgressReporter() | 110 return progress_reporter.ProgressReporter() |
108 | 111 |
109 return gtest_progress_reporter.GTestProgressReporter( | 112 return gtest_progress_reporter.GTestProgressReporter( |
110 sys.stdout, output_skipped_tests_summary=output_skipped_tests_summary) | 113 sys.stdout, output_skipped_tests_summary=output_skipped_tests_summary) |
111 | 114 |
112 | 115 |
(...skipping 26 matching lines...) Expand all Loading... |
139 # file. Another option for this is to output the results directly | 142 # file. Another option for this is to output the results directly |
140 # in gtest-style results (via some sort of progress reporter), | 143 # in gtest-style results (via some sort of progress reporter), |
141 # as we plan to enable gtest-style output for all output formatters. | 144 # as we plan to enable gtest-style output for all output formatters. |
142 output_formatters.append( | 145 output_formatters.append( |
143 buildbot_output_formatter.BuildbotOutputFormatter( | 146 buildbot_output_formatter.BuildbotOutputFormatter( |
144 sys.stdout, trace_tag=options.output_trace_tag)) | 147 sys.stdout, trace_tag=options.output_trace_tag)) |
145 output_formatters.append(html_output_formatter.HtmlOutputFormatter( | 148 output_formatters.append(html_output_formatter.HtmlOutputFormatter( |
146 output_stream, benchmark_metadata, options.reset_results, | 149 output_stream, benchmark_metadata, options.reset_results, |
147 options.upload_results, options.browser_type, | 150 options.upload_results, options.browser_type, |
148 options.results_label)) | 151 options.results_label)) |
| 152 elif output_format == 'html2': |
| 153 output_formatters.append(html2_output_formatter.Html2OutputFormatter( |
| 154 output_stream, options.reset_results, options.upload_results)) |
149 elif output_format == 'json': | 155 elif output_format == 'json': |
150 output_formatters.append(json_output_formatter.JsonOutputFormatter( | 156 output_formatters.append(json_output_formatter.JsonOutputFormatter( |
151 output_stream, benchmark_metadata)) | 157 output_stream, benchmark_metadata)) |
152 elif output_format == 'chartjson': | 158 elif output_format == 'chartjson': |
153 output_formatters.append( | 159 output_formatters.append( |
154 chart_json_output_formatter.ChartJsonOutputFormatter( | 160 chart_json_output_formatter.ChartJsonOutputFormatter( |
155 output_stream, benchmark_metadata)) | 161 output_stream, benchmark_metadata)) |
156 else: | 162 else: |
157 # Should never be reached. The parser enforces the choices. | 163 # Should never be reached. The parser enforces the choices. |
158 raise Exception('Invalid --output-format "%s". Valid choices are: %s' | 164 raise Exception('Invalid --output-format "%s". Valid choices are: %s' |
159 % (output_format, ', '.join(_OUTPUT_FORMAT_CHOICES))) | 165 % (output_format, ', '.join(_OUTPUT_FORMAT_CHOICES))) |
160 | 166 |
161 # TODO(chrishenry): This is here to not change the output of | 167 # TODO(chrishenry): This is here to not change the output of |
162 # gtest. Let's try enabling skipped tests summary for gtest test | 168 # gtest. Let's try enabling skipped tests summary for gtest test |
163 # results too (in a separate patch), and see if we break anything. | 169 # results too (in a separate patch), and see if we break anything. |
164 output_skipped_tests_summary = 'gtest' in options.output_formats | 170 output_skipped_tests_summary = 'gtest' in options.output_formats |
165 | 171 |
166 reporter = _GetProgressReporter(output_skipped_tests_summary, | 172 reporter = _GetProgressReporter(output_skipped_tests_summary, |
167 options.suppress_gtest_report) | 173 options.suppress_gtest_report) |
168 return page_test_results.PageTestResults( | 174 return page_test_results.PageTestResults( |
169 output_formatters=output_formatters, progress_reporter=reporter, | 175 output_formatters=output_formatters, progress_reporter=reporter, |
170 output_dir=options.output_dir, | 176 output_dir=options.output_dir, |
171 value_can_be_added_predicate=value_can_be_added_predicate) | 177 value_can_be_added_predicate=value_can_be_added_predicate) |
OLD | NEW |