From f323e4defeae94372e08b79ae3c68a90380a6580 Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sun, 30 Apr 2023 18:54:52 -0500 Subject: [PATCH] power: report usage as a percentage of limit --- src/amdgpu_stats/tui.py | 3 ++- src/amdgpu_stats/utils.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/amdgpu_stats/tui.py b/src/amdgpu_stats/tui.py index b5e1925..9eb517f 100644 --- a/src/amdgpu_stats/tui.py +++ b/src/amdgpu_stats/tui.py @@ -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", diff --git a/src/amdgpu_stats/utils.py b/src/amdgpu_stats/utils.py index 767e994..01e680a 100644 --- a/src/amdgpu_stats/utils.py +++ b/src/amdgpu_stats/utils.py @@ -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: """