Skip to content

Commit e7bdf87

Browse files
committed
0.1.24: improve power reading file selection
1 parent 8362397 commit e7bdf87

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "amdgpu-stats"
3-
version = "0.1.23"
3+
version = "0.1.24"
44
description = "A module/TUI for AMD GPU statistics"
55
authors = ["Josh Lay <[email protected]>"]
66
repository = "https://github.com/joshlay/amdgpu_stats"
@@ -18,6 +18,7 @@ classifiers = [
1818
"Programming Language :: Python :: 3.9",
1919
"Programming Language :: Python :: 3.10",
2020
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
2122
]
2223

2324
[tool.poetry.dependencies]

src/amdgpu_stats/tui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def get_column_data_mapping(self, card: Optional[str] = None) -> dict:
6161
# ... then map to a smaller dict that's used to update the table
6262
_all_pwr = get_power_stats(card=card)
6363
power_stats = {
64-
"usage": _all_pwr["average"],
64+
"usage": _all_pwr["usage"],
6565
"lim": _all_pwr["limit"],
6666
"def": _all_pwr["default"],
6767
"cap": _all_pwr["capability"],

src/amdgpu_stats/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,20 @@ def get_power_stats(card: Optional[str] = None) -> dict:
135135
"""
136136
card = validate_card(card)
137137
hwmon_dir = CARDS[card]
138+
139+
# different GPUs/drivers may offer either averaged or instant readouts [in different files]; adjust gracefully
140+
for usage_file in (path.join(hwmon_dir, 'power1_input'), path.join(hwmon_dir, 'power1_average')):
141+
if path.exists(usage_file):
142+
usage = read_stat(usage_file, stat_type='power')
143+
138144
_pwr = {"limit": read_stat(path.join(hwmon_dir, "power1_cap"), stat_type='power'),
139-
"limit_pct": 0,
140-
"average": read_stat(path.join(hwmon_dir, "power1_average"), stat_type='power'),
145+
"usage_pct": 0,
146+
"usage": usage,
141147
"capability": read_stat(path.join(hwmon_dir, "power1_cap_max"), stat_type='power'),
142148
"default": read_stat(path.join(hwmon_dir, "power1_cap_default"), stat_type='power')}
143149

144150
if _pwr['limit'] is not None:
145-
_pwr['limit_pct'] = round((_pwr['average'] / _pwr['limit']) * 100, 1)
151+
_pwr['usage_pct'] = round((_pwr['usage'] / _pwr['limit']) * 100, 1)
146152

147153
return _pwr
148154

0 commit comments

Comments
 (0)