OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 | |
6 import logging | |
7 | |
8 import android_commands | |
9 | |
10 | |
11 class PerfControl(object): | |
12 """Provides methods for setting the performance mode of a device.""" | |
13 _SCALING_GOVERNOR_FMT = ( | |
14 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') | |
15 | |
16 def __init__(self, adb): | |
17 self._adb = adb | |
18 kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', | |
19 log_result=False) | |
20 assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max' | |
frankf
2013/09/16 18:09:23
DRY: Factor out the path
bulach
2013/09/16 19:51:10
Done.
| |
21 self._kernel_max = int(kernel_max[0]) | |
22 logging.info('Maximum CPU index: %d' % self._kernel_max) | |
frankf
2013/09/16 18:09:23
run gpylint: You can pass self._kernel_max as addi
bulach
2013/09/16 19:51:10
Done.
| |
23 self._original_scaling_governor = self._adb.GetFileContents( | |
24 PerfControl._SCALING_GOVERNOR_FMT % 0, | |
25 log_result=False)[0] | |
26 | |
27 def SetHighPerfMode(self): | |
28 """Sets the highest possible performance mode for the device.""" | |
29 self._SetScalingGovernorInternal('performance') | |
30 | |
31 def SetDefaultPerfMode(self): | |
32 """Sets the performance mode for the device to its default mode.""" | |
33 product_model = self._adb.GetProductModel() | |
34 governor_mode = { | |
35 "GT-I9300" : 'pegasusq', | |
36 "Galaxy Nexus" : 'interactive', | |
37 "Nexus 4" : 'ondemand', | |
38 "Nexus 7" : 'interactive', | |
39 "Nexus 10": 'interactive' | |
40 }.get(product_model, 'ondemand') | |
41 self._SetScalingGovernorInternal(governor_mode) | |
42 | |
43 def RestoreOriginalPerfMode(self): | |
44 """Resets the original performance mode of the device.""" | |
45 self._SetScalingGovernorInternal(self._original_scaling_governor) | |
46 | |
47 def _SetScalingGovernorInternal(self, value): | |
48 for cpu in range(self._kernel_max + 1): | |
49 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | |
50 if self._adb.FileExistsOnDevice(scaling_governor_file): | |
51 logging.info('Writing scaling governor mode \'%s\' -> %s' % | |
52 (value, scaling_governor_file)) | |
53 self._adb.SetProtectedFileContents(scaling_governor_file, value) | |
OLD | NEW |