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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if sd: | 119 if sd: |
120 output += '\nSd %s: %f%s' % (measurement, sd, units) | 120 output += '\nSd %s: %f%s' % (measurement, sd, units) |
121 if print_to_stdout: | 121 if print_to_stdout: |
122 print output | 122 print output |
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_FMT = ( |
| 130 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') |
130 | 131 |
131 def __init__(self, adb): | 132 def __init__(self, adb): |
132 self._adb = adb | 133 self._adb = adb |
133 num_cpus = self._adb.GetFileContents('/sys/devices/system/cpu/online', | 134 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', |
134 log_result=False) | 135 log_result=False) |
135 assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' | 136 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max' |
136 self._num_cpus = int(num_cpus[0].split('-')[-1]) | 137 self._kernel_max = int(kernel_max[0]) |
137 self._original_scaling_governor = None | 138 self._original_scaling_governor = None |
138 | 139 |
139 def DropRamCaches(self): | 140 def DropRamCaches(self): |
140 """Drops the filesystem ram caches for performance testing.""" | 141 """Drops the filesystem ram caches for performance testing.""" |
141 if not self._adb.IsRootEnabled(): | 142 if not self._adb.IsRootEnabled(): |
142 self._adb.EnableAdbRoot() | 143 self._adb.EnableAdbRoot() |
143 self._adb.RunShellCommand('sync') | 144 self._adb.RunShellCommand('sync') |
144 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) | 145 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) |
145 | 146 |
146 def SetUp(self): | 147 def SetUp(self): |
147 """Sets up performance tests.""" | 148 """Sets up performance tests.""" |
148 if not self._original_scaling_governor: | 149 if not self._original_scaling_governor: |
149 self._original_scaling_governor = self._adb.GetFileContents( | 150 self._original_scaling_governor = self._adb.GetFileContents( |
150 PerfTestSetup._SCALING_GOVERNOR % 0, | 151 PerfTestSetup._SCALING_GOVERNOR_FMT % 0, |
151 log_result=False)[0] | 152 log_result=False)[0] |
152 self._SetScalingGovernorInternal('performance') | 153 self._SetScalingGovernorInternal('performance') |
153 self.DropRamCaches() | 154 self.DropRamCaches() |
154 | 155 |
155 def TearDown(self): | 156 def TearDown(self): |
156 """Tears down performance tests.""" | 157 """Tears down performance tests.""" |
157 if self._original_scaling_governor: | 158 if self._original_scaling_governor: |
158 self._SetScalingGovernorInternal(self._original_scaling_governor) | 159 self._SetScalingGovernorInternal(self._original_scaling_governor) |
159 self._original_scaling_governor = None | 160 self._original_scaling_governor = None |
160 | 161 |
161 def _SetScalingGovernorInternal(self, value): | 162 def _SetScalingGovernorInternal(self, value): |
162 for cpu in range(self._num_cpus): | 163 for cpu in range(self._kernel_max + 1): |
163 self._adb.RunShellCommand( | 164 scaling_governor_file = PerfTestSetup._SCALING_GOVERNOR_FMT % cpu |
164 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) | 165 if self._adb.Adb().DoesFileExist(scaling_governor_file): |
| 166 self._adb.RunShellCommand( |
| 167 ('echo %s > ' + scaling_governor_file) % value) |
OLD | NEW |