Ejemplo n.º 1
0
 def __init__(self, adb):
     super(DS2784PowerMonitor, self).__init__()
     self._adb = adb
     self._powermonitor_process_port = None
     android_prebuilt_profiler_helper.InstallOnDevice(adb, 'file_poller')
     self._file_poller_binary = android_prebuilt_profiler_helper.GetDevicePath(
         'file_poller')
 def __init__(self, device, platform_backend):
     super(DS2784PowerMonitor, self).__init__(platform_backend)
     self._device = device
     self._device_battery = battery_utils.BatteryUtils(self._device)
     self._powermonitor_process_port = None
     self._file_poller_binary = android_prebuilt_profiler_helper.GetDevicePath(
         'file_poller')
Ejemplo n.º 3
0
 def __init__(self, pid, output_file, browser_backend, platform_backend):
     self._pid = pid
     self._browser_backend = browser_backend
     self._platform_backend = platform_backend
     self._output_file = output_file
     self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0)
     self._is_android = platform_backend.GetOSName() == 'android'
     cmd_prefix = []
     if self._is_android:
         perf_binary = android_prebuilt_profiler_helper.GetDevicePath(
             'perf')
         cmd_prefix = [
             'adb', '-s',
             browser_backend.adb.device(), 'shell', perf_binary
         ]
         output_file = os.path.join('/sdcard', 'perf_profiles',
                                    os.path.basename(output_file))
         self._device_output_file = output_file
         browser_backend.adb.RunShellCommand(
             'mkdir -p ' + os.path.dirname(self._device_output_file))
     else:
         cmd_prefix = ['perf']
     self._proc = subprocess.Popen(cmd_prefix + [
         'record', '--call-graph', '--pid',
         str(pid), '--output', output_file
     ],
                                   stdout=self._tmp_output_file,
                                   stderr=subprocess.STDOUT)
 def __init__(self, adb, output_path):
   self._adb = adb
   self._output_path = output_path
   self._adb.RunShellCommand('mkdir -p ' +
                             os.path.dirname(self._DEVICE_DUMP_FILE))
   self._proc = subprocess.Popen(
       ['adb', '-s', self._adb.device(),
        'shell', android_prebuilt_profiler_helper.GetDevicePath('tcpdump')] +
        _TCP_DUMP_BASE_OPTS +
        [self._DEVICE_DUMP_FILE])
Ejemplo n.º 5
0
    def PurgeUnpinnedMemory(self):
        """Purges the unpinned ashmem memory for the whole system.

    This can be used to make memory measurements more stable in particular.
    """
        android_prebuilt_profiler_helper.InstallOnDevice(
            self._adb, 'purge_ashmem')
        if self._adb.RunShellCommand(
                android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem'),
                log_result=True):
            return
        raise Exception('Error while purging ashmem.')
Ejemplo n.º 6
0
def PrepareDeviceForPerf(device):
    """Set up a device for running perf.

  Args:
    device: DeviceUtils instance identifying the target device.

  Returns:
    The path to the installed perf binary on the device.
  """
    android_prebuilt_profiler_helper.InstallOnDevice(device, 'perf')
    # Make sure kernel pointers are not hidden.
    device.WriteFile('/proc/sys/kernel/kptr_restrict', '0', as_root=True)
    return android_prebuilt_profiler_helper.GetDevicePath('perf')
 def CollectProfile(self):
   tcpdump_pid = self._adb.ExtractPid('tcpdump')
   if not tcpdump_pid or not tcpdump_pid[0]:
     raise Exception('Unable to find TCPDump. Check your device is rooted '
         'and tcpdump is installed at ' +
         android_prebuilt_profiler_helper.GetDevicePath('tcpdump'))
   self._adb.RunShellCommand('kill -term ' + tcpdump_pid[0])
   self._proc.terminate()
   host_dump = os.path.join(self._output_path,
                            os.path.basename(self._DEVICE_DUMP_FILE))
   self._adb.Adb().Adb().Pull(self._DEVICE_DUMP_FILE, host_dump)
   print 'TCP dump available at: %s ' % host_dump
   print 'Use Wireshark to open it.'
   return host_dump
  def PurgeUnpinnedMemory(self):
    """Purges the unpinned ashmem memory for the whole system.

    This can be used to make memory measurements more stable. Requires root.
    """
    if not self._can_access_protected_file_contents:
      logging.warning('Cannot run purge_ashmem. Requires a rooted device.')
      return

    if not android_prebuilt_profiler_helper.InstallOnDevice(
        self._device, 'purge_ashmem'):
      raise Exception('Error installing purge_ashmem.')
    output = self._device.RunShellCommand(
        android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem'),
        check_return=True)
    for l in output:
      logging.info(l)
    def PurgeUnpinnedMemory(self):
        """Purges the unpinned ashmem memory for the whole system.

    This can be used to make memory measurements more stable. Requires root.
    """
        if not self._can_access_protected_file_contents:
            logging.warning(
                'Cannot run purge_ashmem. Requires a rooted device.')
            return

        if not android_prebuilt_profiler_helper.InstallOnDevice(
                self._device, 'purge_ashmem'):
            raise Exception('Error installing purge_ashmem.')
        (status,
         output) = self._device.old_interface.GetAndroidToolStatusAndOutput(
             android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem'),
             log_result=True)
        if status != 0:
            raise Exception('Error while purging ashmem: ' + '\n'.join(output))
 def __init__(self, device):
     super(DS2784PowerMonitor, self).__init__()
     self._device = device
     self._powermonitor_process_port = None
     self._file_poller_binary = android_prebuilt_profiler_helper.GetDevicePath(
         'file_poller')