| 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 | 6 |
| 7 import android_commands | 7 import android_commands |
| 8 import json | 8 import json |
| 9 import math | 9 import math |
| 10 | 10 |
| 11 # Valid values of result type. | 11 # Valid values of result type. |
| 12 RESULT_TYPES = {'unimportant': 'RESULT ', | 12 RESULT_TYPES = {'unimportant': 'RESULT ', |
| 13 'default': '*RESULT ', | 13 'default': '*RESULT ', |
| 14 'informational': '', | 14 'informational': '', |
| 15 'unimportant-histogram': 'HISTOGRAM ', | 15 'unimportant-histogram': 'HISTOGRAM ', |
| 16 'histogram': '*HISTOGRAM '} | 16 'histogram': '*HISTOGRAM '} |
| 17 | 17 |
| 18 | 18 |
| 19 def _EscapePerfResult(s): | 19 def _EscapePerfResult(s): |
| 20 """Escapes |s| for use in a perf result.""" | 20 """Escapes |s| for use in a perf result.""" |
| 21 return re.sub('[\:|=/#&]', '_', s) | 21 return re.sub('[\:|=/#&]', '_', s) |
| 22 | 22 |
| 23 | 23 |
| 24 def GeomMeanAndStdDevFromHistogram(histogram_json): | 24 def GeomMeanAndStdDevFromHistogram(histogram_json): |
| 25 histogram = json.loads(histogram_json) | 25 histogram = json.loads(histogram_json) |
| 26 # Handle empty histograms gracefully. |
| 27 if not 'buckets' in histogram: |
| 28 return 0.0, 0.0 |
| 26 count = 0 | 29 count = 0 |
| 27 sum_of_logs = 0 | 30 sum_of_logs = 0 |
| 28 for bucket in histogram['buckets']: | 31 for bucket in histogram['buckets']: |
| 29 if 'high' in bucket: | 32 if 'high' in bucket: |
| 30 bucket['mean'] = (bucket['low'] + bucket['high']) / 2.0 | 33 bucket['mean'] = (bucket['low'] + bucket['high']) / 2.0 |
| 31 else: | 34 else: |
| 32 bucket['mean'] = bucket['low'] | 35 bucket['mean'] = bucket['low'] |
| 33 if bucket['mean'] > 0: | 36 if bucket['mean'] > 0: |
| 34 sum_of_logs += math.log(bucket['mean']) * bucket['count'] | 37 sum_of_logs += math.log(bucket['mean']) * bucket['count'] |
| 35 count += bucket['count'] | 38 count += bucket['count'] |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 def TearDown(self): | 158 def TearDown(self): |
| 156 """Tears down performance tests.""" | 159 """Tears down performance tests.""" |
| 157 if self._original_scaling_governor: | 160 if self._original_scaling_governor: |
| 158 self._SetScalingGovernorInternal(self._original_scaling_governor) | 161 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 159 self._original_scaling_governor = None | 162 self._original_scaling_governor = None |
| 160 | 163 |
| 161 def _SetScalingGovernorInternal(self, value): | 164 def _SetScalingGovernorInternal(self, value): |
| 162 for cpu in range(self._num_cpus): | 165 for cpu in range(self._num_cpus): |
| 163 self._adb.RunShellCommand( | 166 self._adb.RunShellCommand( |
| 164 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) | 167 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) |
| OLD | NEW |