Esempio n. 1
0
    def __init__(self, browser_backend, platform_backend, output_path, state):
        super(PerfProfiler, self).__init__(browser_backend, platform_backend,
                                           output_path, state)
        process_output_file_map = self._GetProcessOutputFileMap()
        self._process_profilers = []
        self._perf_control = None

        perf_binary = perfhost_binary = _InstallPerfHost()
        try:
            if platform_backend.GetOSName() == 'android':
                device = browser_backend.device
                perf_binary = android_profiling_helper.PrepareDeviceForPerf(
                    device)
                self._perf_control = perf_control.PerfControl(device)
                self._perf_control.SetPerfProfilingMode()
            else:
                _PrepareHostForPerf()

            for pid, output_file in process_output_file_map.iteritems():
                if 'zygote' in output_file:
                    continue
                self._process_profilers.append(
                    _SingleProcessPerfProfiler(pid, output_file,
                                               browser_backend,
                                               platform_backend, perf_binary,
                                               perfhost_binary))
        except:
            if self._perf_control:
                self._perf_control.SetDefaultPerfMode()
            raise
Esempio n. 2
0
    def testNexus5HighPerfMode(self):
        # Mock out the device state for PerfControl.
        mock_device = mock.Mock(spec=device_utils.DeviceUtils)
        mock_device.product_model = 'Nexus 5'
        mock_device.adb = mock.Mock(spec=adb_wrapper.AdbWrapper)
        mock_device.ListDirectory.return_value = [
            'cpu%d' % cpu for cpu in xrange(4)
        ] + ['cpufreq']
        mock_device.FileExists.return_value = True
        mock_device.RunShellCommand = mock.Mock(
            side_effect=_ShellCommandHandler)
        pc = perf_control.PerfControl(mock_device)

        # Set up mocks on PerfControl members when it is harder via mocking
        # RunShellCommand().
        # pylint: disable=protected-access
        pc.SetScalingGovernor = mock.Mock()
        pc._ForceAllCpusOnline = mock.Mock()
        pc._SetScalingMaxFreq = mock.Mock()
        pc._SetMaxGpuClock = mock.Mock()

        # Check the actions performed by SetHighPerfMode().
        pc.SetHighPerfMode()
        mock_device.EnableRoot.assert_called_once_with()
        pc._ForceAllCpusOnline.assert_called_once_with(True)
        pc.SetScalingGovernor.assert_called_once_with('performance')
        pc._SetScalingMaxFreq.assert_called_once_with(1190400)
        pc._SetMaxGpuClock.assert_called_once_with(200000000)
Esempio n. 3
0
  def __init__(self, device):
    assert device, (
        'AndroidPlatformBackend can only be initialized from remote device')
    super(AndroidPlatformBackend, self).__init__(device)
    self._device = device_utils.DeviceUtils(device.device_id)
    # Trying to root the device, if possible.
    if not self._device.HasRoot():
      try:
        self._device.EnableRoot()
      except device_errors.CommandFailedError:
        logging.warning('Unable to root %s', str(self._device))
    self._can_elevate_privilege = (
        self._device.HasRoot() or self._device.NeedsSU())
    assert self._can_elevate_privilege, (
        'Android device must have root access to run Telemetry')
    self._battery = battery_utils.BatteryUtils(self._device)
    self._enable_performance_mode = device.enable_performance_mode
    self._surface_stats_collector = None
    self._perf_tests_setup = perf_control.PerfControl(self._device)
    self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
    self._raw_display_frame_rate_measurements = []
    self._device_copy_script = None
    self._power_monitor = (
        android_power_monitor_controller.AndroidPowerMonitorController([
            android_temperature_monitor.AndroidTemperatureMonitor(self._device),
            android_dumpsys_power_monitor.DumpsysPowerMonitor(
                self._battery, self),
            sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True),
            android_fuelgauge_power_monitor.FuelGaugePowerMonitor(
                self._battery),
        ], self._battery))
    self._video_recorder = None
    self._system_ui = None

    _FixPossibleAdbInstability()
Esempio n. 4
0
  def __init__(self, device, require_root):
    assert device, (
        'AndroidPlatformBackend can only be initialized from remote device')
    super(AndroidPlatformBackend, self).__init__(device)
    self._device = device_utils.DeviceUtils(device.device_id)
    self._require_root = require_root
    if self._require_root:
      # Trying to root the device, if possible.
      if not self._device.HasRoot():
        try:
          self._device.EnableRoot()
        except device_errors.CommandFailedError:
          logging.warning('Unable to root %s', str(self._device))
      self._can_elevate_privilege = (
          self._device.HasRoot() or self._device.NeedsSU())
      assert self._can_elevate_privilege, (
          'Android device must have root access to run Telemetry')
      self._enable_performance_mode = device.enable_performance_mode
    else:
      self._enable_performance_mode = False
    self._battery = battery_utils.BatteryUtils(self._device)
    self._surface_stats_collector = None
    self._perf_tests_setup = perf_control.PerfControl(self._device)
    self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
    self._raw_display_frame_rate_measurements = []
    self._device_copy_script = None
    self._system_ui = None

    _FixPossibleAdbInstability()
Esempio n. 5
0
    def __init__(self, device, require_root):
        assert device, (
            'AndroidPlatformBackend can only be initialized from remote device'
        )
        super(AndroidPlatformBackend, self).__init__(device)
        self._device = device_utils.DeviceUtils(device.device_id)
        self._can_elevate_privilege = False
        self._require_root = require_root
        if self._require_root:
            # Trying to root the device, if possible.
            if not self._device.HasRoot():
                try:
                    self._device.EnableRoot()
                except device_errors.CommandFailedError:
                    logging.warning('Unable to root %s', str(self._device))
            self._can_elevate_privilege = (self._device.HasRoot()
                                           or self._device.NeedsSU())
            assert self._can_elevate_privilege, (
                'Android device must have root access to run Telemetry')
        self._battery = battery_utils.BatteryUtils(self._device)
        self._surface_stats_collector = None
        self._perf_tests_setup = perf_control.PerfControl(self._device)
        self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
        self._raw_display_frame_rate_measurements = []
        self._device_copy_script = None
        self._system_ui = None
        self._device_host_clock_offset = None
        self._video_recorder = None

        # TODO(https://crbug.com/1026296): Remove this once --chromium-output-dir
        # has a default value we can use.
        self._build_dir = util.GetUsedBuildDirectory()

        _FixPossibleAdbInstability()
Esempio n. 6
0
    def __init__(self, device, finder_options):
        assert device, (
            'AndroidPlatformBackend can only be initialized from remote device'
        )
        super(AndroidPlatformBackend, self).__init__(device)
        self._device = device_utils.DeviceUtils(device.device_id)
        installed_prebuilt_tools = _SetupPrebuiltTools(self._device)
        if not installed_prebuilt_tools:
            logging.error(
                '%s detected, however prebuilt android tools could not '
                'be used. To run on Android you must build them first:\n'
                '  $ ninja -C out/Release android_tools' % device.name)
            raise exceptions.PlatformError()
        # Trying to root the device, if possible.
        if not self._device.HasRoot():
            try:
                self._device.EnableRoot()
            except device_errors.CommandFailedError:
                logging.warning('Unable to root %s', str(self._device))
        self._battery = battery_utils.BatteryUtils(self._device)
        self._enable_performance_mode = device.enable_performance_mode
        self._surface_stats_collector = None
        self._perf_tests_setup = perf_control.PerfControl(self._device)
        self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device)
        self._raw_display_frame_rate_measurements = []
        try:
            self._can_access_protected_file_contents = (self._device.HasRoot()
                                                        or
                                                        self._device.NeedsSU())
        except Exception:
            logging.exception('New exception caused by DeviceUtils conversion')
            raise
        self._device_copy_script = None
        self._power_monitor = (
            android_power_monitor_controller.AndroidPowerMonitorController([
                android_temperature_monitor.AndroidTemperatureMonitor(
                    self._device),
                monsoon_power_monitor.MonsoonPowerMonitor(self._device, self),
                android_dumpsys_power_monitor.DumpsysPowerMonitor(
                    self._battery, self),
                sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True),
                android_fuelgauge_power_monitor.FuelGaugePowerMonitor(
                    self._battery, self),
            ], self._battery))
        self._video_recorder = None
        self._installed_applications = None

        self._wpr_ca_cert_path = None
        self._device_cert_util = None
        self._is_test_ca_installed = False

        self._use_rndis_forwarder = (
            finder_options.android_rndis
            or finder_options.browser_options.netsim
            or platform.GetHostPlatform().GetOSName() != 'linux')

        _FixPossibleAdbInstability()
 def testHighPerfMode(self):
     perf = perf_control.PerfControl(self._device)
     try:
         perf.SetPerfProfilingMode()
         cpu_info = perf.GetCpuInfo()
         self.assertEquals(len(perf._cpu_files), len(cpu_info))
         for _, online, governor in cpu_info:
             self.assertTrue(online)
             self.assertEquals('performance', governor)
     finally:
         perf.SetDefaultPerfMode()
Esempio n. 8
0
    def __init__(self, device):
        """CpuTemperature constructor.

      Args:
        device: A DeviceUtils instance.
      Raises:
        TypeError: If it is not passed a DeviceUtils instance.
    """
        if not isinstance(device, device_utils.DeviceUtils):
            raise TypeError('Must be initialized with DeviceUtils object.')
        self._device = device
        self._perf_control = perf_control.PerfControl(self._device)
        self._device_info = None
Esempio n. 9
0
    def __init__(self, device, perf_binary, categories):
        self._device = device
        self._output_file = device_temp_file.DeviceTempFile(
            self._device.adb, prefix='perf_output')
        self._log_file = tempfile.TemporaryFile()

        # TODO(jbudorick) Look at providing a way to unhandroll this once the
        #                 adb rewrite has fully landed.
        device_param = (['-s', str(self._device)] if str(self._device) else [])
        cmd = ['adb'] + device_param + \
              ['shell', perf_binary, 'record',
               '--output', self._output_file.name] + _PERF_OPTIONS
        if categories:
            cmd += ['--event', ','.join(categories)]
        self._perf_control = perf_control.PerfControl(self._device)
        self._perf_control.SetPerfProfilingMode()
        self._perf_process = subprocess.Popen(cmd,
                                              stdout=self._log_file,
                                              stderr=subprocess.STDOUT)
Esempio n. 10
0
  def testNexus5XDefaultPerfMode(self):
    # Mock out the device state for PerfControl.
    cpu_list = ['cpu%d' % cpu for cpu in xrange(6)]
    mock_device = mock.Mock(spec=device_utils.DeviceUtils)
    mock_device.product_model = 'Nexus 5X'
    mock_device.adb = mock.Mock(spec=adb_wrapper.AdbWrapper)
    mock_device.ListDirectory.return_value = cpu_list + ['cpufreq']
    mock_device.FileExists.return_value = True
    mock_device.RunShellCommand = mock.Mock(side_effect=_ShellCommandHandler)
    pc = perf_control.PerfControl(mock_device)
    self._MockOutLowLevelPerfControlMethods(pc)

    # Verify.
    # pylint: disable=protected-access
    # pylint: disable=no-member
    pc.SetDefaultPerfMode()
    pc.SetScalingGovernor.assert_called_once_with('ondemand')
    pc._SetScalingMaxFreqForCpus.assert_any_call(1440000, 'cpu0 cpu1 cpu2 cpu3')
    pc._SetScalingMaxFreqForCpus.assert_any_call(1824000, 'cpu4 cpu5')
    pc._SetMaxGpuClock.assert_called_once_with(600000000)
    pc._ForceAllCpusOnline.assert_called_once_with(False)
Esempio n. 11
0
  def testNexus5XHighPerfMode(self):
    # Mock out the device state for PerfControl.
    cpu_list = ['cpu%d' % cpu for cpu in xrange(6)]
    mock_device = mock.Mock(spec=device_utils.DeviceUtils)
    mock_device.product_model = 'Nexus 5X'
    mock_device.adb = mock.Mock(spec=adb_wrapper.AdbWrapper)
    mock_device.ListDirectory.return_value = cpu_list + ['cpufreq']
    mock_device.FileExists.return_value = True
    mock_device.RunShellCommand = mock.Mock(side_effect=_ShellCommandHandler)
    pc = perf_control.PerfControl(mock_device)
    self._MockOutLowLevelPerfControlMethods(pc)

    # Verify.
    # pylint: disable=protected-access
    # pylint: disable=no-member
    pc.SetHighPerfMode()
    mock_device.EnableRoot.assert_called_once_with()
    pc._ForceAllCpusOnline.assert_called_once_with(True)
    pc.SetScalingGovernor.assert_called_once_with('performance')
    pc._SetScalingMaxFreqForCpus.assert_called_once_with(
        1248000, ' '.join(cpu_list))
    pc._SetMaxGpuClock.assert_called_once_with(300000000)
Esempio n. 12
0
def GetScalingGovernor(device, _args):
  p = perf_control.PerfControl(device)
  for cpu, governor in p.GetScalingGovernor():
    print '%s %s: %s' % (str(device), cpu, governor)
Esempio n. 13
0
 def _setup_performance(self):
     # Disable CPU scaling and drop ram cache to reduce noise in tests
     perf_control.PerfControl(self._device).SetPerfProfilingMode()
Esempio n. 14
0
 def _teardown_performance(self):
     perf_control.PerfControl(self._device).SetDefaultPerfMode()
Esempio n. 15
0
 def PostExecution(self):
     perf = perf_control.PerfControl(self.device)
     perf.SetDefaultPerfMode()
     self.device.RunShellCommand(["rm", "-rf", AndroidPlatform.DEVICE_DIR])
Esempio n. 16
0
 def set_default_perf_mode(self):
   """Set device into default performance mode."""
   perf = perf_control.PerfControl(self.device)
   perf.SetDefaultPerfMode()
Esempio n. 17
0
 def set_high_perf_mode(self):
   """Set device into high performance mode."""
   perf = perf_control.PerfControl(self.device)
   perf.SetHighPerfMode()
Esempio n. 18
0
import pprint
import sys

if __name__ == '__main__':
  sys.path.append(
      os.path.abspath(os.path.join(os.path.dirname(__file__),
                                   '..', '..', '..')))

from devil import devil_env
from devil.android import device_utils
from devil.android.perf import perf_control
from devil.utils import run_tests_helper


def SetScalingGovernor(presentation.device, args):
  p = perf_control.PerfControl(presentation.device)
  p.SetScalingGovernor(args.governor)


def GetScalingGovernor(presentation.device, _args):
  p = perf_control.PerfControl(presentation.device)
  for cpu, governor in p.GetScalingGovernor():
    print '%s %s: %s' % (str(presentation.device), cpu, governor)


def ListAvailableGovernors(presentation.device, _args):
  p = perf_control.PerfControl(presentation.device)
  for cpu, governors in p.ListAvailableGovernors():
    print '%s %s: %s' % (str(presentation.device), cpu, pprint.pformat(governors))

Esempio n. 19
0
  def PreExecution(self):
    perf = perf_control.PerfControl(self.device)
    perf.SetHighPerfMode()

    # Remember what we have already pushed to the device.
    self.pushed = set()
Esempio n. 20
0
def SetScalingGovernor(device, args):
  p = perf_control.PerfControl(device)
  p.SetScalingGovernor(args.governor)
Esempio n. 21
0
 def PostExecution(self):
   perf = perf_control.PerfControl(self.device)
   perf.SetDefaultPerfMode()
   self.device.RemovePath(
       AndroidPlatform.DEVICE_DIR, force=True, recursive=True)
Esempio n. 22
0
def ListAvailableGovernors(device, _args):
  p = perf_control.PerfControl(device)
  for cpu, governors in p.ListAvailableGovernors():
    print '%s %s: %s' % (str(device), cpu, pprint.pformat(governors))