Chromium Code Reviews| 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 | 12 |
| 13 # Valid values of result type. | 13 # Valid values of result type. |
| 14 RESULT_TYPES = {'unimportant': 'RESULT ', | 14 RESULT_TYPES = {'unimportant': 'RESULT ', |
| 15 'default': '*RESULT ', | 15 'default': '*RESULT ', |
| 16 'informational': '', | 16 'informational': '', |
| 17 'unimportant-histogram': 'HISTOGRAM ', | 17 'unimportant-histogram': 'HISTOGRAM ', |
| 18 'histogram': '*HISTOGRAM '} | 18 'histogram': '*HISTOGRAM '} |
| 19 | 19 |
| 20 | 20 |
| 21 def _EscapePerfResult(s): | 21 def _EscapePerfResult(s): |
| 22 """Escapes |s| for use in a perf result.""" | 22 """Escapes |s| for use in a perf result.""" |
| 23 return re.sub('[\:|=/#&,]', '_', s) | 23 return re.sub('[\:|=/#&,]', '_', s) |
| 24 | 24 |
|
bulach
2013/06/19 12:19:42
nit: add another \n here and after the function (i
| |
| 25 def _Flatten(values): | |
| 26 """Returns a simple list without sub-lists.""" | |
|
bulach
2013/06/19 12:19:42
nit: indentation should be 2 rather than 4
| |
| 27 ret = [] | |
| 28 for entry in values: | |
| 29 if isinstance(entry, list): | |
| 30 ret.extend(_Flatten(entry)) | |
| 31 else: | |
| 32 ret.append(entry) | |
| 33 return ret | |
| 25 | 34 |
| 26 def GeomMeanAndStdDevFromHistogram(histogram_json): | 35 def GeomMeanAndStdDevFromHistogram(histogram_json): |
| 27 histogram = json.loads(histogram_json) | 36 histogram = json.loads(histogram_json) |
| 28 # Handle empty histograms gracefully. | 37 # Handle empty histograms gracefully. |
| 29 if not 'buckets' in histogram: | 38 if not 'buckets' in histogram: |
| 30 return 0.0, 0.0 | 39 return 0.0, 0.0 |
| 31 count = 0 | 40 count = 0 |
| 32 sum_of_logs = 0 | 41 sum_of_logs = 0 |
| 33 for bucket in histogram['buckets']: | 42 for bucket in histogram['buckets']: |
| 34 if 'high' in bucket: | 43 if 'high' in bucket: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 def PrintPerfResult(measurement, trace, values, units, result_type='default', | 84 def PrintPerfResult(measurement, trace, values, units, result_type='default', |
| 76 print_to_stdout=True): | 85 print_to_stdout=True): |
| 77 """Prints numerical data to stdout in the format required by perf tests. | 86 """Prints numerical data to stdout in the format required by perf tests. |
| 78 | 87 |
| 79 The string args may be empty but they must not contain any colons (:) or | 88 The string args may be empty but they must not contain any colons (:) or |
| 80 equals signs (=). | 89 equals signs (=). |
| 81 | 90 |
| 82 Args: | 91 Args: |
| 83 measurement: A description of the quantity being measured, e.g. "vm_peak". | 92 measurement: A description of the quantity being measured, e.g. "vm_peak". |
| 84 trace: A description of the particular data point, e.g. "reference". | 93 trace: A description of the particular data point, e.g. "reference". |
| 85 values: A list of numeric measured values. | 94 values: A list of numeric measured values. |
|
bulach
2013/06/19 12:19:42
nit: probably best to expand this, something like
| |
| 86 units: A description of the units of measure, e.g. "bytes". | 95 units: A description of the units of measure, e.g. "bytes". |
| 87 result_type: Accepts values of RESULT_TYPES. | 96 result_type: Accepts values of RESULT_TYPES. |
| 88 print_to_stdout: If True, prints the output in stdout instead of returning | 97 print_to_stdout: If True, prints the output in stdout instead of returning |
| 89 the output to caller. | 98 the output to caller. |
| 90 | 99 |
| 91 Returns: | 100 Returns: |
| 92 String of the formated perf result. | 101 String of the formated perf result. |
| 93 """ | 102 """ |
| 94 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type | 103 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type |
| 95 | 104 |
| 96 trace_name = _EscapePerfResult(trace) | 105 trace_name = _EscapePerfResult(trace) |
| 97 | 106 |
| 98 if result_type in ['unimportant', 'default', 'informational']: | 107 if result_type in ['unimportant', 'default', 'informational']: |
| 99 assert isinstance(values, list) | 108 assert isinstance(values, list) |
| 100 assert len(values) | 109 assert len(values) |
| 101 assert '/' not in measurement | 110 assert '/' not in measurement |
| 102 value, avg, sd = _MeanAndStdDevFromList(values) | 111 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) |
| 103 output = '%s%s: %s%s%s %s' % ( | 112 output = '%s%s: %s%s%s %s' % ( |
| 104 RESULT_TYPES[result_type], | 113 RESULT_TYPES[result_type], |
| 105 _EscapePerfResult(measurement), | 114 _EscapePerfResult(measurement), |
| 106 trace_name, | 115 trace_name, |
| 107 # Do not show equal sign if the trace is empty. Usually it happens when | 116 # Do not show equal sign if the trace is empty. Usually it happens when |
| 108 # measurement is enough clear to describe the result. | 117 # measurement is enough clear to describe the result. |
| 109 '= ' if trace_name else '', | 118 '= ' if trace_name else '', |
| 110 value, | 119 value, |
| 111 units) | 120 units) |
| 112 else: | 121 else: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 """Resets the original performance mode of the device.""" | 190 """Resets the original performance mode of the device.""" |
| 182 self._SetScalingGovernorInternal(self._original_scaling_governor) | 191 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 183 | 192 |
| 184 def _SetScalingGovernorInternal(self, value): | 193 def _SetScalingGovernorInternal(self, value): |
| 185 for cpu in range(self._kernel_max + 1): | 194 for cpu in range(self._kernel_max + 1): |
| 186 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | 195 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
| 187 if self._adb.FileExistsOnDevice(scaling_governor_file): | 196 if self._adb.FileExistsOnDevice(scaling_governor_file): |
| 188 logging.info('Writing scaling governor mode \'%s\' -> %s' % | 197 logging.info('Writing scaling governor mode \'%s\' -> %s' % |
| 189 (value, scaling_governor_file)) | 198 (value, scaling_governor_file)) |
| 190 self._adb.SetProtectedFileContents(scaling_governor_file, value) | 199 self._adb.SetProtectedFileContents(scaling_governor_file, value) |
| OLD | NEW |