1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
7from telemetry.internal.platform import power_monitor
8
9
10class AndroidPowerMonitorBase(power_monitor.PowerMonitor):
11
12  # Abstract class.
13  # pylint: disable=abstract-method
14
15  def _ParseVoltage(self, millivolts):
16    # Parse voltage information.
17    # If voltage is None, use 4.0 as default.
18    # Otherwise, convert millivolts to volts.
19    if millivolts is None:
20      # Converting at a nominal voltage of 4.0V, as those values are obtained by
21      # a heuristic, and 4.0V is the voltage we set when using a monsoon device.
22      voltage = 4.0
23      logging.warning('Unable to get device voltage. Using %s.', voltage)
24    else:
25      voltage = float(millivolts) / 1000
26      logging.info('Device voltage at %s', voltage)
27      return voltage
28
29  def _LogPowerAnomalies(self, power_data, package):
30    # Log anomalies in power data.
31    if power_data['energy_consumption_mwh'] == 0:
32      logging.warning('Power data is returning 0 for system total usage. %s'
33                      % (power_data))
34      if power_data['application_energy_consumption_mwh'] == 0:
35        logging.warning('Power data is returning 0 usage for %s. %s'
36                        % (package, power_data))
37