OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import re | 5 import re |
6 import sys | 6 import sys |
7 | 7 |
8 import android_commands | 8 import android_commands |
9 import json | 9 import json |
10 import logging | 10 import logging |
11 import math | 11 import math |
12 from telemetry.page import result_data_type | |
12 | 13 |
13 # Valid values of result type. | |
14 RESULT_TYPES = {'unimportant': 'RESULT ', | |
15 'default': '*RESULT ', | |
16 'informational': '', | |
17 'unimportant-histogram': 'HISTOGRAM ', | |
18 'histogram': '*HISTOGRAM '} | |
19 | 14 |
15 # Mapping from result type to test output | |
16 RESULT_TYPES = {result_data_type.UNIMPORTANT: 'RESULT ', | |
17 result_data_type.DEFAULT: '*RESULT ', | |
18 result_data_type.INFORMATIONAL: '', | |
19 result_data_type.UNIMPORTANT_HISTOGRAM: 'HISTOGRAM ', | |
20 result_data_type.HISTOGRAM: '*HISTOGRAM '} | |
20 | 21 |
21 def _EscapePerfResult(s): | 22 def _EscapePerfResult(s): |
22 """Escapes |s| for use in a perf result.""" | 23 """Escapes |s| for use in a perf result.""" |
23 return re.sub('[\:|=/#&,]', '_', s) | 24 return re.sub('[\:|=/#&,]', '_', s) |
24 | 25 |
25 | 26 |
26 def _Flatten(values): | 27 def _Flatten(values): |
27 """Returns a simple list without sub-lists.""" | 28 """Returns a simple list without sub-lists.""" |
28 ret = [] | 29 ret = [] |
29 for entry in values: | 30 for entry in values: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 else: | 77 else: |
77 value = values[0] | 78 value = values[0] |
78 return value, avg, sd | 79 return value, avg, sd |
79 | 80 |
80 | 81 |
81 def PrintPages(page_list): | 82 def PrintPages(page_list): |
82 """Prints list of pages to stdout in the format required by perf tests.""" | 83 """Prints list of pages to stdout in the format required by perf tests.""" |
83 print 'Pages: [%s]' % ','.join([_EscapePerfResult(p) for p in page_list]) | 84 print 'Pages: [%s]' % ','.join([_EscapePerfResult(p) for p in page_list]) |
84 | 85 |
85 | 86 |
86 def PrintPerfResult(measurement, trace, values, units, result_type='default', | 87 def PrintPerfResult(measurement, trace, values, units, |
88 result_type=result_data_type.DEFAULT, | |
87 print_to_stdout=True): | 89 print_to_stdout=True): |
88 """Prints numerical data to stdout in the format required by perf tests. | 90 """Prints numerical data to stdout in the format required by perf tests. |
89 | 91 |
90 The string args may be empty but they must not contain any colons (:) or | 92 The string args may be empty but they must not contain any colons (:) or |
91 equals signs (=). | 93 equals signs (=). |
92 | 94 |
93 Args: | 95 Args: |
94 measurement: A description of the quantity being measured, e.g. "vm_peak". | 96 measurement: A description of the quantity being measured, e.g. "vm_peak". |
95 trace: A description of the particular data point, e.g. "reference". | 97 trace: A description of the particular data point, e.g. "reference". |
96 values: A list of numeric measured values. An N-dimensional list will be | 98 values: A list of numeric measured values. An N-dimensional list will be |
97 flattened and treated as a simple list. | 99 flattened and treated as a simple list. |
98 units: A description of the units of measure, e.g. "bytes". | 100 units: A description of the units of measure, e.g. "bytes". |
99 result_type: Accepts values of RESULT_TYPES. | 101 result_type: Accepts values of result_data_type.ALL_TYPES. |
100 print_to_stdout: If True, prints the output in stdout instead of returning | 102 print_to_stdout: If True, prints the output in stdout instead of returning |
101 the output to caller. | 103 the output to caller. |
102 | 104 |
103 Returns: | 105 Returns: |
104 String of the formated perf result. | 106 String of the formated perf result. |
105 """ | 107 """ |
106 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type | 108 assert result_data_type.IsValidType(result_type), \ |
dtu
2013/08/16 00:40:02
nit: use parentheses instead of \ (Google style gu
| |
109 'result type: %s is invalid' % result_type | |
107 | 110 |
108 trace_name = _EscapePerfResult(trace) | 111 trace_name = _EscapePerfResult(trace) |
109 | 112 |
110 if result_type in ['unimportant', 'default', 'informational']: | 113 if (result_type == result_data_type.UNIMPORTANT or |
114 result_type == result_data_type.DEFAULT or | |
115 result_type == result_data_type.INFORMATIONAL): | |
111 assert isinstance(values, list) | 116 assert isinstance(values, list) |
112 assert len(values) | 117 assert len(values) |
113 assert '/' not in measurement | 118 assert '/' not in measurement |
114 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) | 119 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) |
115 output = '%s%s: %s%s%s %s' % ( | 120 output = '%s%s: %s%s%s %s' % ( |
116 RESULT_TYPES[result_type], | 121 RESULT_TYPES[result_type], |
117 _EscapePerfResult(measurement), | 122 _EscapePerfResult(measurement), |
118 trace_name, | 123 trace_name, |
119 # Do not show equal sign if the trace is empty. Usually it happens when | 124 # Do not show equal sign if the trace is empty. Usually it happens when |
120 # measurement is enough clear to describe the result. | 125 # measurement is enough clear to describe the result. |
121 '= ' if trace_name else '', | 126 '= ' if trace_name else '', |
122 value, | 127 value, |
123 units) | 128 units) |
124 else: | 129 else: |
125 assert(result_type in ['histogram', 'unimportant-histogram']) | 130 assert result_data_type.IsHistogram(result_type) |
126 assert isinstance(values, list) | 131 assert isinstance(values, list) |
127 # The histograms can only be printed individually, there's no computation | 132 # The histograms can only be printed individually, there's no computation |
128 # across different histograms. | 133 # across different histograms. |
129 assert len(values) == 1 | 134 assert len(values) == 1 |
130 value = values[0] | 135 value = values[0] |
131 output = '%s%s: %s= %s' % ( | 136 output = '%s%s: %s= %s' % ( |
132 RESULT_TYPES[result_type], | 137 RESULT_TYPES[result_type], |
133 _EscapePerfResult(measurement), | 138 _EscapePerfResult(measurement), |
134 trace_name, | 139 trace_name, |
135 value) | 140 value) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 """Resets the original performance mode of the device.""" | 198 """Resets the original performance mode of the device.""" |
194 self._SetScalingGovernorInternal(self._original_scaling_governor) | 199 self._SetScalingGovernorInternal(self._original_scaling_governor) |
195 | 200 |
196 def _SetScalingGovernorInternal(self, value): | 201 def _SetScalingGovernorInternal(self, value): |
197 for cpu in range(self._kernel_max + 1): | 202 for cpu in range(self._kernel_max + 1): |
198 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | 203 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
199 if self._adb.FileExistsOnDevice(scaling_governor_file): | 204 if self._adb.FileExistsOnDevice(scaling_governor_file): |
200 logging.info('Writing scaling governor mode \'%s\' -> %s' % | 205 logging.info('Writing scaling governor mode \'%s\' -> %s' % |
201 (value, scaling_governor_file)) | 206 (value, scaling_governor_file)) |
202 self._adb.SetProtectedFileContents(scaling_governor_file, value) | 207 self._adb.SetProtectedFileContents(scaling_governor_file, value) |
OLD | NEW |