Example #1
0
    def GetAllConnectedDevices(cls):
        device_serials = adb_commands.GetAttachedDevices()
        # The monsoon provides power for the device, so for devices with no
        # real battery, we need to turn them on after the monsoon enables voltage
        # output to the device.
        if not device_serials:
            try:
                m = monsoon.Monsoon(wait=False)
                m.SetUsbPassthrough(1)
                m.SetVoltage(3.8)
                m.SetMaxCurrent(8)
                logging.warn("""
Monsoon power monitor detected, but no Android devices.

The Monsoon's power output has been enabled. Please now ensure that:

  1. The Monsoon's front and back USB are connected to the host.
  2. The device is connected to the Monsoon's main and USB channels.
  3. The device is turned on.

Waiting for device...
""")
                util.WaitFor(adb_commands.GetAttachedDevices, 600)
                device_serials = adb_commands.GetAttachedDevices()
            except IOError:
                return []
        return [cls(s) for s in device_serials]
 def is_supported(cls, browser_type):
   try:
     monsoon.Monsoon(wait=False)
   except EnvironmentError:
     return False
   else:
     return True
Example #3
0
 def __init__(self):
     super(MonsoonPowerMonitor, self).__init__()
     self._powermonitor_process = None
     self._powermonitor_output_file = None
     self._is_collecting = None
     self._monsoon = None
     try:
         self._monsoon = monsoon.Monsoon(wait=False)
         # Nominal Li-ion voltage is 3.7V, but it puts out 4.2V at max capacity.
         # Use 4.0V to simulate a "~80%" charged battery. Google "li-ion voltage
         # curve". This is true only for a single cell. (Most smartphones, some
         # tablets.)
         self._monsoon.SetVoltage(4.0)
     except EnvironmentError:
         self._monsoon = None
Example #4
0
def _CollectData(output_path, is_collecting):
    mon = monsoon.Monsoon(wait=False)
    # Note: Telemetry requires the device to be connected by USB, but that
    # puts it in charging mode. This increases the power consumption.
    mon.SetUsbPassthrough(1)
    # Nominal Li-ion voltage is 3.7V, but it puts out 4.2V at max capacity. Use
    # 4.0V to simulate a "~80%" charged battery. Google "li-ion voltage curve".
    # This is true only for a single cell. (Most smartphones, some tablets.)
    mon.SetVoltage(4.0)

    samples = []
    try:
        mon.StartDataCollection()
        # Do one CollectData() to make the Monsoon set up, which takes about
        # 0.3 seconds, and only signal that we've started after that.
        mon.CollectData()
        is_collecting.set()
        while is_collecting.is_set():
            samples += mon.CollectData()
    finally:
        mon.StopDataCollection()

    # Add x-axis labels.
    plot_data = [(i / 5000., sample.amps * sample.volts)
                 for i, sample in enumerate(samples)]

    # Print data in csv.
    with open(output_path, 'w') as output_file:
        output_writer = csv.writer(output_file)
        output_writer.writerows(plot_data)
        output_file.flush()

    power_samples = [s.amps * s.volts for s in samples]

    print 'Monsoon profile power readings in watts:'
    print('  Total    = %f' %
          statistics.TrapezoidalRule(power_samples, 1 / 5000.))
    print('  Average  = %f' % statistics.ArithmeticMean(power_samples) +
          '+-%f' % statistics.StandardDeviation(power_samples))
    print('  Peak     = %f' % max(power_samples))
    print('  Duration = %f' % (len(power_samples) / 5000.))

    print 'To view the Monsoon profile, run:'
    print(
        '  echo "set datafile separator \',\'; plot \'%s\' with lines" | '
        'gnuplot --persist' % output_path)
Example #5
0
def FindAllAvailableBrowsers(finder_options, logging=real_logging):
  """Finds all the desktop browsers available on this machine."""
  if not CanFindAvailableBrowsers(logging=logging):
    logging.info('No adb command found. ' +
                 'Will not try searching for Android browsers.')
    return []

  def _GetDevices():
    if finder_options.android_device:
      return [finder_options.android_device]
    else:
      return adb_commands.GetAttachedDevices()

  devices = _GetDevices()

  if not devices:
    try:
      m = monsoon.Monsoon(wait=False)
      m.SetUsbPassthrough(1)
      m.SetVoltage(3.8)
      m.SetMaxCurrent(8)
      logging.warn("""
Monsoon power monitor detected, but no Android devices.

The Monsoon's power output has been enabled. Please now ensure that:

  1. The Monsoon's front and back USB are connected to the host.
  2. The Device is connected to the Monsoon's main and USB channels.
  3. The Device is turned on.

Waiting for device...
""")
      util.WaitFor(_GetDevices, 600)
      devices = _GetDevices()
      if not devices:
        raise IOError()
    except IOError:
      logging.info('No android devices found.')
      return []

  if len(devices) > 1:
    logging.warn(
        'Multiple devices attached. Please specify one of the following:\n' +
        '\n'.join(['  --device=%s' % d for d in devices]))
    return []

  device = devices[0]

  adb = adb_commands.AdbCommands(device=device)
  # Trying to root the device, if possible.
  if not adb.IsRootEnabled():
    # Ignore result.
    adb.EnableAdbRoot()

  if psutil:
    # Host side workaround for crbug.com/268450 (adb instability).
    # The adb server has a race which is mitigated by binding to a single core.
    for proc in psutil.process_iter():
      try:
        if 'adb' in proc.name:
          if 'cpu_affinity' in dir(proc):
            proc.cpu_affinity([0])      # New versions of psutil.
          elif 'set_cpu_affinity' in dir(proc):
            proc.set_cpu_affinity([0])  # Older versions.
          else:
            logging.warn(
                'Cannot set CPU affinity due to stale psutil version: %s',
                '.'.join(str(x) for x in psutil.version_info))
      except (psutil.NoSuchProcess, psutil.AccessDenied):
        logging.warn('Failed to set adb process CPU affinity')

  if not os.environ.get('BUILDBOT_BUILDERNAME'):
    # Killing adbd before running tests has proven to make them less likely to
    # flake out during the test. We skip this if Telemetry is running under a
    # buildbot because build/android/test_runner.py wrapper already took care
    # of it before starting the shards.
    adb.RestartAdbdOnDevice()

  packages = adb.RunShellCommand('pm list packages')
  possible_browsers = []

  for name, package_info in CHROME_PACKAGE_NAMES.iteritems():
    [package, backend_settings, local_apk] = package_info
    b = PossibleAndroidBrowser(
        name,
        finder_options,
        backend_settings(adb, package),
        local_apk)

    if 'package:' + package in packages or b.HaveLocalAPK():
      possible_browsers.append(b)

  if possible_browsers:
    installed_prebuilt_tools = adb_commands.SetupPrebuiltTools(adb)
    if not installed_prebuilt_tools:
      logging.error(
          'Android device 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')
      return []

  return possible_browsers