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 | 6 |
| 7 import android_commands | 7 import android_commands |
| 8 import json | 8 import json |
| 9 import math | 9 import math |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 return output | 123 return output |
| 124 | 124 |
| 125 | 125 |
| 126 class PerfTestSetup(object): | 126 class PerfTestSetup(object): |
| 127 """Provides methods for setting up a device for perf testing.""" | 127 """Provides methods for setting up a device for perf testing.""" |
| 128 _DROP_CACHES = '/proc/sys/vm/drop_caches' | 128 _DROP_CACHES = '/proc/sys/vm/drop_caches' |
| 129 _SCALING_GOVERNOR = '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor' | 129 _SCALING_GOVERNOR = '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor' |
| 130 | 130 |
| 131 def __init__(self, adb): | 131 def __init__(self, adb): |
| 132 self._adb = adb | 132 self._adb = adb |
| 133 num_cpus = self._adb.GetFileContents('/sys/devices/system/cpu/online', | 133 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', |
| 134 log_result=False) | 134 log_result=False) |
| 135 assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' | 135 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max' |
| 136 self._num_cpus = int(num_cpus[0].split('-')[-1]) | 136 self._kernel_max = int(kernel_max[0]) |
| 137 self._original_scaling_governor = None | 137 self._original_scaling_governor = None |
| 138 | 138 |
| 139 def DropRamCaches(self): | 139 def DropRamCaches(self): |
| 140 """Drops the filesystem ram caches for performance testing.""" | 140 """Drops the filesystem ram caches for performance testing.""" |
| 141 if not self._adb.IsRootEnabled(): | 141 if not self._adb.IsRootEnabled(): |
| 142 self._adb.EnableAdbRoot() | 142 self._adb.EnableAdbRoot() |
| 143 self._adb.RunShellCommand('sync') | 143 self._adb.RunShellCommand('sync') |
| 144 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) | 144 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) |
| 145 | 145 |
| 146 def SetUp(self): | 146 def SetUp(self): |
| 147 """Sets up performance tests.""" | 147 """Sets up performance tests.""" |
| 148 if not self._original_scaling_governor: | 148 if not self._original_scaling_governor: |
| 149 self._original_scaling_governor = self._adb.GetFileContents( | 149 self._original_scaling_governor = self._adb.GetFileContents( |
| 150 PerfTestSetup._SCALING_GOVERNOR % 0, | 150 PerfTestSetup._SCALING_GOVERNOR % 0, |
| 151 log_result=False)[0] | 151 log_result=False)[0] |
| 152 self._SetScalingGovernorInternal('performance') | 152 self._SetScalingGovernorInternal('performance') |
| 153 self.DropRamCaches() | 153 self.DropRamCaches() |
| 154 | 154 |
| 155 def TearDown(self): | 155 def TearDown(self): |
| 156 """Tears down performance tests.""" | 156 """Tears down performance tests.""" |
| 157 if self._original_scaling_governor: | 157 if self._original_scaling_governor: |
| 158 self._SetScalingGovernorInternal(self._original_scaling_governor) | 158 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 159 self._original_scaling_governor = None | 159 self._original_scaling_governor = None |
| 160 | 160 |
| 161 def _SetScalingGovernorInternal(self, value): | 161 def _SetScalingGovernorInternal(self, value): |
| 162 for cpu in range(self._num_cpus): | 162 for cpu in range(self._kernel_max + 1): |
| 163 self._adb.RunShellCommand( | 163 scaling_governor = PerfTestSetup._SCALING_GOVERNOR % cpu |
|
bulach
2013/01/16 09:34:15
hehe, probably best to:
scaling_governor_file = Pe
| |
| 164 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) | 164 if self._adb.Adb().DoesFileExist(scaling_governor): |
| 165 self._adb.RunShellCommand( | |
| 166 ('echo %s > ' + scaling_governor) % value) | |
| OLD | NEW |