| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 logging | 5 import logging |
| 6 | 6 |
| 7 |
| 7 class ThermalThrottle(object): | 8 class ThermalThrottle(object): |
| 8 """Class to detect and track thermal throttling | 9 """Class to detect and track thermal throttling. |
| 9 | 10 |
| 10 Usage: | 11 Usage: |
| 11 Wait for IsThrottled() to be False before running test | 12 Wait for IsThrottled() to be False before running test |
| 12 After running test call HasBeenThrottled() to find out if the | 13 After running test call HasBeenThrottled() to find out if the |
| 13 test run was affected by thermal throttling. | 14 test run was affected by thermal throttling. |
| 14 | 15 |
| 15 Currently assumes an OMap device. | 16 Currently assumes an OMap device. |
| 16 """ | 17 """ |
| 18 |
| 17 def __init__(self, adb): | 19 def __init__(self, adb): |
| 18 self._adb = adb | 20 self._adb = adb |
| 19 self._throttled = False | 21 self._throttled = False |
| 20 | 22 |
| 21 | 23 |
| 22 def HasBeenThrottled(self): | 24 def HasBeenThrottled(self): |
| 23 """ True if there has been any throttling since the last call to | 25 """True if there has been any throttling since the last call to |
| 24 HasBeenThrottled or IsThrottled | 26 HasBeenThrottled or IsThrottled. |
| 25 """ | 27 """ |
| 26 return self._ReadLog() | 28 return self._ReadLog() |
| 27 | 29 |
| 28 def IsThrottled(self): | 30 def IsThrottled(self): |
| 29 """True if currently throttled""" | 31 """True if currently throttled.""" |
| 30 self._ReadLog() | 32 self._ReadLog() |
| 31 return self._throttled | 33 return self._throttled |
| 32 | 34 |
| 33 def _ReadLog(self): | 35 def _ReadLog(self): |
| 34 has_been_throttled = False | 36 has_been_throttled = False |
| 35 serial_number = self._adb.Adb().GetSerialNumber() | 37 serial_number = self._adb.Adb().GetSerialNumber() |
| 36 log = self._adb.RunShellCommand('dmesg -c') | 38 log = self._adb.RunShellCommand('dmesg -c') |
| 37 degree_symbol = unichr(0x00B0) | 39 degree_symbol = unichr(0x00B0) |
| 38 for line in log: | 40 for line in log: |
| 39 if 'omap_thermal_throttle' in line: | 41 if 'omap_thermal_throttle' in line: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 # Print temperature of battery, to give a system temperature | 66 # Print temperature of battery, to give a system temperature |
| 65 dumpsys_log = self._adb.RunShellCommand('dumpsys battery') | 67 dumpsys_log = self._adb.RunShellCommand('dumpsys battery') |
| 66 for line in dumpsys_log: | 68 for line in dumpsys_log: |
| 67 if 'temperature' in line: | 69 if 'temperature' in line: |
| 68 btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0 | 70 btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0 |
| 69 logging.debug(u'Current battery temperature of %s = %3.1f%sC', | 71 logging.debug(u'Current battery temperature of %s = %3.1f%sC', |
| 70 serial_number, btemp, degree_symbol) | 72 serial_number, btemp, degree_symbol) |
| 71 | 73 |
| 72 return has_been_throttled | 74 return has_been_throttled |
| OLD | NEW |