Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | |
| 6 import time | |
| 5 | 7 |
| 6 import logging | |
| 7 from pylib import android_commands | 8 from pylib import android_commands |
| 8 from pylib.device import device_utils | 9 from pylib.device import device_utils |
| 9 | 10 |
| 10 | 11 |
| 11 class PerfControl(object): | 12 class PerfControl(object): |
| 12 """Provides methods for setting the performance mode of a device.""" | 13 """Provides methods for setting the performance mode of a device.""" |
| 13 _SCALING_GOVERNOR_FMT = ( | 14 _SCALING_GOVERNOR_FMT = ( |
| 14 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') | 15 '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor') |
| 15 _KERNEL_MAX = '/sys/devices/system/cpu/kernel_max' | 16 _KERNEL_MAX = '/sys/devices/system/cpu/kernel_max' |
| 16 | 17 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 52 |
| 52 def _SetScalingGovernorInternal(self, value): | 53 def _SetScalingGovernorInternal(self, value): |
| 53 for cpu in range(self._kernel_max + 1): | 54 for cpu in range(self._kernel_max + 1): |
| 54 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu | 55 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
| 55 if self._device.old_interface.FileExistsOnDevice(scaling_governor_file): | 56 if self._device.old_interface.FileExistsOnDevice(scaling_governor_file): |
| 56 logging.info('Writing scaling governor mode \'%s\' -> %s', | 57 logging.info('Writing scaling governor mode \'%s\' -> %s', |
| 57 value, scaling_governor_file) | 58 value, scaling_governor_file) |
| 58 self._device.old_interface.SetProtectedFileContents( | 59 self._device.old_interface.SetProtectedFileContents( |
| 59 scaling_governor_file, value) | 60 scaling_governor_file, value) |
| 60 | 61 |
| 62 def ForceAllCpusOnline(self, force_online): | |
| 63 """Force all CPUs on a device to be online. | |
| 64 | |
| 65 Force every CPU core on an Android device to remain online, or return the | |
| 66 cores under system power management control. This is needed to work around | |
| 67 a bug in perf which makes it unable to record samples from CPUs that become | |
| 68 online when recording is already underway. | |
| 69 | |
| 70 Args: | |
| 71 force_online: True to set all CPUs online, False to return them under | |
| 72 system power management control. | |
| 73 """ | |
| 74 def ForceCpuOnline(online_path): | |
| 75 script = 'chmod 644 {0}; echo 1 > {0}; chmod 444 {0}'.format(online_path) | |
| 76 self._device.old_interface.RunShellCommandWithSU(script) | |
| 77 return self._device.old_interface.GetFileContents(online_path)[0] == '1' | |
| 78 | |
| 79 def ResetCpu(online_path): | |
| 80 self._device.old_interface.RunShellCommandWithSU( | |
| 81 'chmod 644 %s' % online_path) | |
| 82 | |
| 83 def WaitFor(condition): | |
| 84 for _ in range(10): | |
| 85 if condition(): | |
| 86 return | |
| 87 time.sleep(1) | |
|
tonyg
2014/06/09 15:58:09
Should we consider polling more often? 1s delay is
| |
| 88 raise RuntimeError('Timed out') | |
| 89 | |
| 90 cpu_online_files = self._device.old_interface.RunShellCommand( | |
| 91 'ls -d /sys/devices/system/cpu/cpu[0-9]*/online') | |
| 92 for online_path in cpu_online_files: | |
| 93 if force_online: | |
| 94 WaitFor(lambda: ForceCpuOnline(online_path)) | |
| 95 else: | |
| 96 ResetCpu(online_path) | |
| OLD | NEW |