Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / power_monitor / monsoon_power_monitor.py
index a1e3629..89420fb 100644 (file)
@@ -8,8 +8,8 @@ import tempfile
 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):
@@ -59,12 +59,12 @@ class MonsoonPowerMonitor(power_monitor.PowerMonitor):
     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(
@@ -77,9 +77,9 @@ class MonsoonPowerMonitor(power_monitor.PowerMonitor):
       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()
@@ -99,19 +99,20 @@ class MonsoonPowerMonitor(power_monitor.PowerMonitor):
     """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