mirror of
https://github.com/blw1138/Zordon.git
synced 2026-02-05 13:46:10 +00:00
GPU Reporting in UI (#120)
* Add basic GPU info reporting to UI * Update GPU display to showcase multiple GPUs, if available * Add fallback for Windows for fetching GPU info * Improve Windows GPU lookup. Add GPUtil to requirements.txt * Clean up GPU and CPU naming in UI * Update Linux GPU fetching * Update misc_helper.py Fix getting GPU names on Linux * Update .gitignore
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import string
|
||||
@@ -225,3 +227,121 @@ def iso_datestring_to_formatted_datestring(iso_date_string):
|
||||
formatted_date = date_local.strftime('%Y-%m-%d %I:%M %p')
|
||||
|
||||
return formatted_date
|
||||
|
||||
def get_gpu_info():
|
||||
"""Cross-platform GPU information retrieval"""
|
||||
|
||||
def get_windows_gpu_info():
|
||||
"""Get GPU info on Windows"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['wmic', 'path', 'win32_videocontroller', 'get', 'name,AdapterRAM', '/format:list'],
|
||||
capture_output=True, text=True, timeout=5
|
||||
)
|
||||
|
||||
# Virtual adapters to exclude
|
||||
virtual_adapters = [
|
||||
'virtual', 'rdp', 'hyper-v', 'microsoft basic', 'basic display',
|
||||
'vga compatible', 'dummy', 'nvfbc', 'nvencode'
|
||||
]
|
||||
|
||||
gpus = []
|
||||
current_gpu = None
|
||||
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
if line.startswith('Name='):
|
||||
if current_gpu and current_gpu.get('name'):
|
||||
gpus.append(current_gpu)
|
||||
gpu_name = line.replace('Name=', '').strip()
|
||||
|
||||
# Skip virtual adapters
|
||||
if any(virtual in gpu_name.lower() for virtual in virtual_adapters):
|
||||
current_gpu = None
|
||||
else:
|
||||
current_gpu = {'name': gpu_name, 'memory': 'Integrated'}
|
||||
|
||||
elif line.startswith('AdapterRAM=') and current_gpu:
|
||||
vram_bytes_str = line.replace('AdapterRAM=', '').strip()
|
||||
if vram_bytes_str and vram_bytes_str != '0':
|
||||
try:
|
||||
vram_gb = int(vram_bytes_str) / (1024**3)
|
||||
current_gpu['memory'] = round(vram_gb, 2)
|
||||
except:
|
||||
pass
|
||||
|
||||
if current_gpu and current_gpu.get('name'):
|
||||
gpus.append(current_gpu)
|
||||
|
||||
return gpus if gpus else [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get Windows GPU info: {e}")
|
||||
return [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||
|
||||
def get_macos_gpu_info():
|
||||
"""Get GPU info on macOS (works with Apple Silicon)"""
|
||||
try:
|
||||
result = subprocess.run(['system_profiler', 'SPDisplaysDataType', '-json'],
|
||||
capture_output=True, text=True, timeout=5)
|
||||
data = json.loads(result.stdout)
|
||||
|
||||
gpus = []
|
||||
displays = data.get('SPDisplaysDataType', [])
|
||||
for display in displays:
|
||||
if 'sppci_model' in display:
|
||||
gpus.append({
|
||||
'name': display.get('sppci_model', 'Unknown GPU'),
|
||||
'memory': display.get('sppci_vram', 'Integrated'),
|
||||
})
|
||||
return gpus if gpus else [{'name': 'Apple Silicon GPU', 'memory': 'Integrated'}]
|
||||
except Exception as e:
|
||||
print(f"Failed to get macOS GPU info: {e}")
|
||||
return [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||
|
||||
def get_linux_gpu_info():
|
||||
gpus = []
|
||||
try:
|
||||
# Run plain lspci and filter for GPU-related lines
|
||||
output = subprocess.check_output(
|
||||
["lspci"], universal_newlines=True, stderr=subprocess.DEVNULL
|
||||
)
|
||||
for line in output.splitlines():
|
||||
if any(keyword in line.lower() for keyword in ["vga", "3d", "display"]):
|
||||
# Extract the part after the colon (vendor + model)
|
||||
if ":" in line:
|
||||
name_part = line.split(":", 1)[1].strip()
|
||||
# Clean up common extras like (rev xx) or (prog-if ...)
|
||||
name = name_part.split("(")[0].split("controller:")[-1].strip()
|
||||
vendor = "Unknown"
|
||||
if "nvidia" in name.lower():
|
||||
vendor = "NVIDIA"
|
||||
elif "amd" in name.lower() or "ati" in name.lower():
|
||||
vendor = "AMD"
|
||||
elif "intel" in name.lower():
|
||||
vendor = "Intel"
|
||||
|
||||
gpus.append({
|
||||
"name": name,
|
||||
"vendor": vendor,
|
||||
"memory": "Unknown"
|
||||
})
|
||||
except FileNotFoundError:
|
||||
print("lspci not found. Install pciutils: sudo apt install pciutils")
|
||||
return []
|
||||
except Exception as e:
|
||||
print(f"Error running lspci: {e}")
|
||||
return []
|
||||
|
||||
return gpus
|
||||
|
||||
system = platform.system()
|
||||
|
||||
if system == 'Darwin': # macOS
|
||||
return get_macos_gpu_info()
|
||||
elif system == 'Windows':
|
||||
return get_windows_gpu_info()
|
||||
else: # Assume Linux or other
|
||||
return get_linux_gpu_info()
|
||||
|
||||
Reference in New Issue
Block a user