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 5from telemetry import perf_tests_helper 6from telemetry import value as value_module 7from telemetry.value import summary as summary_module 8from telemetry.results import page_measurement_results 9 10 11class BuildbotPageMeasurementResults( 12 page_measurement_results.PageMeasurementResults): 13 def __init__(self, output_stream, trace_tag=''): 14 super(BuildbotPageMeasurementResults, self).__init__(output_stream) 15 self._trace_tag = trace_tag 16 17 def _PrintPerfResult(self, measurement, trace, v, units, 18 result_type='default'): 19 output = perf_tests_helper.PrintPerfResult( 20 measurement, trace, v, units, result_type, print_to_stdout=False) 21 self._output_stream.write(output + '\n') 22 self._output_stream.flush() 23 24 @property 25 def had_errors_or_failures(self): 26 return self.errors or self.failures 27 28 def PrintSummary(self): 29 """Print summary data in a format expected by buildbot for perf dashboards. 30 31 If any failed pages exist, only output individual page results, and do 32 not output any average data. 33 """ 34 # Print out the list of unique pages. 35 perf_tests_helper.PrintPages( 36 [page.display_name for page in self.pages_that_succeeded]) 37 summary = summary_module.Summary(self.all_page_specific_values, 38 self.had_errors_or_failures) 39 for value in summary.interleaved_computed_per_page_values_and_summaries: 40 if value.page: 41 self._PrintComputedPerPageValue(value) 42 else: 43 self._PrintComputedSummaryValue(value) 44 self._PrintOverallResults() 45 46 def _PrintComputedPerPageValue(self, value): 47 # We dont print per-page-values when there is a trace tag. 48 if self._trace_tag: 49 return 50 51 # Actually print the result. 52 buildbot_value = value.GetBuildbotValue() 53 buildbot_data_type = value.GetBuildbotDataType( 54 output_context=value_module.PER_PAGE_RESULT_OUTPUT_CONTEXT) 55 buildbot_measurement_name, buildbot_trace_name = ( 56 value.GetBuildbotMeasurementAndTraceNameForPerPageResult()) 57 self._PrintPerfResult(buildbot_measurement_name, 58 buildbot_trace_name, 59 buildbot_value, value.units, buildbot_data_type) 60 61 def _PrintComputedSummaryValue(self, value): 62 # If there were any page errors, we typically will print nothing. 63 # 64 # Note: this branch is structured less-densely to improve legibility. 65 if self.had_errors_or_failures: 66 return 67 68 buildbot_value = value.GetBuildbotValue() 69 buildbot_data_type = value.GetBuildbotDataType( 70 output_context=value_module.COMPUTED_PER_PAGE_SUMMARY_OUTPUT_CONTEXT) 71 buildbot_measurement_name, buildbot_trace_name = ( 72 value.GetBuildbotMeasurementAndTraceNameForComputedSummaryResult( 73 self._trace_tag)) 74 75 self._PrintPerfResult(buildbot_measurement_name, 76 buildbot_trace_name, 77 buildbot_value, value.units, buildbot_data_type) 78 79 def _PrintOverallResults(self): 80 # If there were no failed pages, output the overall results (results not 81 # associated with a page). 82 if not self.had_errors_or_failures: 83 for value in self._all_summary_values: 84 buildbot_value = value.GetBuildbotValue() 85 buildbot_data_type = value.GetBuildbotDataType( 86 output_context=value_module.SUMMARY_RESULT_OUTPUT_CONTEXT) 87 buildbot_measurement_name, buildbot_trace_name = ( 88 value.GetBuildbotMeasurementAndTraceNameForComputedSummaryResult( 89 self._trace_tag)) 90 self._PrintPerfResult( 91 buildbot_measurement_name, 92 buildbot_trace_name, 93 buildbot_value, 94 value.units, 95 buildbot_data_type) 96 97 98 # Print the number of failed and errored pages. 99 self._PrintPerfResult('telemetry_page_measurement_results', 'num_failed', 100 [len(self.failures)], 'count', 'unimportant') 101 self._PrintPerfResult('telemetry_page_measurement_results', 'num_errored', 102 [len(self.errors)], 'count', 'unimportant') 103 104 super(BuildbotPageMeasurementResults, self).PrintSummary() 105