Chromium Code Reviews| Index: client/cros/power_status.py |
| diff --git a/client/cros/power_status.py b/client/cros/power_status.py |
| index 17a2358c357c8a8a341ee8104bd2a3238fe75cfd..b2efbc58fd7853c227f413997e7cbac841e59fbe 100644 |
| --- a/client/cros/power_status.py |
| +++ b/client/cros/power_status.py |
| @@ -41,6 +41,67 @@ class DevStat(object): |
| setattr(self, field, val) |
| +class ThermalStat(DevStat): |
| + """ |
| + Thermal status. |
| + |
| + Fields: |
| + (All temperatures are in degrees Celsius times 1000.) |
|
Sameer Nanda
2011/04/07 21:27:39
may want to call it millidegrees Celsius instead.
Simon Que
2011/04/07 22:50:03
Done.
|
| + |
| + 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): |
| + # Browse the thermal folder for trip point fields. |
| + self.num_trip_points = 0 |
| + |
| + thermal_fields = glob.glob(path + '/*') |
| + for file in thermal_fields: |
| + field = file[len(path + '/'):] |
|
Sameer Nanda
2011/04/07 21:27:39
this breaks (in the unlikely) case of zone# > 9, I
Simon Que
2011/04/07 22:50:03
Are you sure? the zone # is passed in as part of
|
| + if field.find('trip_point') != -1: |
| + if field.find('temp'): |
| + field_type = int |
| + else: |
| + field_type = str |
| + self.thermal_fields[field] = [field, field_type] |
| + |
| + # Count the number of trip points. |
| + if field.find('_type') != -1: |
| + self.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 field in self.thermal_fields: |
| + if field.find('trip_point_') != -1 and field.find('_temp') != -1 \ |
| + and self.temp > self.read_val(field, int): |
| + self.num_points_tripped += 1 |
|
Sameer Nanda
2011/04/07 21:27:39
can you add a logging.info message here printing o
Simon Que
2011/04/07 22:50:03
Done.
|
| + |
| + |
| + |
| class BatteryStat(DevStat): |
| """ |
| Battery status. |
| @@ -135,15 +196,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_zone*' |
| + |
| power_supplies = glob.glob(power_supply_path) |
| for path in power_supplies: |
| type_path = os.path.join(path,'type') |
| @@ -159,7 +223,11 @@ class SysStat(object): |
| self.linepower_path = linepower_path |
| else: |
| raise error.TestError('Battery or Linepower path not found') |
| + self.thermal_path = glob.glob(thermal_path)[0] |
| + self.min_temp = 999999999 |
| + self.max_temp = -999999999 |
| + self.temp_log = {} |
| def refresh(self): |
| """ |
| @@ -168,6 +236,15 @@ class SysStat(object): |
| """ |
| self.battery = [ BatteryStat(self.battery_path) ] |
| self.linepower = [ LineStat(self.linepower_path) ] |
| + self.thermal = [ ThermalStat(self.thermal_path) ] |
| + |
| + try: |
| + if self.thermal[0].temp < self.min_temp * 1000: |
| + self.min_temp = float(self.thermal[0].temp) / 1000 |
| + if self.thermal[0].temp > self.max_temp * 1000: |
| + self.max_temp = float(self.thermal[0].temp) / 1000 |
| + except: |
| + logging.error('Could not read temperature, skipping.') |
| def get_status(): |