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 atexit | 5 import atexit |
6 import logging | 6 import logging |
7 | 7 |
8 from pylib import android_commands | 8 from pylib import android_commands |
| 9 from pylib.device import device_errors |
9 from pylib.device import device_utils | 10 from pylib.device import device_utils |
10 | 11 |
| 12 |
11 class PerfControl(object): | 13 class PerfControl(object): |
12 """Provides methods for setting the performance mode of a device.""" | 14 """Provides methods for setting the performance mode of a device.""" |
13 _CPU_PATH = '/sys/devices/system/cpu' | 15 _CPU_PATH = '/sys/devices/system/cpu' |
14 _KERNEL_MAX = '/sys/devices/system/cpu/kernel_max' | 16 _KERNEL_MAX = '/sys/devices/system/cpu/kernel_max' |
15 | 17 |
16 def __init__(self, device): | 18 def __init__(self, device): |
17 # TODO(jbudorick) Remove once telemetry gets switched over. | 19 # TODO(jbudorick) Remove once telemetry gets switched over. |
18 if isinstance(device, android_commands.AndroidCommands): | 20 if isinstance(device, android_commands.AndroidCommands): |
19 device = device_utils.DeviceUtils(device) | 21 device = device_utils.DeviceUtils(device) |
20 self._device = device | 22 self._device = device |
21 # this will raise an AdbCommandFailedError if no CPU files are found | 23 # this will raise an AdbCommandFailedError if no CPU files are found |
22 self._cpu_files = self._device.RunShellCommand( | 24 self._cpu_files = self._device.RunShellCommand( |
23 'ls -d cpu[0-9]*', cwd=self._CPU_PATH, check_return=True, as_root=True) | 25 'ls -d cpu[0-9]*', cwd=self._CPU_PATH, check_return=True, as_root=True) |
24 assert self._cpu_files, 'Failed to detect CPUs.' | 26 assert self._cpu_files, 'Failed to detect CPUs.' |
25 self._cpu_file_list = ' '.join(self._cpu_files) | 27 self._cpu_file_list = ' '.join(self._cpu_files) |
26 logging.info('CPUs found: %s', self._cpu_file_list) | 28 logging.info('CPUs found: %s', self._cpu_file_list) |
27 self._have_mpdecision = self._device.FileExists('/system/bin/mpdecision') | 29 self._have_mpdecision = self._device.FileExists('/system/bin/mpdecision') |
28 | 30 |
29 def SetHighPerfMode(self): | 31 def SetHighPerfMode(self): |
30 """Sets the highest stable performance mode for the device.""" | 32 """Sets the highest stable performance mode for the device.""" |
31 if not self._device.HasRoot(): | 33 try: |
| 34 self._device.EnableRoot() |
| 35 except device_errors.CommandFailedError: |
32 message = 'Need root for performance mode. Results may be NOISY!!' | 36 message = 'Need root for performance mode. Results may be NOISY!!' |
33 logging.warning(message) | 37 logging.warning(message) |
34 # Add an additional warning at exit, such that it's clear that any results | 38 # Add an additional warning at exit, such that it's clear that any results |
35 # may be different/noisy (due to the lack of intended performance mode). | 39 # may be different/noisy (due to the lack of intended performance mode). |
36 atexit.register(logging.warning, message) | 40 atexit.register(logging.warning, message) |
37 return | 41 return |
38 | 42 |
39 product_model = self._device.product_model | 43 product_model = self._device.product_model |
40 # TODO(epenner): Enable on all devices (http://crbug.com/383566) | 44 # TODO(epenner): Enable on all devices (http://crbug.com/383566) |
41 if 'Nexus 4' == product_model: | 45 if 'Nexus 4' == product_model: |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 """ | 152 """ |
149 if self._have_mpdecision: | 153 if self._have_mpdecision: |
150 script = 'stop mpdecision' if force_online else 'start mpdecision' | 154 script = 'stop mpdecision' if force_online else 'start mpdecision' |
151 self._device.RunShellCommand(script, check_return=True, as_root=True) | 155 self._device.RunShellCommand(script, check_return=True, as_root=True) |
152 | 156 |
153 if not self._have_mpdecision and not self._AllCpusAreOnline(): | 157 if not self._have_mpdecision and not self._AllCpusAreOnline(): |
154 logging.warning('Unexpected cpu hot plugging detected.') | 158 logging.warning('Unexpected cpu hot plugging detected.') |
155 | 159 |
156 if force_online: | 160 if force_online: |
157 self._ForEachCpu('echo 1 > "$CPU/online"') | 161 self._ForEachCpu('echo 1 > "$CPU/online"') |
OLD | NEW |