Skip to content

Commit

Permalink
0.1.24: improve power reading file selection
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlay committed Jun 11, 2024
1 parent 8362397 commit e7bdf87
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "amdgpu-stats"
version = "0.1.23"
version = "0.1.24"
description = "A module/TUI for AMD GPU statistics"
authors = ["Josh Lay <pypi@jlay.io>"]
repository = "https://github.com/joshlay/amdgpu_stats"
Expand All @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[tool.poetry.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/amdgpu_stats/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_column_data_mapping(self, card: Optional[str] = None) -> dict:
# ... then map to a smaller dict that's used to update the table
_all_pwr = get_power_stats(card=card)
power_stats = {
"usage": _all_pwr["average"],
"usage": _all_pwr["usage"],
"lim": _all_pwr["limit"],
"def": _all_pwr["default"],
"cap": _all_pwr["capability"],
Expand Down
12 changes: 9 additions & 3 deletions src/amdgpu_stats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ def get_power_stats(card: Optional[str] = None) -> dict:
"""
card = validate_card(card)
hwmon_dir = CARDS[card]

# different GPUs/drivers may offer either averaged or instant readouts [in different files]; adjust gracefully
for usage_file in (path.join(hwmon_dir, 'power1_input'), path.join(hwmon_dir, 'power1_average')):
if path.exists(usage_file):
usage = read_stat(usage_file, stat_type='power')

_pwr = {"limit": read_stat(path.join(hwmon_dir, "power1_cap"), stat_type='power'),
"limit_pct": 0,
"average": read_stat(path.join(hwmon_dir, "power1_average"), stat_type='power'),
"usage_pct": 0,
"usage": usage,
"capability": read_stat(path.join(hwmon_dir, "power1_cap_max"), stat_type='power'),
"default": read_stat(path.join(hwmon_dir, "power1_cap_default"), stat_type='power')}

if _pwr['limit'] is not None:
_pwr['limit_pct'] = round((_pwr['average'] / _pwr['limit']) * 100, 1)
_pwr['usage_pct'] = round((_pwr['usage'] / _pwr['limit']) * 100, 1)

return _pwr

Expand Down

0 comments on commit e7bdf87

Please sign in to comment.