| 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 class ThermalThrottle(object): | 7 from perf import thermal_throttle |
| 8 """Class to detect and track thermal throttling | |
| 9 | 8 |
| 10 Usage: | 9 # TODO(bulach): remove once all references to ThermalThrottle are fixed. |
| 11 Wait for IsThrottled() to be False before running test | 10 class ThermalThrottle(thermal_throttle.ThermalThrottle): |
| 12 After running test call HasBeenThrottled() to find out if the | |
| 13 test run was affected by thermal throttling. | |
| 14 | |
| 15 Currently assumes an OMap device. | |
| 16 """ | |
| 17 def __init__(self, adb): | 11 def __init__(self, adb): |
| 18 self._adb = adb | 12 super(ThermalThrottle, self).__init__(adb) |
| 19 self._throttled = False | |
| 20 | |
| 21 | |
| 22 def HasBeenThrottled(self): | |
| 23 """ True if there has been any throttling since the last call to | |
| 24 HasBeenThrottled or IsThrottled | |
| 25 """ | |
| 26 return self._ReadLog() | |
| 27 | |
| 28 def IsThrottled(self): | |
| 29 """True if currently throttled""" | |
| 30 self._ReadLog() | |
| 31 return self._throttled | |
| 32 | |
| 33 def _ReadLog(self): | |
| 34 has_been_throttled = False | |
| 35 serial_number = self._adb.Adb().GetSerialNumber() | |
| 36 log = self._adb.RunShellCommand('dmesg -c') | |
| 37 degree_symbol = unichr(0x00B0) | |
| 38 for line in log: | |
| 39 if 'omap_thermal_throttle' in line: | |
| 40 if not self._throttled: | |
| 41 logging.warning('>>> Device %s Thermally Throttled', serial_number) | |
| 42 self._throttled = True | |
| 43 has_been_throttled = True | |
| 44 if 'omap_thermal_unthrottle' in line: | |
| 45 if self._throttled: | |
| 46 logging.warning('>>> Device %s Thermally Unthrottled', serial_number) | |
| 47 self._throttled = False | |
| 48 has_been_throttled = True | |
| 49 if 'throttle_delayed_work_fn' in line: | |
| 50 temp = float([s for s in line.split() if s.isdigit()][0]) / 1000.0 | |
| 51 logging.info(u' Device %s Thermally Thottled at %3.1f%sC', | |
| 52 serial_number, temp, degree_symbol) | |
| 53 | |
| 54 if logging.getLogger().isEnabledFor(logging.DEBUG): | |
| 55 # Print temperature of CPU SoC. | |
| 56 omap_temp_file = ('/sys/devices/platform/omap/omap_temp_sensor.0/' | |
| 57 'temperature') | |
| 58 if self._adb.FileExistsOnDevice(omap_temp_file): | |
| 59 tempdata = self._adb.GetFileContents(omap_temp_file) | |
| 60 temp = float(tempdata[0]) / 1000.0 | |
| 61 logging.debug(u'Current OMAP Temperature of %s = %3.1f%sC', | |
| 62 serial_number, temp, degree_symbol) | |
| 63 | |
| 64 # Print temperature of battery, to give a system temperature | |
| 65 dumpsys_log = self._adb.RunShellCommand('dumpsys battery') | |
| 66 for line in dumpsys_log: | |
| 67 if 'temperature' in line: | |
| 68 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', | |
| 70 serial_number, btemp, degree_symbol) | |
| 71 | |
| 72 return has_been_throttled | |
| OLD | NEW |