Files
ComfyUI/custom_nodes/ComfyUI-Crystools/general/hardware.py
jaidaken f09734b0ee
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Add custom nodes, Civitai loras (LFS), and vast.ai setup script
Includes 30 custom nodes committed directly, 7 Civitai-exclusive
loras stored via Git LFS, and a setup script that installs all
dependencies and downloads HuggingFace-hosted models on vast.ai.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 00:56:42 +00:00

133 lines
3.9 KiB
Python

import platform
import re
import cpuinfo
from cpuinfo import DataSource
import psutil
from .gpu import CGPUInfo
from .hdd import getDrivesInfo
from ..core import logger
class CHardwareInfo:
"""
This is only class to get information from hardware.
Specially for share it to other software.
"""
switchCPU = False
switchHDD = False
switchRAM = False
whichHDD = '/' # breaks linux
@property
def switchGPU(self):
return self.GPUInfo.switchGPU
@switchGPU.setter
def switchGPU(self, value):
self.GPUInfo.switchGPU = value
@property
def switchVRAM(self):
return self.GPUInfo.switchVRAM
@switchVRAM.setter
def switchVRAM(self, value):
self.GPUInfo.switchVRAM = value
def __init__(self, switchCPU=False, switchGPU=False, switchHDD=False, switchRAM=False, switchVRAM=False):
self.switchCPU = switchCPU
self.switchHDD = switchHDD
self.switchRAM = switchRAM
self.print_sys_info()
self.GPUInfo = CGPUInfo()
self.switchGPU = switchGPU
self.switchVRAM = switchVRAM
def print_sys_info(self):
brand = None
if DataSource.is_windows: # Windows
brand = DataSource.winreg_processor_brand().strip()
elif DataSource.has_proc_cpuinfo(): # Linux
return_code, output = DataSource.cat_proc_cpuinfo()
if return_code == 0 and output is not None:
for line in output.splitlines():
r = re.search(r'model name\s*:\s*(.+)', line)
if r:
brand = r.group(1)
break
elif DataSource.has_sysctl(): # macOS
return_code, output = DataSource.sysctl_machdep_cpu_hw_cpufrequency()
if return_code == 0 and output is not None:
for line in output.splitlines():
r = re.search(r'machdep\.cpu\.brand_string\s*:\s*(.+)', line)
if r:
brand = r.group(1)
break
# fallback to use cpuinfo.get_cpu_info()
if not brand:
brand = cpuinfo.get_cpu_info().get('brand_raw', "Unknown")
arch_string_raw = 'Arch unknown'
try:
arch_string_raw = DataSource.arch_string_raw
except:
pass
specName = 'CPU: ' + brand
specArch = 'Arch: ' + arch_string_raw
specOs = 'OS: ' + str(platform.system()) + ' ' + str(platform.release())
logger.info(f"{specName} - {specArch} - {specOs}")
def getHDDsInfo(self):
return getDrivesInfo()
def getGPUInfo(self):
return self.GPUInfo.getInfo()
def getStatus(self):
cpu = -1
ramTotal = -1
ramUsed = -1
ramUsedPercent = -1
hddTotal = -1
hddUsed = -1
hddUsedPercent = -1
if self.switchCPU:
cpu = psutil.cpu_percent()
if self.switchRAM:
ram = psutil.virtual_memory()
ramTotal = ram.total
ramUsed = ram.used
ramUsedPercent = ram.percent
if self.switchHDD:
try:
hdd = psutil.disk_usage(self.whichHDD)
hddTotal = hdd.total
hddUsed = hdd.used
hddUsedPercent = hdd.percent
except Exception as e:
logger.error(f"Error getting disk usage for {self.whichHDD}: {e}")
hddTotal = -1
hddUsed = -1
hddUsedPercent = -1
getStatus = self.GPUInfo.getStatus()
return {
'cpu_utilization': cpu,
'ram_total': ramTotal,
'ram_used': ramUsed,
'ram_used_percent': ramUsedPercent,
'hdd_total': hddTotal,
'hdd_used': hddUsed,
'hdd_used_percent': hddUsedPercent,
'device_type': getStatus['device_type'],
'gpus': getStatus['gpus'],
}