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.
7 from telemetry
.value
import summary
as summary_module
9 class OutputFormatter(object):
10 """A formatter for PageTestResults.
12 An OutputFormatter takes PageTestResults, formats the results
13 (telemetry.value.Value instances), and output the formatted results
14 in the given output stream.
16 Examples of output formatter: CsvOutputFormatter produces results in
19 def __init__(self
, output_stream
):
20 """Constructs a new formatter that writes to the output_stream.
23 output_stream: The stream to write the formatted output to.
25 self
._output
_stream
= output_stream
27 def Format(self
, page_test_results
):
28 """Formats the given PageTestResults into the output stream.
30 This will be called once at the end of a benchmark.
33 page_test_results: A PageTestResults object containing all results
34 from the current benchmark run.
36 raise NotImplementedError()
38 def PrintViewResults(self
):
39 print 'View result at file://' + os
.path
.abspath(self
.output_stream
.name
)
41 def FormatDisabled(self
):
42 """Formats disabled results into the output stream.
44 This will be called once when a benchmark is run but disabled.
49 def output_stream(self
):
50 return self
._output
_stream
53 def SummarizePageSpecificValues(page_specific_values
):
54 """Summarize results appropriately for TBM and legacy benchmarks.
56 For benchmarks that are timeline-based, we need to summarize not once, but
57 twice, once by name and tir_label (default) and again by name only. But for
58 benchmarks that are not timeline-based, since no tir_labels are set, we will
59 end up duplicating values.
61 Thus, we only want to summarize once if the benchmark is not timeline-based,
62 but twice, using the two different key functions, otherwise.
64 # Default summary uses merge_values.DefaultKeyFunc to summarize both by name
66 summary
= summary_module
.Summary(page_specific_values
)
67 values
= summary
.interleaved_computed_per_page_values_and_summaries
69 if any(v
.tir_label
for v
in page_specific_values
):
70 summary_by_name_only
= summary_module
.Summary(
72 key_func
=lambda v
: v
.name
)
74 summary_by_name_only
.interleaved_computed_per_page_values_and_summaries