Archived
1
1
Fork 0

power: report usage as a percentage of limit

This commit is contained in:
Josh Lay 2023-04-30 18:54:52 -05:00
parent 6a7964285e
commit f323e4defe
Signed by: jlay
GPG key ID: B265E45CACAD108A
2 changed files with 9 additions and 3 deletions

View file

@ -277,6 +277,7 @@ class PowerDisplay(Static):
"""A widget to display GPU power stats."""
watts = reactive({"limit": 0,
"limit_pct": 0,
"average": 0,
"capability": 0,
"default": 0})
@ -318,7 +319,7 @@ class PowerDisplay(Static):
- Updates label values
- Casting inputs to string to avoid type problems w/ int/None"""
self.query_one("#pwr_avg_val",
Static).update(f"{watts['average']}W")
Static).update(f"{watts['limit_pct']}%, {watts['average']}W")
self.query_one("#pwr_lim_val",
Static).update(f"{watts['limit']}W")
self.query_one("#pwr_def_val",

View file

@ -132,12 +132,17 @@ def get_power_stats(card: Optional[str] = None) -> dict:
"""
card = validate_card(card)
hwmon_dir = AMDGPU_CARDS[card]
return {"limit": read_stat(path.join(hwmon_dir, "power1_cap"), 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'),
"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'] != 0:
_pwr['limit_pct'] = round((_pwr['average'] / _pwr['limit']) * 100, 1)
return _pwr
def get_core_stats(card: Optional[str] = None) -> dict:
"""