Index: client/cros/power_status.py |
diff --git a/client/cros/power_status.py b/client/cros/power_status.py |
index 17a2358c357c8a8a341ee8104bd2a3238fe75cfd..b7557285d8688b999e92c7882dd8f16211d9b63e 100644 |
--- a/client/cros/power_status.py |
+++ b/client/cros/power_status.py |
@@ -41,6 +41,65 @@ class DevStat(object): |
setattr(self, field, val) |
+class ThermalStat(DevStat): |
+ """ |
+ Thermal status. |
+ |
+ Fields: |
+ (All temperatures are in degrees Celsius times 1000.) |
+ |
+ str enabled: Whether thermal zone is enabled |
+ int temp: Current temperature |
+ str type: Thermal zone type |
+ int num_trip_points: Number of thermal trip points that activate |
+ cooling devices |
+ int num_points_tripped: Temperature is above this many trip points |
+ str trip_point_N_type: Trip point #N's type |
+ int trip_point_N_temp: Trip point #N's temperature value |
+ int cdevX_trip_point: Trip point o cooling device #X (index) |
+ """ |
+ |
+ MAX_TRIP_POINTS = 20 |
+ |
+ thermal_fields = { |
+ 'enabled': ['enabled', str], |
+ 'temp': ['temp', int], |
+ 'type': ['type', str], |
+ 'num_points_tripped': ['', ''] |
+ } |
+ def __init__(self, path=None): |
+ # Dynamically generate the rest of the fields |
+ thermal_point_strings = [ 'trip_point_%d_type', |
+ 'trip_point_%d_temp', |
+ 'cdev%d_trip_point' ] |
+ thermal_point_types = [ str, int, int ] |
+ self.num_trip_points = 0 |
+ |
+ for i in range(MAX_TRIP_POINTS): |
+ for j in range(len(thermal_point_strings)): |
+ file = thermal_point_strings[j] % i |
+ |
+ if os.path.exists(path + file): |
+ self.thermal_fields[file] = [file, thermal_point_types[j]] |
+ if j == 0: |
+ num_trip_points += 1 |
+ |
+ super(ThermalStat, self).__init__(self.thermal_fields, path) |
+ self.update() |
+ |
+ def update(self): |
+ if not os.path.exists(self.path): |
+ return |
+ |
+ self.read_all_vals() |
+ self.num_points_tripped = 0 |
+ |
+ for i in range(self.num_trip_points): |
Sameer Nanda
2011/04/06 18:13:40
probably better to just save the names of all trip
Simon Que
2011/04/07 20:59:47
Done.
|
+ if self.temp > self.read_val('trip_point_%d_temp' % i, int): |
+ self.num_points_tripped += 1 |
+ |
+ |
+ |
class BatteryStat(DevStat): |
""" |
Battery status. |
@@ -135,15 +194,18 @@ class SysStat(object): |
Fields: |
battery: A list of BatteryStat objects. |
- linepower: A list of LineStat opbjects. |
+ linepower: A list of LineStat objects. |
""" |
def __init__(self): |
power_supply_path = '/sys/class/power_supply/*' |
self.battery = None |
self.linepower = None |
+ self.thermal = None |
battery_path = None |
linepower_path = None |
+ thermal_path = '/sys/class/thermal/thermal_zone0' |
Sameer Nanda
2011/04/06 18:13:40
do you want to use thermal_zone* here instead? I
Simon Que
2011/04/07 20:59:47
Done.
|
+ |
power_supplies = glob.glob(power_supply_path) |
for path in power_supplies: |
type_path = os.path.join(path,'type') |
@@ -159,7 +221,10 @@ class SysStat(object): |
self.linepower_path = linepower_path |
else: |
raise error.TestError('Battery or Linepower path not found') |
+ self.thermal_path = thermal_path |
+ self.min_temp = 999999999 |
+ self.max_temp = -999999999 |
def refresh(self): |
""" |
@@ -168,6 +233,15 @@ class SysStat(object): |
""" |
self.battery = [ BatteryStat(self.battery_path) ] |
self.linepower = [ LineStat(self.linepower_path) ] |
+ self.thermal = [ ThermalStat(self.thermal_path) ] |
+ |
+ try: |
Sameer Nanda
2011/04/06 18:13:40
lets add a logging.info for the temperature that w
Simon Que
2011/04/07 20:59:47
This isn't trivial, as there may be other log mess
Simon Que
2011/04/07 23:30:51
Done.
|
+ if self.thermal[0].temp < self.min_temp: |
+ self.min_temp = self.thermal[0].temp |
+ if self.thermal[0].temp > self.max_temp: |
+ self.max_temp = self.thermal[0].temp |
+ except: |
+ logging.error('Could not read temperature, skipping.') |
def get_status(): |