Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: build/android/pylib/perf/thermal_throttle.py

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 from pylib import android_commands
7 from pylib.device import device_utils
6 8
7 9
8 class OmapThrottlingDetector(object): 10 class OmapThrottlingDetector(object):
9 """Class to detect and track thermal throttling on an OMAP 4.""" 11 """Class to detect and track thermal throttling on an OMAP 4."""
10 OMAP_TEMP_FILE = ('/sys/devices/platform/omap/omap_temp_sensor.0/' 12 OMAP_TEMP_FILE = ('/sys/devices/platform/omap/omap_temp_sensor.0/'
11 'temperature') 13 'temperature')
12 14
13 @staticmethod 15 @staticmethod
14 def IsSupported(adb): 16 def IsSupported(device):
15 return adb.FileExistsOnDevice(OmapThrottlingDetector.OMAP_TEMP_FILE) 17 return device.old_interface.FileExistsOnDevice(
18 OmapThrottlingDetector.OMAP_TEMP_FILE)
16 19
17 def __init__(self, adb): 20 def __init__(self, device):
18 self._adb = adb 21 self._device = device
19 22
20 @staticmethod 23 @staticmethod
21 def BecameThrottled(log_line): 24 def BecameThrottled(log_line):
22 return 'omap_thermal_throttle' in log_line 25 return 'omap_thermal_throttle' in log_line
23 26
24 @staticmethod 27 @staticmethod
25 def BecameUnthrottled(log_line): 28 def BecameUnthrottled(log_line):
26 return 'omap_thermal_unthrottle' in log_line 29 return 'omap_thermal_unthrottle' in log_line
27 30
28 @staticmethod 31 @staticmethod
29 def GetThrottlingTemperature(log_line): 32 def GetThrottlingTemperature(log_line):
30 if 'throttle_delayed_work_fn' in log_line: 33 if 'throttle_delayed_work_fn' in log_line:
31 return float([s for s in log_line.split() if s.isdigit()][0]) / 1000.0 34 return float([s for s in log_line.split() if s.isdigit()][0]) / 1000.0
32 35
33 def GetCurrentTemperature(self): 36 def GetCurrentTemperature(self):
34 tempdata = self._adb.GetFileContents(OmapThrottlingDetector.OMAP_TEMP_FILE) 37 tempdata = self._device.old_interface.GetFileContents(
38 OmapThrottlingDetector.OMAP_TEMP_FILE)
35 return float(tempdata[0]) / 1000.0 39 return float(tempdata[0]) / 1000.0
36 40
37 41
38 class ExynosThrottlingDetector(object): 42 class ExynosThrottlingDetector(object):
39 """Class to detect and track thermal throttling on an Exynos 5.""" 43 """Class to detect and track thermal throttling on an Exynos 5."""
40 @staticmethod 44 @staticmethod
41 def IsSupported(adb): 45 def IsSupported(device):
42 return adb.FileExistsOnDevice('/sys/bus/exynos5-core') 46 return device.old_interface.FileExistsOnDevice('/sys/bus/exynos5-core')
43 47
44 def __init__(self, adb): 48 def __init__(self, device):
45 pass 49 pass
46 50
47 @staticmethod 51 @staticmethod
48 def BecameThrottled(log_line): 52 def BecameThrottled(log_line):
49 return 'exynos_tmu: Throttling interrupt' in log_line 53 return 'exynos_tmu: Throttling interrupt' in log_line
50 54
51 @staticmethod 55 @staticmethod
52 def BecameUnthrottled(log_line): 56 def BecameUnthrottled(log_line):
53 return 'exynos_thermal_unthrottle: not throttling' in log_line 57 return 'exynos_thermal_unthrottle: not throttling' in log_line
54 58
55 @staticmethod 59 @staticmethod
56 def GetThrottlingTemperature(_log_line): 60 def GetThrottlingTemperature(_log_line):
57 return None 61 return None
58 62
59 @staticmethod 63 @staticmethod
60 def GetCurrentTemperature(): 64 def GetCurrentTemperature():
61 return None 65 return None
62 66
63 67
64 class ThermalThrottle(object): 68 class ThermalThrottle(object):
65 """Class to detect and track thermal throttling. 69 """Class to detect and track thermal throttling.
66 70
67 Usage: 71 Usage:
68 Wait for IsThrottled() to be False before running test 72 Wait for IsThrottled() to be False before running test
69 After running test call HasBeenThrottled() to find out if the 73 After running test call HasBeenThrottled() to find out if the
70 test run was affected by thermal throttling. 74 test run was affected by thermal throttling.
71 """ 75 """
72 76
73 def __init__(self, adb): 77 def __init__(self, device):
74 self._adb = adb 78 # TODO(jbudorick) Remove once telemetry gets switched over.
79 if isinstance(device, android_commands.AndroidCommands):
80 device = device_utils.DeviceUtils(device)
81 self._device = device
75 self._throttled = False 82 self._throttled = False
76 self._detector = None 83 self._detector = None
77 if OmapThrottlingDetector.IsSupported(adb): 84 if OmapThrottlingDetector.IsSupported(device):
78 self._detector = OmapThrottlingDetector(adb) 85 self._detector = OmapThrottlingDetector(device)
79 elif ExynosThrottlingDetector.IsSupported(adb): 86 elif ExynosThrottlingDetector.IsSupported(device):
80 self._detector = ExynosThrottlingDetector(adb) 87 self._detector = ExynosThrottlingDetector(device)
81 88
82 def HasBeenThrottled(self): 89 def HasBeenThrottled(self):
83 """True if there has been any throttling since the last call to 90 """True if there has been any throttling since the last call to
84 HasBeenThrottled or IsThrottled. 91 HasBeenThrottled or IsThrottled.
85 """ 92 """
86 return self._ReadLog() 93 return self._ReadLog()
87 94
88 def IsThrottled(self): 95 def IsThrottled(self):
89 """True if currently throttled.""" 96 """True if currently throttled."""
90 self._ReadLog() 97 self._ReadLog()
91 return self._throttled 98 return self._throttled
92 99
93 def _ReadLog(self): 100 def _ReadLog(self):
94 if not self._detector: 101 if not self._detector:
95 return False 102 return False
96 has_been_throttled = False 103 has_been_throttled = False
97 serial_number = self._adb.Adb().GetSerialNumber() 104 serial_number = self._device.old_interface.GetDevice()
98 log = self._adb.RunShellCommand('dmesg -c') 105 log = self._device.old_interface.RunShellCommand('dmesg -c')
99 degree_symbol = unichr(0x00B0) 106 degree_symbol = unichr(0x00B0)
100 for line in log: 107 for line in log:
101 if self._detector.BecameThrottled(line): 108 if self._detector.BecameThrottled(line):
102 if not self._throttled: 109 if not self._throttled:
103 logging.warning('>>> Device %s thermally throttled', serial_number) 110 logging.warning('>>> Device %s thermally throttled', serial_number)
104 self._throttled = True 111 self._throttled = True
105 has_been_throttled = True 112 has_been_throttled = True
106 elif self._detector.BecameUnthrottled(line): 113 elif self._detector.BecameUnthrottled(line):
107 if self._throttled: 114 if self._throttled:
108 logging.warning('>>> Device %s thermally unthrottled', serial_number) 115 logging.warning('>>> Device %s thermally unthrottled', serial_number)
109 self._throttled = False 116 self._throttled = False
110 has_been_throttled = True 117 has_been_throttled = True
111 temperature = self._detector.GetThrottlingTemperature(line) 118 temperature = self._detector.GetThrottlingTemperature(line)
112 if temperature is not None: 119 if temperature is not None:
113 logging.info(u'Device %s thermally throttled at %3.1f%sC', 120 logging.info(u'Device %s thermally throttled at %3.1f%sC',
114 serial_number, temperature, degree_symbol) 121 serial_number, temperature, degree_symbol)
115 122
116 if logging.getLogger().isEnabledFor(logging.DEBUG): 123 if logging.getLogger().isEnabledFor(logging.DEBUG):
117 # Print current temperature of CPU SoC. 124 # Print current temperature of CPU SoC.
118 temperature = self._detector.GetCurrentTemperature() 125 temperature = self._detector.GetCurrentTemperature()
119 if temperature is not None: 126 if temperature is not None:
120 logging.debug(u'Current SoC temperature of %s = %3.1f%sC', 127 logging.debug(u'Current SoC temperature of %s = %3.1f%sC',
121 serial_number, temperature, degree_symbol) 128 serial_number, temperature, degree_symbol)
122 129
123 # Print temperature of battery, to give a system temperature 130 # Print temperature of battery, to give a system temperature
124 dumpsys_log = self._adb.RunShellCommand('dumpsys battery') 131 dumpsys_log = self._device.old_interface.RunShellCommand(
132 'dumpsys battery')
125 for line in dumpsys_log: 133 for line in dumpsys_log:
126 if 'temperature' in line: 134 if 'temperature' in line:
127 btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0 135 btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0
128 logging.debug(u'Current battery temperature of %s = %3.1f%sC', 136 logging.debug(u'Current battery temperature of %s = %3.1f%sC',
129 serial_number, btemp, degree_symbol) 137 serial_number, btemp, degree_symbol)
130 138
131 return has_been_throttled 139 return has_been_throttled
140
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698