| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import multiprocessing | 6 import multiprocessing |
| 7 import tempfile | 7 import tempfile |
| 8 import time | 8 import time |
| 9 | 9 |
| 10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 assert not self._powermonitor_process, ( | 66 assert not self._powermonitor_process, ( |
| 67 'Must call StopMonitoringPower().') | 67 'Must call StopMonitoringPower().') |
| 68 super(MonsoonPowerMonitor, self).StartMonitoringPower(browser) | 68 super(MonsoonPowerMonitor, self).StartMonitoringPower(browser) |
| 69 self._powermonitor_output_file = tempfile.TemporaryFile() | 69 self._powermonitor_output_file = tempfile.TemporaryFile() |
| 70 self._is_collecting = multiprocessing.Event() | 70 self._is_collecting = multiprocessing.Event() |
| 71 self._powermonitor_process = multiprocessing.Process( | 71 self._powermonitor_process = multiprocessing.Process( |
| 72 target=_MonitorPower, | 72 target=_MonitorPower, |
| 73 args=(self._monsoon, | 73 args=(self._monsoon, |
| 74 self._is_collecting, | 74 self._is_collecting, |
| 75 self._powermonitor_output_file)) | 75 self._powermonitor_output_file)) |
| 76 # Ensure child is not left behind: parent kills daemonic children on exit. |
| 77 self._powermonitor_process.daemon = True |
| 76 self._powermonitor_process.start() | 78 self._powermonitor_process.start() |
| 77 if not self._is_collecting.wait(timeout=0.5): | 79 if not self._is_collecting.wait(timeout=0.5): |
| 78 self._powermonitor_process.terminate() | 80 self._powermonitor_process.terminate() |
| 79 raise exceptions.ProfilingException('Failed to start data collection.') | 81 raise exceptions.ProfilingException('Failed to start data collection.') |
| 80 | 82 |
| 81 def StopMonitoringPower(self): | 83 def StopMonitoringPower(self): |
| 82 assert self._powermonitor_process, ( | 84 assert self._powermonitor_process, ( |
| 83 'StartMonitoringPower() not called.') | 85 'StartMonitoringPower() not called.') |
| 84 try: | 86 try: |
| 85 cpu_stats = super(MonsoonPowerMonitor, self).StopMonitoringPower() | 87 cpu_stats = super(MonsoonPowerMonitor, self).StopMonitoringPower() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 energy_consumption_mw = current_a * voltage_v * 10**3 | 117 energy_consumption_mw = current_a * voltage_v * 10**3 |
| 116 total_energy_consumption_mwh += energy_consumption_mw * timedelta_h | 118 total_energy_consumption_mwh += energy_consumption_mw * timedelta_h |
| 117 power_samples.append(energy_consumption_mw) | 119 power_samples.append(energy_consumption_mw) |
| 118 | 120 |
| 119 out_dict = {} | 121 out_dict = {} |
| 120 out_dict['identifier'] = 'monsoon' | 122 out_dict['identifier'] = 'monsoon' |
| 121 out_dict['power_samples_mw'] = power_samples | 123 out_dict['power_samples_mw'] = power_samples |
| 122 out_dict['energy_consumption_mwh'] = total_energy_consumption_mwh | 124 out_dict['energy_consumption_mwh'] = total_energy_consumption_mwh |
| 123 | 125 |
| 124 return out_dict | 126 return out_dict |
| OLD | NEW |