import time
from telemetry.core import exceptions
+from telemetry.core.platform import power_monitor
from telemetry.core.platform.profiler import monsoon
-import telemetry.core.platform.power_monitor as power_monitor
def _MonitorPower(device, is_collecting, output):
except EnvironmentError:
self._monsoon = None
- def CanMonitorPowerAsync(self):
+ def CanMonitorPower(self):
return self._monsoon is not None
- def StartMonitoringPowerAsync(self):
+ def StartMonitoringPower(self, browser):
assert not self._powermonitor_process, (
- 'Must call StopMonitoringPowerAsync().')
+ 'Must call StopMonitoringPower().')
self._powermonitor_output_file = tempfile.TemporaryFile()
self._is_collecting = multiprocessing.Event()
self._powermonitor_process = multiprocessing.Process(
self._powermonitor_process.terminate()
raise exceptions.ProfilingException('Failed to start data collection.')
- def StopMonitoringPowerAsync(self):
+ def StopMonitoringPower(self):
assert self._powermonitor_process, (
- 'StartMonitoringPowerAsync() not called.')
+ 'StartMonitoringPower() not called.')
try:
# Tell powermonitor to take an immediate sample and join.
self._is_collecting.clear()
"""Parse the output of of the samples collector process.
Returns:
- Dictionary in the format returned by StopMonitoringPowerAsync().
+ Dictionary in the format returned by StopMonitoringPower().
"""
power_samples = []
total_energy_consumption_mwh = 0
+
result = json.loads(powermonitor_output)
- timedelta_h = result['duration_s'] / len(result['samples']) / 3600
- for (current_a, voltage_v) in result['samples']:
- energy_consumption_mw = current_a * voltage_v * 10**3
- total_energy_consumption_mwh += energy_consumption_mw * timedelta_h
- power_samples.append(energy_consumption_mw)
- # -------- Collect and Process Data -------------
+ if result['samples']:
+ timedelta_h = result['duration_s'] / len(result['samples']) / 3600
+ for (current_a, voltage_v) in result['samples']:
+ energy_consumption_mw = current_a * voltage_v * 10**3
+ total_energy_consumption_mwh += energy_consumption_mw * timedelta_h
+ power_samples.append(energy_consumption_mw)
+
out_dict = {}
- # Raw power usage samples.
out_dict['identifier'] = 'monsoon'
out_dict['power_samples_mw'] = power_samples
out_dict['energy_consumption_mwh'] = total_energy_consumption_mwh