diff options
Diffstat (limited to 'glances/plugins/gpu/cards/amd.py')
-rw-r--r-- | glances/plugins/gpu/cards/amd.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/glances/plugins/gpu/cards/amd.py b/glances/plugins/gpu/cards/amd.py index ff161997..b3a84e04 100644 --- a/glances/plugins/gpu/cards/amd.py +++ b/glances/plugins/gpu/cards/amd.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # This file is part of Glances. # @@ -35,9 +34,9 @@ See: https://wiki.archlinux.org/title/AMDGPU#Manually # └── 0 # └── amdgpu_pm_info -from glances.logger import logger -import re import os +import re +from typing import Optional DRM_ROOT_FOLDER: str = '/sys/class/drm' CARD_REGEX: str = r"^card\d$" @@ -59,14 +58,13 @@ class AmdGPU: def exit(self): """Close AMD GPU class.""" - pass def get_device_stats(self): """Get AMD GPU stats.""" stats = [] for index, device in enumerate(self.device_folders): - device_stats = dict() + device_stats = {} # Dictionary key is the GPU_ID device_stats['key'] = 'gpu_id' # GPU id (for multiple GPU, start at 0) @@ -91,9 +89,11 @@ def get_device_list(drm_root_folder: str) -> list: ret = [] for root, dirs, _ in os.walk(drm_root_folder): for d in dirs: - if re.match(CARD_REGEX, d) and \ - DEVICE_FOLDER in os.listdir(os.path.join(root, d)) and \ - os.path.isfile(os.path.join(root, d, DEVICE_FOLDER, GPU_PROC_PERCENT)): + if ( + re.match(CARD_REGEX, d) + and DEVICE_FOLDER in os.listdir(os.path.join(root, d)) + and os.path.isfile(os.path.join(root, d, DEVICE_FOLDER, GPU_PROC_PERCENT)) + ): # If the GPU busy file is present then take the card into account ret.append(os.path.join(root, d, DEVICE_FOLDER)) return ret @@ -104,7 +104,7 @@ def get_device_name(device_folder: str) -> str: return 'AMD GPU' -def get_mem(device_folder: str) -> int: +def get_mem(device_folder: str) -> Optional[int]: """Return the memory consumption in %.""" mem_info_vram_total = os.path.join(device_folder, GPU_MEM_TOTAL) mem_info_vram_used = os.path.join(device_folder, GPU_MEM_USED) @@ -118,7 +118,7 @@ def get_mem(device_folder: str) -> int: return None -def get_proc(device_folder: str) -> int: +def get_proc(device_folder: str) -> Optional[int]: """Return the processor consumption in %.""" gpu_busy_percent = os.path.join(device_folder, GPU_PROC_PERCENT) if os.path.isfile(gpu_busy_percent): @@ -127,7 +127,7 @@ def get_proc(device_folder: str) -> int: return None -def get_temperature(device_folder: str) -> int: +def get_temperature(device_folder: str) -> Optional[int]: """Return the processor temperature in °C (mean of all HWMON)""" temp_input = [] for root, dirs, _ in os.walk(device_folder): @@ -140,10 +140,9 @@ def get_temperature(device_folder: str) -> int: temp_input.append(int(f.read())) if len(temp_input) > 0: return round(sum(temp_input) / len(temp_input) / 1000) - else: - return None + return None -def get_fan_speed(device_folder: str) -> int: +def get_fan_speed(device_folder: str) -> Optional[int]: """Return the fan speed in %.""" return None |