Chromium Code Reviews| Index: build/android/pylib/perf_control.py |
| diff --git a/build/android/pylib/perf_control.py b/build/android/pylib/perf_control.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..403ff75258716ae90b1e07be4c85c2c3e97f6894 |
| --- /dev/null |
| +++ b/build/android/pylib/perf_control.py |
| @@ -0,0 +1,53 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| + |
| +import logging |
| + |
| +import android_commands |
| + |
| + |
| +class PerfControl(object): |
| + """Provides methods for setting the performance mode of a device.""" |
| + _SCALING_GOVERNOR_FMT = ( |
| + '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') |
| + |
| + def __init__(self, adb): |
| + self._adb = adb |
| + kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max', |
| + log_result=False) |
| + 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.
|
| + self._kernel_max = int(kernel_max[0]) |
| + 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.
|
| + self._original_scaling_governor = self._adb.GetFileContents( |
| + PerfControl._SCALING_GOVERNOR_FMT % 0, |
| + log_result=False)[0] |
| + |
| + def SetHighPerfMode(self): |
| + """Sets the highest possible performance mode for the device.""" |
| + self._SetScalingGovernorInternal('performance') |
| + |
| + def SetDefaultPerfMode(self): |
| + """Sets the performance mode for the device to its default mode.""" |
| + product_model = self._adb.GetProductModel() |
| + governor_mode = { |
| + "GT-I9300" : 'pegasusq', |
| + "Galaxy Nexus" : 'interactive', |
| + "Nexus 4" : 'ondemand', |
| + "Nexus 7" : 'interactive', |
| + "Nexus 10": 'interactive' |
| + }.get(product_model, 'ondemand') |
| + self._SetScalingGovernorInternal(governor_mode) |
| + |
| + def RestoreOriginalPerfMode(self): |
| + """Resets the original performance mode of the device.""" |
| + self._SetScalingGovernorInternal(self._original_scaling_governor) |
| + |
| + def _SetScalingGovernorInternal(self, value): |
| + for cpu in range(self._kernel_max + 1): |
| + scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
| + if self._adb.FileExistsOnDevice(scaling_governor_file): |
| + logging.info('Writing scaling governor mode \'%s\' -> %s' % |
| + (value, scaling_governor_file)) |
| + self._adb.SetProtectedFileContents(scaling_governor_file, value) |