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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 num_cpus = self._adb.GetFileContents('/sys/devices/system/cpu/online', |
| 134 log_result=False) | 134 log_result=False) |
| 135 assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' | 135 assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' |
| 136 self._num_cpus = int(num_cpus[0].split('-')[-1]) | 136 self._num_cpus = int(re.findall(r'\d+',num_cpus[0])[-1]) |
|
bulach
2013/01/14 17:26:50
nit: space after ,
aberent
2013/01/14 20:19:10
Done.
| |
| 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 self._adb.RunShellCommand('su -c sync') |
| 142 self._adb.EnableAdbRoot() | 142 self._adb.RunShellCommand('su -c echo 3 > ' + PerfTestSetup._DROP_CACHES) |
| 143 self._adb.RunShellCommand('sync') | |
| 144 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) | |
| 145 | 143 |
| 146 def SetUp(self): | 144 def SetUp(self): |
| 147 """Sets up performance tests.""" | 145 """Sets up performance tests.""" |
| 148 if not self._original_scaling_governor: | 146 if not self._original_scaling_governor: |
| 149 self._original_scaling_governor = self._adb.GetFileContents( | 147 self._original_scaling_governor = self._adb.GetFileContents( |
| 150 PerfTestSetup._SCALING_GOVERNOR % 0, | 148 PerfTestSetup._SCALING_GOVERNOR % 0, |
| 151 log_result=False)[0] | 149 log_result=False)[0] |
| 152 self._SetScalingGovernorInternal('performance') | 150 self._SetScalingGovernorInternal('performance') |
| 153 self.DropRamCaches() | 151 self.DropRamCaches() |
| 154 | 152 |
| 155 def TearDown(self): | 153 def TearDown(self): |
| 156 """Tears down performance tests.""" | 154 """Tears down performance tests.""" |
| 157 if self._original_scaling_governor: | 155 if self._original_scaling_governor: |
| 158 self._SetScalingGovernorInternal(self._original_scaling_governor) | 156 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 159 self._original_scaling_governor = None | 157 self._original_scaling_governor = None |
| 160 | 158 |
| 161 def _SetScalingGovernorInternal(self, value): | 159 def _SetScalingGovernorInternal(self, value): |
| 162 for cpu in range(self._num_cpus): | 160 for cpu in range(self._num_cpus): |
| 163 self._adb.RunShellCommand( | 161 self._adb.RunShellCommand( |
| 164 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) | 162 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) |
| OLD | NEW |