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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 if avg: | 121 if avg: |
122 output += '\nAvg %s: %f%s' % (measurement, avg, units) | 122 output += '\nAvg %s: %f%s' % (measurement, avg, units) |
123 if sd: | 123 if sd: |
124 output += '\nSd %s: %f%s' % (measurement, sd, units) | 124 output += '\nSd %s: %f%s' % (measurement, sd, units) |
125 if print_to_stdout: | 125 if print_to_stdout: |
126 print output | 126 print output |
127 sys.stdout.flush() | 127 sys.stdout.flush() |
128 return output | 128 return output |
129 | 129 |
130 | 130 |
131 class PerfTestSetup(object): | 131 class CacheControl(object): |
132 """Provides methods for setting up a device for perf testing.""" | |
133 _DROP_CACHES = '/proc/sys/vm/drop_caches' | 132 _DROP_CACHES = '/proc/sys/vm/drop_caches' |
133 | |
134 def __init__(self, adb): | |
135 self._adb = adb | |
136 | |
137 def DropRamCaches(self): | |
138 """Drops the filesystem ram caches for performance testing.""" | |
139 self._adb.RunShellCommand('su -c sync') | |
140 self._adb.SetProtectedFileContents(CacheControl._DROP_CACHES, '3') | |
141 | |
bulach
2013/03/19 17:28:46
nit: remove extra \n
aberent
2013/03/19 17:35:46
Done.
| |
142 | |
143 | |
144 class PerfControl(object): | |
145 """Provides methods for setting the performance mode of a device.""" | |
134 _SCALING_GOVERNOR_FMT = ( | 146 _SCALING_GOVERNOR_FMT = ( |
135 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') | 147 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') |
136 | 148 |
137 def __init__(self, adb): | 149 def __init__(self, adb): |
138 self._adb = adb | 150 self._adb = adb |
139 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', | 151 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', |
140 log_result=False) | 152 log_result=False) |
141 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max' | 153 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max' |
142 self._kernel_max = int(kernel_max[0]) | 154 self._kernel_max = int(kernel_max[0]) |
143 self._original_scaling_governor = None | 155 self._original_scaling_governor = self._adb.GetFileContents( |
156 PerfControl._SCALING_GOVERNOR_FMT % 0, | |
157 log_result=False)[0] | |
158 | |
159 def SetHighPerfMode(self): | |
160 """Sets the highest possible performance mode for the device.""" | |
161 self._SetScalingGovernorInternal('performance') | |
162 | |
163 def SetDefaultPerfMode(self): | |
164 """Sets the performance mode for the device to its default mode.""" | |
165 product_model = self._adb.GetProductModel() | |
166 governor_mode = { | |
167 "GT-I9300" : 'pegasusq', | |
168 "Galaxy Nexus" : 'interactive', | |
169 "Nexus 4" : 'ondemand', | |
170 "Nexus 7" : 'interactive', | |
171 "Nexus 10": 'interactive' | |
172 }.get(product_model, 'ondemand') | |
bulach
2013/03/19 17:28:46
maybe interactive as default?
aberent
2013/03/19 17:35:46
My understanding is that ondemand exists on everyt
| |
173 self._SetScalingGovernorInternal(governor_mode) | |
174 | |
175 def RestoreOriginalPerfMode(self): | |
176 """Resets the original performance mode of the device.""" | |
177 self._SetScalingGovernorInternal(self._original_scaling_governor) | |
178 | |
179 def _SetScalingGovernorInternal(self, value): | |
180 for cpu in range(self._kernel_max + 1): | |
181 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | |
182 if self._adb.FileExistsOnDevice(scaling_governor_file): | |
183 self._adb.SetProtectedFileContents(scaling_governor_file, value) | |
184 | |
185 class PerfTestSetup(PerfControl): | |
186 """Provides methods for setting up a device for perf testing. | |
187 | |
188 Will be removed once all tests have been moved to the new classes | |
bulach
2013/03/19 17:28:46
TODO(aberent): remove once all tests have been mov
aberent
2013/03/19 17:35:46
Done.
| |
189 """ | |
144 | 190 |
145 def DropRamCaches(self): | 191 def DropRamCaches(self): |
146 """Drops the filesystem ram caches for performance testing.""" | 192 CacheControl(self._adb).DropRamCaches() |
147 self._adb.RunShellCommand('su -c sync') | |
148 self._adb.SetProtectedFileContents(PerfTestSetup._DROP_CACHES, '3') | |
149 | 193 |
150 def SetUp(self): | 194 def SetUp(self): |
151 """Sets up performance tests.""" | 195 self.SetHighPerfMode() |
152 if not self._original_scaling_governor: | |
153 self._original_scaling_governor = self._adb.GetFileContents( | |
154 PerfTestSetup._SCALING_GOVERNOR_FMT % 0, | |
155 log_result=False)[0] | |
156 self._SetScalingGovernorInternal('performance') | |
157 self.DropRamCaches() | 196 self.DropRamCaches() |
158 | 197 |
159 def TearDown(self): | 198 def TearDown(self): |
160 """Tears down performance tests.""" | 199 self.ResetOriginalPerfMode() |
161 if self._original_scaling_governor: | |
162 self._SetScalingGovernorInternal(self._original_scaling_governor) | |
163 self._original_scaling_governor = None | |
164 | |
165 def _SetScalingGovernorInternal(self, value): | |
166 for cpu in range(self._kernel_max + 1): | |
167 scaling_governor_file = PerfTestSetup._SCALING_GOVERNOR_FMT % cpu | |
168 if self._adb.FileExistsOnDevice(scaling_governor_file): | |
169 self._adb.SetProtectedFileContents(scaling_governor_file, value) | |
OLD | NEW |