Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / results / buildbot_output_formatter.py
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.
4
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
9
10
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
15
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()
22
23   def Format(self, page_test_results):
24     """Print summary data in a format expected by buildbot for perf dashboards.
25
26     If any failed pages exist, only output individual page results, and do
27     not output any average data.
28     """
29     had_failures = len(page_test_results.failures) > 0
30
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:
36       if value.page:
37         self._PrintComputedPerPageValue(value)
38       else:
39         self._PrintComputedSummaryValue(value, had_failures)
40     self._PrintOverallResults(page_test_results)
41
42   def _PrintComputedPerPageValue(self, value):
43     # We dont print per-page-values when there is a trace tag.
44     if self._trace_tag:
45       return
46
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:
52       return
53
54     buildbot_measurement_name, buildbot_trace_name = (
55         value.GetChartAndTraceNameForPerPageResult())
56     self._PrintPerfResult(buildbot_measurement_name,
57                           buildbot_trace_name,
58                           buildbot_value, value.units, buildbot_data_type)
59
60   def _PrintComputedSummaryValue(self, value, had_failures):
61     # If there were any page errors, we typically will print nothing.
62     #
63     # Note: this branch is structured less-densely to improve legibility.
64     if had_failures:
65       return
66
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:
71       return
72
73     buildbot_measurement_name, buildbot_trace_name = (
74         value.GetChartAndTraceNameForComputedSummaryResult(
75             self._trace_tag))
76     self._PrintPerfResult(buildbot_measurement_name,
77                           buildbot_trace_name,
78                           buildbot_value, value.units, buildbot_data_type)
79
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
84     if not had_failures:
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(
91                 self._trace_tag))
92         self._PrintPerfResult(
93             buildbot_measurement_name,
94             buildbot_trace_name,
95             buildbot_value,
96             value.units,
97             buildbot_data_type)
98
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',
102                           'unimportant')
103
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
107     # removed.
108     self._PrintPerfResult('telemetry_page_measurement_results', 'num_errored',
109                           [0], 'count', 'unimportant')