Esempio n. 1
0
 def __init__(self, device, output_path):
     self._device = device
     self._output_path = output_path
     self._device.RunShellCommand('mkdir -p ' +
                                  os.path.dirname(self._DEVICE_DUMP_FILE))
     self._proc = subprocess.Popen([
         'adb', '-s',
         self._device.adb.GetDeviceSerial(), 'shell',
         android_prebuilt_profiler_helper.GetDevicePath('tcpdump')
     ] + _TCP_DUMP_BASE_OPTS + [self._DEVICE_DUMP_FILE])
Esempio n. 2
0
  def SetGraphicsMemoryTrackingEnabled(self, enabled):
    if not enabled:
      self.KillApplication('memtrack_helper')
      return

    if not android_prebuilt_profiler_helper.InstallOnDevice(
        self._device, 'memtrack_helper'):
      raise Exception('Error installing memtrack_helper.')
    self._device.RunShellCommand([
      android_prebuilt_profiler_helper.GetDevicePath('memtrack_helper'),
      '-d'], as_root=True, check_return=True)
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')
Esempio n. 4
0
  def SetGraphicsMemoryTrackingEnabled(self, enabled):
    if not enabled:
      self.KillApplication('memtrack_helper')
      return

    if not android_prebuilt_profiler_helper.InstallOnDevice(
        self._device, 'memtrack_helper'):
      raise Exception('Error installing memtrack_helper.')
    try:
      cmd = android_prebuilt_profiler_helper.GetDevicePath('memtrack_helper')
      cmd += ' -d'
      self._device.RunShellCommand(cmd, as_root=True, check_return=True)
    except Exception:
      logging.exception('New exception caused by DeviceUtils conversion')
      raise
Esempio 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. Requires root.
    """
    if not self._can_elevate_privilege:
      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')])
    for l in output:
      logging.info(l)
Esempio n. 6
0
 def CollectProfile(self):
   tcpdump_pid = self._device.GetPids('tcpdump')
   if not tcpdump_pid or not 'tcpdump' in tcpdump_pid:
     raise Exception('Unable to find TCPDump. Check your device is rooted '
         'and tcpdump is installed at ' +
         android_prebuilt_profiler_helper.GetDevicePath('tcpdump'))
   tcpdump_pid = int(tcpdump_pid['tcpdump'])
   self._device.RunShellCommand('kill -term ' + tcpdump_pid)
   self._proc.terminate()
   host_dump = os.path.join(self._output_path,
                            os.path.basename(self._DEVICE_DUMP_FILE))
   try:
     self._device.PullFile(self._DEVICE_DUMP_FILE, host_dump)
   except:
     logging.exception('New exception caused by DeviceUtils conversion')
     raise
   print 'TCP dump available at: %s ' % host_dump
   print 'Use Wireshark to open it.'
   return host_dump
Esempio n. 7
0
 def CollectProfile(self):
   tcpdump_pid = self._device.GetPids('tcpdump')
   if not tcpdump_pid or not 'tcpdump' in tcpdump_pid:
     raise Exception('Unable to find TCPDump. Check your device is rooted '
         'and tcpdump is installed at ' +
         android_prebuilt_profiler_helper.GetDevicePath('tcpdump'))
   if len(tcpdump_pid['tcpdump']) > 1:
     raise Exception(
         'At most one instance of process tcpdump expected but found pids: '
         '%s' % tcpdump_pid)
   tcpdump_pid = int(tcpdump_pid['tcpdump'][0])
   self._device.RunShellCommand('kill -term ' + tcpdump_pid)
   self._proc.terminate()
   host_dump = os.path.join(self._output_path,
                            os.path.basename(self._DEVICE_DUMP_FILE))
   self._device.PullFile(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.')
    try:
      output = self._device.RunShellCommand(
          android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem'))
    except:
      logging.exception('New exception caused by DeviceUtils conversion')
      raise
    for l in output:
      logging.info(l)
class _TCPDumpProfilerAndroid(object):
  """An internal class to collect TCP dumps on android.

  This profiler uses pre-built binaries from AOSP.
  See more details in prebuilt/android/README.txt.
  """

  _DEVICE_DUMP_FILE = '/sdcard/tcpdump_profiles/capture.pcap'

  def __init__(self, presentation.device, output_path):
    self._device = presentation.device
    self._output_path = output_path
    self._device.RunShellCommand(
        ['mkdir', '-p', os.path.dirname(self._DEVICE_DUMP_FILE)],
        check_return=True)
    self._proc = subprocess.Popen(
        [self._device.adb.GetAdbPath(),
         '-s', self._device.adb.GetDeviceSerial(),
         'shell', android_prebuilt_profiler_helper.GetDevicePath('tcpdump')] +
         _TCP_DUMP_BASE_OPTS +
         [self._DEVICE_DUMP_FILE])
Esempio n. 10
0
  return output_kallsyms


def PrepareDeviceForPerf(presentation.device):
  """Set up a presentation.device for running perf.

  Args:
    presentation.device: DeviceUtils instance identifying the target presentation.device.

  Returns:
    The path to the installed perf binary on the presentation.device.
  """
  android_prebuilt_profiler_helper.InstallOnDevice(presentation.device, 'perf')
  # Make sure kernel pointers are not hidden.
  presentation.device.WriteFile('/proc/sys/kernel/kptr_restrict', '0', as_root=True)
  return android_prebuilt_profiler_helper.GetDevicePath('perf')


def GetToolchainBinaryPath(library_file, binary_name):
  """Return the path to an Android toolchain binary on the host.

  Args:
    library_file: ELF library which is used to identify the used ABI,
        architecture and toolchain.
    binary_name: Binary to search for, e.g., 'objdump'
  Returns:
    Full path to binary or None if the binary was not found.
  """
  # Mapping from ELF machine identifiers to GNU toolchain names.
  toolchain_configs = {
    'x86': 'i686-linux-android',