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

Side by Side Diff: appengine/swarming/swarming_bot/api/platforms/osx.py

Issue 2993523002: swarming: round OSX temperature readings to 2 digits, trim sensor readings (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """OSX specific utility functions.""" 5 """OSX specific utility functions."""
6 6
7 import cgi 7 import cgi
8 import ctypes 8 import ctypes
9 import logging 9 import logging
10 import os 10 import os
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 ] 112 ]
113 113
114 114
115 # http://bxr.su/OpenBSD/sys/dev/isa/asmc.c is a great list of sensors. 115 # http://bxr.su/OpenBSD/sys/dev/isa/asmc.c is a great list of sensors.
116 # 116 #
117 # The following other sensor were found on a MBP 2012 via brute forcing but 117 # The following other sensor were found on a MBP 2012 via brute forcing but
118 # their signification is unknown: 118 # their signification is unknown:
119 # TC0E, TC0F, TH0A, TH0B, TH0V, TP0P, TS0D, TS0P 119 # TC0E, TC0F, TH0A, TH0B, TH0V, TP0P, TS0D, TS0P
120 _sensor_names = { 120 _sensor_names = {
121 'TA0P': u'ambient', # 'hdd bay 1', 121 'TA0P': u'ambient', # 'hdd bay 1',
122 'TA0S': u'pci slot 1 pos 1', 122 #'TA0S': u'pci slot 1 pos 1',
123 'TA1S': u'pci slot 1 pos 2', 123 #'TA1S': u'pci slot 1 pos 2',
124 'TA3S': u'pci slot 2 pos 2', 124 #'TA3S': u'pci slot 2 pos 2',
125 'TB0T': u'enclosure bottom', 125 'TB0T': u'enclosure bottom',
126 'TB2T': u'enclosure bottom 3', 126 #'TB2T': u'enclosure bottom 3',
127 'TC0D': u'cpu0 die core', 127 #'TC0D': u'cpu0 die core',
128 'TC0P': u'cpu0 proximity', 128 'TC0P': u'cpu0', # 'cpu0 proximity'
129 'TC1D': u'cpu1', 129 #'TC1D': u'cpu1',
130 'TCAH': u'cpu0', 130 #'TCAH': u'cpu0',
131 'TCDH': u'cpu3', 131 #'TCDH': u'cpu3',
132 'TG0D': u'gpu0 diode', 132 'TG0D': u'gpu0 diode',
133 'TG0P': u'gpu0 proximity', 133 'TG0P': u'gpu0 proximity',
134 'TG1H': u'gpu heatsink 2', 134 #'TG1H': u'gpu heatsink 2',
135 'TH0P': u'hdd bay 1', 135 #'TH0P': u'hdd bay 1',
136 'TH2P': u'hdd bay 3', 136 #'TH2P': u'hdd bay 3',
137 'TL0P': u'lcd proximity', 137 #'TL0P': u'lcd proximity',
138 'TM0P': u'mem bank a1', 138 #'TM0P': u'mem bank a1',
139 'TM1P': u'mem bank a2', 139 #'TM1P': u'mem bank a2',
140 'TM2P': u'mem bank a3', 140 #'TM2P': u'mem bank a3',
141 'TM3P': u'mem bank a4', 141 #'TM3P': u'mem bank a4',
142 'TM4P': u'mem bank a5', 142 #'TM4P': u'mem bank a5',
143 'TM5P': u'mem bank a6', 143 #'TM5P': u'mem bank a6',
144 'TM6P': u'mem bank a7', 144 #'TM6P': u'mem bank a7',
145 'TM7P': u'mem bank a8', 145 #'TM7P': u'mem bank a8',
146 'TM8P': u'mem bank b1', 146 #'TM8P': u'mem bank b1',
147 'TM9P': u'mem bank b2', 147 #'TM9P': u'mem bank b2',
148 'TMA1': u'ram a1', 148 #'TMA1': u'ram a1',
149 'TMA3': u'ram a3', 149 #'TMA3': u'ram a3',
150 'TMAP': u'mem bank b3', 150 #'TMAP': u'mem bank b3',
151 'TMB1': u'ram b1', 151 #'TMB1': u'ram b1',
152 'TMB3': u'ram b3', 152 #'TMB3': u'ram b3',
153 'TMBP': u'mem bank b4', 153 #'TMBP': u'mem bank b4',
154 'TMCP': u'mem bank b5', 154 #'TMCP': u'mem bank b5',
155 'TMDP': u'mem bank b6', 155 #'TMDP': u'mem bank b6',
156 'TMEP': u'mem bank b7', 156 #'TMEP': u'mem bank b7',
157 'TMFP': u'mem bank b8', 157 #'TMFP': u'mem bank b8',
158 'TN0D': u'northbridge die core', 158 #'TN0D': u'northbridge die core',
159 'TN0P': u'northbridge proximity', 159 #'TN0P': u'northbridge proximity',
160 'TO0P': u'optical drive', 160 #'TO0P': u'optical drive',
161 'TW0P': u'wireless airport card', 161 #'TW0P': u'wireless airport card',
162 'Th0H': u'main heatsink a', 162 #'Th0H': u'main heatsink a',
163 'Th2H': u'main heatsink c', 163 #'Th2H': u'main heatsink c',
164 'Tm0P': u'memory controller', 164 #'Tm0P': u'memory controller',
165 'Tp0C': u'power supply 1', 165 'Tp0C': u'power supply C',
166 'Tp1C': u'power supply 2', 166 #'Tp1C': u'power supply 2',
167 'Tp2P': u'power supply 3', 167 #'Tp2P': u'power supply 3',
168 'Tp4P': u'power supply 5', 168 #'Tp4P': u'power supply 5',
169 'TA1P': u'ambient 2', 169 #'TA1P': u'ambient 2',
170 'TA2S': u'pci slot 2 pos 1', 170 #'TA2S': u'pci slot 2 pos 1',
171 'TB1T': u'enclosure bottom 2', 171 #'TB1T': u'enclosure bottom 2',
172 'TB3T': u'enclosure bottom 4', 172 #'TB3T': u'enclosure bottom 4',
173 'TC0H': u'cpu0 heatsink', 173 #'TC0H': u'cpu0 heatsink',
174 'TC2D': u'cpu2', 174 #'TC2D': u'cpu2',
175 'TC3D': u'cpu3', 175 #'TC3D': u'cpu3',
176 'TCBH': u'cpu1', 176 #'TCBH': u'cpu1',
177 'TCCH': u'cpu2', 177 #'TCCH': u'cpu2',
178 'TG0H': u'gpu0 heatsink', 178 #'TG0H': u'gpu0 heatsink',
179 'TH1P': u'hdd bay 2', 179 #'TH1P': u'hdd bay 2',
180 'TH3P': u'hdd bay 4', 180 #'TH3P': u'hdd bay 4',
181 'TM0S': u'mem module a1', 181 #'TM0S': u'mem module a1',
182 'TM1S': u'mem module a2', 182 #'TM1S': u'mem module a2',
183 'TM2S': u'mem module a3', 183 #'TM2S': u'mem module a3',
184 'TM3S': u'mem module a4', 184 #'TM3S': u'mem module a4',
185 'TM4S': u'mem module a5', 185 #'TM4S': u'mem module a5',
186 'TM5S': u'mem module a6', 186 #'TM5S': u'mem module a6',
187 'TM6S': u'mem module a7', 187 #'TM6S': u'mem module a7',
188 'TM7S': u'mem module a8', 188 #'TM7S': u'mem module a8',
189 'TM8S': u'mem module b1', 189 #'TM8S': u'mem module b1',
190 'TM9S': u'mem module b2', 190 #'TM9S': u'mem module b2',
191 'TMA2': u'ram a2', 191 #'TMA2': u'ram a2',
192 'TMA4': u'ram a4', 192 #'TMA4': u'ram a4',
193 'TMAS': u'mem module b3', 193 #'TMAS': u'mem module b3',
194 'TMB2': u'ram b2', 194 #'TMB2': u'ram b2',
195 'TMB4': u'ram b4', 195 #'TMB4': u'ram b4',
196 'TMBS': u'mem module b4', 196 #'TMBS': u'mem module b4',
197 'TMCS': u'mem module b5', 197 #'TMCS': u'mem module b5',
198 'TMDS': u'mem module b6', 198 #'TMDS': u'mem module b6',
199 'TMES': u'mem module b7', 199 #'TMES': u'mem module b7',
200 'TMFS': u'mem module b8', 200 #'TMFS': u'mem module b8',
201 'TN0H': u'northbridge', 201 #'TN0H': u'northbridge',
202 'TN1P': u'northbridge 2', 202 #'TN1P': u'northbridge 2',
203 'TS0C': u'expansion slots', 203 #'TS0C': u'expansion slots',
204 'Th1H': u'main heatsink b', 204 #'Th1H': u'main heatsink b',
205 'Tp0P': u'power supply 1', 205 'Tp0P': u'power supply P',
206 'Tp1P': u'power supply 2', 206 #'Tp1P': u'power supply 2',
207 'Tp3P': u'power supply 4', 207 #'Tp3P': u'power supply 4',
208 'Tp5P': u'power supply 6', 208 #'Tp5P': u'power supply 6',
209 } 209 }
210 210
211 # _sensor_found_cache is set on the first call to _SMC_get_values. 211 # _sensor_found_cache is set on the first call to _SMC_get_values.
212 _sensor_found_cache = None 212 _sensor_found_cache = None
213 213
214 214
215 @tools.cached 215 @tools.cached
216 def _SMC_open(): 216 def _SMC_open():
217 """Opens the default SMC driver and returns the first device. 217 """Opens the default SMC driver and returns the first device.
218 218
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 """Returns a processed measurement via AppleSMC for a specified key. 278 """Returns a processed measurement via AppleSMC for a specified key.
279 279
280 Returns None on failure. 280 Returns None on failure.
281 """ 281 """
282 val = _SMC_read_key(conn, key) 282 val = _SMC_read_key(conn, key)
283 if not val or not val.size: 283 if not val or not val.size:
284 return None 284 return None
285 t = ''.join(map(chr, val.type)) 285 t = ''.join(map(chr, val.type))
286 if t == 'sp78\0' and val.size == 2: 286 if t == 'sp78\0' and val.size == 2:
287 # Format is first byte signed int8, second byte uint8 fractional. 287 # Format is first byte signed int8, second byte uint8 fractional.
288 return float(ctypes.c_int8(val.bytes[0]).value) + (val.bytes[1] / 256.) 288 return round(
289 float(ctypes.c_int8(val.bytes[0]).value) + (val.bytes[1] / 256.),
290 2)
289 if t == 'fpe2\0' and val.size == 2: 291 if t == 'fpe2\0' and val.size == 2:
290 # Format is unsigned 14 bits big endian, 2 bits fractional. 292 # Format is unsigned 14 bits big endian, 2 bits fractional.
291 return ( 293 return round(
292 float((val.bytes[0] << 6) + (val.bytes[1] >> 2)) + 294 (float((val.bytes[0] << 6) + (val.bytes[1] >> 2)) +
293 (val.bytes[1] & 3) / 4.) 295 (val.bytes[1] & 3) / 4.),
296 2)
294 # TODO(maruel): Handler other formats like 64 bits long. This is used for fan 297 # TODO(maruel): Handler other formats like 64 bits long. This is used for fan
295 # speed. 298 # speed.
296 logging.error( 299 logging.error(
297 '_SMC_get_value(%s) got unknown format: %s of %d bytes', key, t, val.size) 300 '_SMC_get_value(%s) got unknown format: %s of %d bytes', key, t, val.size)
298 return None 301 return None
299 302
300 303
301 @tools.cached 304 @tools.cached
302 def _get_system_profiler(data_type): 305 def _get_system_profiler(data_type):
303 """Returns an XML about the system display properties.""" 306 """Returns an XML about the system display properties."""
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 header = ( 695 header = (
693 '<?xml version="1.0" encoding="UTF-8"?>\n' 696 '<?xml version="1.0" encoding="UTF-8"?>\n'
694 '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' 697 '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
695 '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' 698 '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
696 '<plist version="1.0">\n' 699 '<plist version="1.0">\n'
697 ' <dict>\n' 700 ' <dict>\n'
698 + ''.join(' %s\n' % l for l in entries) + 701 + ''.join(' %s\n' % l for l in entries) +
699 ' </dict>\n' 702 ' </dict>\n'
700 '</plist>\n') 703 '</plist>\n')
701 return header 704 return header
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698