Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / telemetry / internal / results / output_formatter.py
blobccd49d28f92d6edc078b34d0ad40615da9c215ce
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 import os
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
17 CSV format."""
19 def __init__(self, output_stream):
20 """Constructs a new formatter that writes to the output_stream.
22 Args:
23 output_stream: The stream to write the formatted output to.
24 """
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.
32 Args:
33 page_test_results: A PageTestResults object containing all results
34 from the current benchmark run.
35 """
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.
45 """
46 pass
48 @property
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.
63 """
64 # Default summary uses merge_values.DefaultKeyFunc to summarize both by name
65 # and tir_label.
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(
71 page_specific_values,
72 key_func=lambda v: v.name)
73 values.extend(
74 summary_by_name_only.interleaved_computed_per_page_values_and_summaries
76 return values