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 math | 10 import math |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 return geom_mean, math.sqrt(sum_of_squares / count) | 49 return geom_mean, math.sqrt(sum_of_squares / count) |
| 50 | 50 |
| 51 | 51 |
| 52 def _MeanAndStdDevFromList(values): | 52 def _MeanAndStdDevFromList(values): |
| 53 avg = None | 53 avg = None |
| 54 sd = None | 54 sd = None |
| 55 if len(values) > 1: | 55 if len(values) > 1: |
| 56 try: | 56 try: |
| 57 value = '[%s]' % ','.join([str(v) for v in values]) | 57 value = '[%s]' % ','.join([str(v) for v in values]) |
| 58 avg = sum([float(v) for v in values]) / len(values) | 58 avg = sum([float(v) for v in values]) / len(values) |
| 59 sqdiffs = [(float(v) - avg) ** 2 for v in values] | 59 sqdiffs = [(float(v) - avg) ** 2 for v in values] |
|
nduca
2013/02/13 18:45:55
yeah, this shouldn't be in android... this library
marja
2013/02/14 13:06:53
This function is used by PrintPerfResult, it needs
| |
| 60 variance = sum(sqdiffs) / (len(values) - 1) | 60 variance = sum(sqdiffs) / (len(values) - 1) |
| 61 sd = math.sqrt(variance) | 61 sd = math.sqrt(variance) |
| 62 except ValueError: | 62 except ValueError: |
| 63 value = ", ".join(values) | 63 value = ", ".join(values) |
| 64 else: | 64 else: |
| 65 value = values[0] | 65 value = values[0] |
| 66 return value, avg, sd | 66 return value, avg, sd |
| 67 | 67 |
| 68 def SubtractHistogram(histogram_json, start_histogram_json): | |
|
marja
2013/02/14 13:06:53
And I moved this one away now.
| |
| 69 """Subtracts a previous histogram from a histogram. Both parameters are json | |
| 70 serializations of histograms.""" | |
| 71 histogram = json.loads(histogram_json) | |
| 72 start_histogram = json.loads(start_histogram_json) | |
| 73 | |
| 74 start_histogram_buckets = dict() | |
| 75 for b in start_histogram['buckets']: | |
| 76 start_histogram_buckets[b['low']] = b['count'] | |
| 77 | |
| 78 new_buckets = [] | |
| 79 for b in histogram['buckets']: | |
| 80 new_bucket = b | |
| 81 low = b['low'] | |
| 82 if low in start_histogram_buckets: | |
| 83 new_bucket['count'] = b['count'] - start_histogram_buckets[low] | |
| 84 if new_bucket['count']: | |
| 85 new_buckets.append(new_bucket) | |
| 86 histogram['buckets'] = new_buckets | |
| 87 histogram['count'] -= start_histogram['count'] | |
| 88 | |
| 89 return json.dumps(histogram) | |
| 68 | 90 |
| 69 def PrintPerfResult(measurement, trace, values, units, result_type='default', | 91 def PrintPerfResult(measurement, trace, values, units, result_type='default', |
| 70 print_to_stdout=True): | 92 print_to_stdout=True): |
| 71 """Prints numerical data to stdout in the format required by perf tests. | 93 """Prints numerical data to stdout in the format required by perf tests. |
| 72 | 94 |
| 73 The string args may be empty but they must not contain any colons (:) or | 95 The string args may be empty but they must not contain any colons (:) or |
| 74 equals signs (=). | 96 equals signs (=). |
| 75 | 97 |
| 76 Args: | 98 Args: |
| 77 measurement: A description of the quantity being measured, e.g. "vm_peak". | 99 measurement: A description of the quantity being measured, e.g. "vm_peak". |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 """Tears down performance tests.""" | 182 """Tears down performance tests.""" |
| 161 if self._original_scaling_governor: | 183 if self._original_scaling_governor: |
| 162 self._SetScalingGovernorInternal(self._original_scaling_governor) | 184 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 163 self._original_scaling_governor = None | 185 self._original_scaling_governor = None |
| 164 | 186 |
| 165 def _SetScalingGovernorInternal(self, value): | 187 def _SetScalingGovernorInternal(self, value): |
| 166 for cpu in range(self._kernel_max + 1): | 188 for cpu in range(self._kernel_max + 1): |
| 167 scaling_governor_file = PerfTestSetup._SCALING_GOVERNOR_FMT % cpu | 189 scaling_governor_file = PerfTestSetup._SCALING_GOVERNOR_FMT % cpu |
| 168 if self._adb.FileExistsOnDevice(scaling_governor_file): | 190 if self._adb.FileExistsOnDevice(scaling_governor_file): |
| 169 self._adb.SetProtectedFileContents(scaling_governor_file, value) | 191 self._adb.SetProtectedFileContents(scaling_governor_file, value) |
| OLD | NEW |