| 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 telemetry.core.platform.power_monitor as power_monitor | 5 from telemetry.core import util |
| 6 from telemetry.core.platform import power_monitor |
| 7 |
| 8 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') |
| 9 try: |
| 10 from pylib.device import device_errors # pylint: disable=F0401 |
| 11 except ImportError: |
| 12 device_errors = None |
| 13 |
| 6 | 14 |
| 7 _TEMPERATURE_FILE = '/sys/class/thermal/thermal_zone0/temp' | 15 _TEMPERATURE_FILE = '/sys/class/thermal/thermal_zone0/temp' |
| 8 | 16 |
| 9 | 17 |
| 10 class AndroidTemperatureMonitor(power_monitor.PowerMonitor): | 18 class AndroidTemperatureMonitor(power_monitor.PowerMonitor): |
| 11 """ | 19 """ |
| 12 Delegates monitoring to another PowerMonitor and adds temperature measurements | 20 Delegates monitoring to another PowerMonitor and adds temperature measurements |
| 13 to overall results. | 21 to overall results. |
| 14 """ | 22 """ |
| 15 def __init__(self, monitor, device): | 23 def __init__(self, monitor, device): |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 for path_element in temperature_path[:-1]: | 58 for path_element in temperature_path[:-1]: |
| 51 if not path_element in temperature_insertion_point: | 59 if not path_element in temperature_insertion_point: |
| 52 temperature_insertion_point[path_element] = {} | 60 temperature_insertion_point[path_element] = {} |
| 53 temperature_insertion_point = temperature_insertion_point[path_element] | 61 temperature_insertion_point = temperature_insertion_point[path_element] |
| 54 assert temperature_path[-1] not in temperature_insertion_point | 62 assert temperature_path[-1] not in temperature_insertion_point |
| 55 temperature_insertion_point[temperature_path[-1]] = average_temperature | 63 temperature_insertion_point[temperature_path[-1]] = average_temperature |
| 56 | 64 |
| 57 return power_data | 65 return power_data |
| 58 | 66 |
| 59 def _GetBoardTemperatureCelsius(self): | 67 def _GetBoardTemperatureCelsius(self): |
| 60 contents = self._device.ReadFile(_TEMPERATURE_FILE) | 68 try: |
| 61 if len(contents) > 0: | 69 contents = self._device.ReadFile(_TEMPERATURE_FILE) |
| 62 return float(contents[0]) | 70 return float(contents) if contents else None |
| 63 return None | 71 except device_errors.CommandFailedError: |
| 72 return None |
| OLD | NEW |