Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing for /sys/class/thermal #1345

Merged
merged 5 commits into from
Oct 1, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,49 @@ def sensors_temperatures():

ret[unit_name].append((label, current, high, critical))

# Indication that no sensors were detected in /sys/class/hwmon/
if len(basenames) == 0:
amanusk marked this conversation as resolved.
Show resolved Hide resolved
basenames = glob.glob('/sys/class/thermal/thermal_zone*')
basenames = sorted(set(basenames))

for base in basenames:
try:
path = os.path.join(base, 'temp')
current = float(cat(path)) / 1000.0
path = os.path.join(base, 'type')
unit_name = cat(path, binary=False)
except (IOError, OSError, ValueError) as err:
warnings.warn("ignoring %r for file %r" % (err, path),
RuntimeWarning)
continue

trip_paths = glob.glob(base + '/trip_point*')
trip_points = [os.path.basename(p) for p in trip_paths]
trip_points = sorted(set(["_".join(x.split('_')[0:3])
for x in trip_points]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm... I have mixed feelings about this. You make 2 for loops here and another 1 later for a total of 3. I wonder if there's a way to reduce the number of loops.

critical = None
high = None
for trip_point in trip_points:
path = os.path.join(base, trip_point + "_type")
trip_type = cat(path, fallback='', binary=False)
if trip_type == 'critical':
critical = cat(os.path.join(base, trip_point + "_temp"))
amanusk marked this conversation as resolved.
Show resolved Hide resolved
elif trip_type == 'high':
high = cat(os.path.join(base, trip_point + "_temp"))
amanusk marked this conversation as resolved.
Show resolved Hide resolved

if high is not None:
try:
high = float(high) / 1000.0
except ValueError:
high = None
if critical is not None:
try:
critical = float(critical) / 1000.0
except ValueError:
critical = None

ret[unit_name].append(('', current, high, critical))

return ret


Expand Down