def is_supported(cls, browser_type): try: monsoon.Monsoon(wait=False) except EnvironmentError: return False else: return True
def __init__(self, _, platform_backend): super(MonsoonPowerMonitor, self).__init__(platform_backend) 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
def GetDeviceSerials(blacklist): """Return the list of device serials of healthy devices. If a preferred device has been set with ANDROID_SERIAL, it will be first in the returned list. The arguments specify what devices to include in the list. """ try: device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) # Sometimes stray adb processes can interfere with using adb. except device_errors.AdbCommandFailedError: _KillStrayADBProcesses() device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) # 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... """) py_utils.WaitFor(_ListSerialsOfHealthyOnlineDevices(blacklist), 600) device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) except IOError: return [] preferred_device = os.environ.get('ANDROID_SERIAL') if preferred_device in device_serials: logging.warn('ANDROID_SERIAL is defined. Put %s in the first of the' 'discovered devices list.' % preferred_device) device_serials.remove(preferred_device) device_serials.insert(0, preferred_device) return device_serials
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)