| 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 | 5 import logging |
| 6 import time | 6 import time |
| 7 | 7 |
| 8 from pylib import android_commands | 8 from pylib import android_commands |
| 9 from pylib.device import device_utils | 9 from pylib.device import device_utils |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 cores under system power management control. This is needed to work around | 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 | 67 a bug in perf which makes it unable to record samples from CPUs that become |
| 68 online when recording is already underway. | 68 online when recording is already underway. |
| 69 | 69 |
| 70 Args: | 70 Args: |
| 71 force_online: True to set all CPUs online, False to return them under | 71 force_online: True to set all CPUs online, False to return them under |
| 72 system power management control. | 72 system power management control. |
| 73 """ | 73 """ |
| 74 def ForceCpuOnline(online_path): | 74 def ForceCpuOnline(online_path): |
| 75 script = 'chmod 644 {0}; echo 1 > {0}; chmod 444 {0}'.format(online_path) | 75 script = 'chmod 644 {0}; echo 1 > {0}; chmod 444 {0}'.format(online_path) |
| 76 self._device.old_interface.RunShellCommandWithSU(script) | 76 self._device.RunShellCommand(script, root=True) |
| 77 return self._device.old_interface.GetFileContents(online_path)[0] == '1' | 77 return self._device.old_interface.GetFileContents(online_path)[0] == '1' |
| 78 | 78 |
| 79 def ResetCpu(online_path): | 79 def ResetCpu(online_path): |
| 80 self._device.old_interface.RunShellCommandWithSU( | 80 self._device.RunShellCommand('chmod 644 %s' % online_path, root=True) |
| 81 'chmod 644 %s' % online_path) | |
| 82 | 81 |
| 83 def WaitFor(condition): | 82 def WaitFor(condition): |
| 84 for _ in range(100): | 83 for _ in range(100): |
| 85 if condition(): | 84 if condition(): |
| 86 return | 85 return |
| 87 time.sleep(0.1) | 86 time.sleep(0.1) |
| 88 raise RuntimeError('Timed out') | 87 raise RuntimeError('Timed out') |
| 89 | 88 |
| 90 cpu_online_files = self._device.old_interface.RunShellCommand( | 89 cpu_online_files = self._device.RunShellCommand( |
| 91 'ls -d /sys/devices/system/cpu/cpu[0-9]*/online') | 90 'ls -d /sys/devices/system/cpu/cpu[0-9]*/online') |
| 92 for online_path in cpu_online_files: | 91 for online_path in cpu_online_files: |
| 93 if force_online: | 92 if force_online: |
| 94 WaitFor(lambda: ForceCpuOnline(online_path)) | 93 WaitFor(lambda: ForceCpuOnline(online_path)) |
| 95 else: | 94 else: |
| 96 ResetCpu(online_path) | 95 ResetCpu(online_path) |
| OLD | NEW |