Index: build/android/pylib/perf/perf_control.py |
diff --git a/build/android/pylib/perf/perf_control.py b/build/android/pylib/perf/perf_control.py |
index e13c02adf8768d6560b2d8957bdae60c148da0ae..6a636e7f37cb018b6cdd773f9b4618c9bb60da40 100644 |
--- a/build/android/pylib/perf/perf_control.py |
+++ b/build/android/pylib/perf/perf_control.py |
@@ -3,7 +3,6 @@ |
# found in the LICENSE file. |
import logging |
-import time |
from pylib import android_commands |
from pylib.device import device_utils |
@@ -21,28 +20,30 @@ class PerfControl(object): |
if isinstance(device, android_commands.AndroidCommands): |
device = device_utils.DeviceUtils(device) |
self._device = device |
- kernel_max = self._device.old_interface.GetFileContents( |
- PerfControl._KERNEL_MAX, log_result=False) |
- assert kernel_max, 'Unable to find %s' % PerfControl._KERNEL_MAX |
- self._kernel_max = int(kernel_max[0]) |
- logging.info('Maximum CPU index: %d', self._kernel_max) |
+ cpu_files = self._device.RunShellCommand( |
+ 'ls -d /sys/devices/system/cpu/cpu[0-9]*') |
+ self._num_cpu_cores = len(cpu_files) |
+ assert self._num_cpu_cores > 0, 'Failed to detect CPUs.' |
+ logging.info('Number of CPUs: %d', self._num_cpu_cores) |
self._have_mpdecision = self._device.old_interface.FileExistsOnDevice( |
'/system/bin/mpdecision') |
- @property |
- def _NumCpuCores(self): |
- return self._kernel_max + 1 |
- |
def SetHighPerfMode(self): |
# TODO(epenner): Enable on all devices (http://crbug.com/383566) |
if 'Nexus 4' == self._device.old_interface.GetProductModel(): |
self._ForceAllCpusOnline(True) |
+ if not self._AllCpusAreOnline(): |
+ logging.warning('Failed to force CPUs online. Results may be noisy!') |
self._SetScalingGovernorInternal('performance') |
def SetPerfProfilingMode(self): |
"""Sets the highest possible performance mode for the device.""" |
self._ForceAllCpusOnline(True) |
self._SetScalingGovernorInternal('performance') |
+ if not self._AllCpusAreOnline(): |
+ if not self._device.old_interface.IsRootEnabled(): |
+ raise RuntimeError('Need root to force CPUs online.') |
+ raise RuntimeError('Failed to force CPUs online.') |
def SetDefaultPerfMode(self): |
"""Sets the performance mode for the device to its default mode.""" |
@@ -58,7 +59,7 @@ class PerfControl(object): |
self._ForceAllCpusOnline(False) |
def _SetScalingGovernorInternal(self, value): |
- for cpu in range(self._NumCpuCores): |
+ for cpu in range(self._num_cpu_cores): |
scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu |
if self._device.old_interface.FileExistsOnDevice(scaling_governor_file): |
logging.info('Writing scaling governor mode \'%s\' -> %s', |
@@ -67,7 +68,7 @@ class PerfControl(object): |
scaling_governor_file, value) |
def _AllCpusAreOnline(self): |
- for cpu in range(self._NumCpuCores): |
+ for cpu in range(self._num_cpu_cores): |
online_path = PerfControl._CPU_ONLINE_FMT % cpu |
if self._device.old_interface.GetFileContents(online_path)[0] == '0': |
return False |
@@ -97,12 +98,7 @@ class PerfControl(object): |
if not force_online: |
return |
- for cpu in range(self._NumCpuCores): |
+ for cpu in range(self._num_cpu_cores): |
online_path = PerfControl._CPU_ONLINE_FMT % cpu |
self._device.old_interface.SetProtectedFileContents( |
online_path, '1') |
- |
- # Double check all cores stayed online. |
- time.sleep(0.25) |
- if not self._AllCpusAreOnline(): |
- raise RuntimeError('Failed to force CPUs online') |