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
3 # found in the LICENSE file.
5 from telemetry import perf_tests_helper
6 from telemetry import value as value_module
7 from telemetry.results import output_formatter
8 from telemetry.value import summary as summary_module
11 class BuildbotOutputFormatter(output_formatter.OutputFormatter):
12 def __init__(self, output_stream, trace_tag=''):
13 super(BuildbotOutputFormatter, self).__init__(output_stream)
14 self._trace_tag = trace_tag
16 def _PrintPerfResult(self, measurement, trace, v, units,
17 result_type='default'):
18 output = perf_tests_helper.PrintPerfResult(
19 measurement, trace, v, units, result_type, print_to_stdout=False)
20 self.output_stream.write(output + '\n')
21 self.output_stream.flush()
23 def Format(self, page_test_results):
24 """Print summary data in a format expected by buildbot for perf dashboards.
26 If any failed pages exist, only output individual page results, and do
27 not output any average data.
29 had_failures = len(page_test_results.failures) > 0
31 # Print out the list of unique pages.
32 perf_tests_helper.PrintPages(
33 [page.display_name for page in page_test_results.pages_that_succeeded])
34 summary = summary_module.Summary(page_test_results.all_page_specific_values)
35 for value in summary.interleaved_computed_per_page_values_and_summaries:
37 self._PrintComputedPerPageValue(value)
39 self._PrintComputedSummaryValue(value, had_failures)
40 self._PrintOverallResults(page_test_results)
42 def _PrintComputedPerPageValue(self, value):
43 # We dont print per-page-values when there is a trace tag.
47 # Actually print the result.
48 buildbot_value = value.GetBuildbotValue()
49 buildbot_data_type = value.GetBuildbotDataType(
50 output_context=value_module.PER_PAGE_RESULT_OUTPUT_CONTEXT)
51 if buildbot_value is None or buildbot_data_type is None:
54 buildbot_measurement_name, buildbot_trace_name = (
55 value.GetChartAndTraceNameForPerPageResult())
56 self._PrintPerfResult(buildbot_measurement_name,
58 buildbot_value, value.units, buildbot_data_type)
60 def _PrintComputedSummaryValue(self, value, had_failures):
61 # If there were any page errors, we typically will print nothing.
63 # Note: this branch is structured less-densely to improve legibility.
67 buildbot_value = value.GetBuildbotValue()
68 buildbot_data_type = value.GetBuildbotDataType(
69 output_context=value_module.COMPUTED_PER_PAGE_SUMMARY_OUTPUT_CONTEXT)
70 if buildbot_value is None or buildbot_data_type is None:
73 buildbot_measurement_name, buildbot_trace_name = (
74 value.GetChartAndTraceNameForComputedSummaryResult(
76 self._PrintPerfResult(buildbot_measurement_name,
78 buildbot_value, value.units, buildbot_data_type)
80 def _PrintOverallResults(self, page_test_results):
81 # If there were no failed pages, output the overall results (results not
82 # associated with a page).
83 had_failures = len(page_test_results.failures) > 0
85 for value in page_test_results.all_summary_values:
86 buildbot_value = value.GetBuildbotValue()
87 buildbot_data_type = value.GetBuildbotDataType(
88 output_context=value_module.SUMMARY_RESULT_OUTPUT_CONTEXT)
89 buildbot_measurement_name, buildbot_trace_name = (
90 value.GetChartAndTraceNameForComputedSummaryResult(
92 self._PrintPerfResult(
93 buildbot_measurement_name,
99 # Print the number of failed and errored pages.
100 self._PrintPerfResult('telemetry_page_measurement_results', 'num_failed',
101 [len(page_test_results.failures)], 'count',
104 # TODO(chrishenry): Remove this in a separate patch to reduce the risk
105 # of rolling back due to buildbot breakage.
106 # Also fix src/tools/bisect-perf-regression_test.py when this is
108 self._PrintPerfResult('telemetry_page_measurement_results', 'num_errored',
109 [0], 'count', 'unimportant')