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 |
bulach
2013/08/19 08:43:01
forgot to mention, I think this is leftover from p
| |
9 import json | 9 import json |
10 import logging | 10 import logging |
11 import math | 11 import math |
12 | 12 |
13 # Valid values of result type. | |
14 RESULT_TYPES = {'unimportant': 'RESULT ', | |
15 'default': '*RESULT ', | |
16 'informational': '', | |
17 'unimportant-histogram': 'HISTOGRAM ', | |
18 'histogram': '*HISTOGRAM '} | |
19 | 13 |
14 sys.path.append( | |
15 os.path.abspath(os.path.join(os.path.dirname(__file__), | |
16 os.pardir, os.pardir, os.pardir, | |
17 'tools', 'telemetry'))) | |
bulach
2013/08/19 08:37:58
hmm, this is dodgy :)
tools/telemetry already dep
| |
18 | |
19 from telemetry.page import result_data_type | |
20 | |
21 | |
22 # Mapping from result type to test output | |
23 RESULT_TYPES = {result_data_type.UNIMPORTANT: 'RESULT ', | |
24 result_data_type.DEFAULT: '*RESULT ', | |
25 result_data_type.INFORMATIONAL: '', | |
26 result_data_type.UNIMPORTANT_HISTOGRAM: 'HISTOGRAM ', | |
27 result_data_type.HISTOGRAM: '*HISTOGRAM '} | |
20 | 28 |
21 def _EscapePerfResult(s): | 29 def _EscapePerfResult(s): |
22 """Escapes |s| for use in a perf result.""" | 30 """Escapes |s| for use in a perf result.""" |
23 return re.sub('[\:|=/#&,]', '_', s) | 31 return re.sub('[\:|=/#&,]', '_', s) |
24 | 32 |
25 | 33 |
26 def _Flatten(values): | 34 def _Flatten(values): |
27 """Returns a simple list without sub-lists.""" | 35 """Returns a simple list without sub-lists.""" |
28 ret = [] | 36 ret = [] |
29 for entry in values: | 37 for entry in values: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 else: | 84 else: |
77 value = values[0] | 85 value = values[0] |
78 return value, avg, sd | 86 return value, avg, sd |
79 | 87 |
80 | 88 |
81 def PrintPages(page_list): | 89 def PrintPages(page_list): |
82 """Prints list of pages to stdout in the format required by perf tests.""" | 90 """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]) | 91 print 'Pages: [%s]' % ','.join([_EscapePerfResult(p) for p in page_list]) |
84 | 92 |
85 | 93 |
86 def PrintPerfResult(measurement, trace, values, units, result_type='default', | 94 def PrintPerfResult(measurement, trace, values, units, |
95 result_type=result_data_type.DEFAULT, | |
87 print_to_stdout=True): | 96 print_to_stdout=True): |
88 """Prints numerical data to stdout in the format required by perf tests. | 97 """Prints numerical data to stdout in the format required by perf tests. |
89 | 98 |
90 The string args may be empty but they must not contain any colons (:) or | 99 The string args may be empty but they must not contain any colons (:) or |
91 equals signs (=). | 100 equals signs (=). |
92 | 101 |
93 Args: | 102 Args: |
94 measurement: A description of the quantity being measured, e.g. "vm_peak". | 103 measurement: A description of the quantity being measured, e.g. "vm_peak". |
95 trace: A description of the particular data point, e.g. "reference". | 104 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 | 105 values: A list of numeric measured values. An N-dimensional list will be |
97 flattened and treated as a simple list. | 106 flattened and treated as a simple list. |
98 units: A description of the units of measure, e.g. "bytes". | 107 units: A description of the units of measure, e.g. "bytes". |
99 result_type: Accepts values of RESULT_TYPES. | 108 result_type: Accepts values of result_data_type.ALL_TYPES. |
100 print_to_stdout: If True, prints the output in stdout instead of returning | 109 print_to_stdout: If True, prints the output in stdout instead of returning |
101 the output to caller. | 110 the output to caller. |
102 | 111 |
103 Returns: | 112 Returns: |
104 String of the formated perf result. | 113 String of the formated perf result. |
105 """ | 114 """ |
106 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type | 115 assert (result_data_type.IsValidType(result_type), |
116 'result type: %s is invalid' % result_type) | |
107 | 117 |
108 trace_name = _EscapePerfResult(trace) | 118 trace_name = _EscapePerfResult(trace) |
109 | 119 |
110 if result_type in ['unimportant', 'default', 'informational']: | 120 if (result_type == result_data_type.UNIMPORTANT or |
121 result_type == result_data_type.DEFAULT or | |
122 result_type == result_data_type.INFORMATIONAL): | |
111 assert isinstance(values, list) | 123 assert isinstance(values, list) |
112 assert len(values) | 124 assert len(values) |
113 assert '/' not in measurement | 125 assert '/' not in measurement |
114 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) | 126 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) |
115 output = '%s%s: %s%s%s %s' % ( | 127 output = '%s%s: %s%s%s %s' % ( |
116 RESULT_TYPES[result_type], | 128 RESULT_TYPES[result_type], |
117 _EscapePerfResult(measurement), | 129 _EscapePerfResult(measurement), |
118 trace_name, | 130 trace_name, |
119 # Do not show equal sign if the trace is empty. Usually it happens when | 131 # Do not show equal sign if the trace is empty. Usually it happens when |
120 # measurement is enough clear to describe the result. | 132 # measurement is enough clear to describe the result. |
121 '= ' if trace_name else '', | 133 '= ' if trace_name else '', |
122 value, | 134 value, |
123 units) | 135 units) |
124 else: | 136 else: |
125 assert(result_type in ['histogram', 'unimportant-histogram']) | 137 assert result_data_type.IsHistogram(result_type) |
126 assert isinstance(values, list) | 138 assert isinstance(values, list) |
127 # The histograms can only be printed individually, there's no computation | 139 # The histograms can only be printed individually, there's no computation |
128 # across different histograms. | 140 # across different histograms. |
129 assert len(values) == 1 | 141 assert len(values) == 1 |
130 value = values[0] | 142 value = values[0] |
131 output = '%s%s: %s= %s' % ( | 143 output = '%s%s: %s= %s' % ( |
132 RESULT_TYPES[result_type], | 144 RESULT_TYPES[result_type], |
133 _EscapePerfResult(measurement), | 145 _EscapePerfResult(measurement), |
134 trace_name, | 146 trace_name, |
135 value) | 147 value) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 """Resets the original performance mode of the device.""" | 205 """Resets the original performance mode of the device.""" |
194 self._SetScalingGovernorInternal(self._original_scaling_governor) | 206 self._SetScalingGovernorInternal(self._original_scaling_governor) |
195 | 207 |
196 def _SetScalingGovernorInternal(self, value): | 208 def _SetScalingGovernorInternal(self, value): |
197 for cpu in range(self._kernel_max + 1): | 209 for cpu in range(self._kernel_max + 1): |
198 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | 210 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
199 if self._adb.FileExistsOnDevice(scaling_governor_file): | 211 if self._adb.FileExistsOnDevice(scaling_governor_file): |
200 logging.info('Writing scaling governor mode \'%s\' -> %s' % | 212 logging.info('Writing scaling governor mode \'%s\' -> %s' % |
201 (value, scaling_governor_file)) | 213 (value, scaling_governor_file)) |
202 self._adb.SetProtectedFileContents(scaling_governor_file, value) | 214 self._adb.SetProtectedFileContents(scaling_governor_file, value) |
OLD | NEW |