Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: build/android/pylib/perf_tests_helper.py

Issue 23681011: Android: splits cache_control and perf_control. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 cache_control
10 import perf_control
9 import json 11 import json
10 import logging 12 import logging
11 import math 13 import math
12 14
13 # Valid values of result type. 15 # Valid values of result type.
14 RESULT_TYPES = {'unimportant': 'RESULT ', 16 RESULT_TYPES = {'unimportant': 'RESULT ',
15 'default': '*RESULT ', 17 'default': '*RESULT ',
16 'informational': '', 18 'informational': '',
17 'unimportant-histogram': 'HISTOGRAM ', 19 'unimportant-histogram': 'HISTOGRAM ',
18 'histogram': '*HISTOGRAM '} 20 'histogram': '*HISTOGRAM '}
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if avg: 141 if avg:
140 output += '\nAvg %s: %f%s' % (measurement, avg, units) 142 output += '\nAvg %s: %f%s' % (measurement, avg, units)
141 if sd: 143 if sd:
142 output += '\nSd %s: %f%s' % (measurement, sd, units) 144 output += '\nSd %s: %f%s' % (measurement, sd, units)
143 if print_to_stdout: 145 if print_to_stdout:
144 print output 146 print output
145 sys.stdout.flush() 147 sys.stdout.flush()
146 return output 148 return output
147 149
148 150
149 class CacheControl(object): 151 # TODO(bulach): remove once all references to PerfControl are fixed.
150 _DROP_CACHES = '/proc/sys/vm/drop_caches' 152 class CacheControl(cache_control.CacheControl):
153 def __init__(self, adb):
154 super(CacheControl, self).__init__(adb)
151 155
156 class PerfControl(perf_control.PerfControl):
152 def __init__(self, adb): 157 def __init__(self, adb):
153 self._adb = adb 158 super(PerfControl, self).__init__(adb)
154
155 def DropRamCaches(self):
156 """Drops the filesystem ram caches for performance testing."""
157 self._adb.RunShellCommand('su -c sync')
158 self._adb.SetProtectedFileContents(CacheControl._DROP_CACHES, '3')
159
160
161 class PerfControl(object):
162 """Provides methods for setting the performance mode of a device."""
163 _SCALING_GOVERNOR_FMT = (
164 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor')
165
166 def __init__(self, adb):
167 self._adb = adb
168 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max',
169 log_result=False)
170 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max'
171 self._kernel_max = int(kernel_max[0])
172 logging.info('Maximum CPU index: %d' % self._kernel_max)
173 self._original_scaling_governor = self._adb.GetFileContents(
174 PerfControl._SCALING_GOVERNOR_FMT % 0,
175 log_result=False)[0]
176
177 def SetHighPerfMode(self):
178 """Sets the highest possible performance mode for the device."""
179 self._SetScalingGovernorInternal('performance')
180
181 def SetDefaultPerfMode(self):
182 """Sets the performance mode for the device to its default mode."""
183 product_model = self._adb.GetProductModel()
184 governor_mode = {
185 "GT-I9300" : 'pegasusq',
186 "Galaxy Nexus" : 'interactive',
187 "Nexus 4" : 'ondemand',
188 "Nexus 7" : 'interactive',
189 "Nexus 10": 'interactive'
190 }.get(product_model, 'ondemand')
191 self._SetScalingGovernorInternal(governor_mode)
192
193 def RestoreOriginalPerfMode(self):
194 """Resets the original performance mode of the device."""
195 self._SetScalingGovernorInternal(self._original_scaling_governor)
196
197 def _SetScalingGovernorInternal(self, value):
198 for cpu in range(self._kernel_max + 1):
199 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu
200 if self._adb.FileExistsOnDevice(scaling_governor_file):
201 logging.info('Writing scaling governor mode \'%s\' -> %s' %
202 (value, scaling_governor_file))
203 self._adb.SetProtectedFileContents(scaling_governor_file, value)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698