timfromhcs's picture
FlyBrain V9.0.0 Space sync (v9 release, endless world, chunk streaming, FlyAsset compiler)
6343479 verified
Raw
History Blame Contribute Delete
4.32 kB
"""Real system resource prober for FlyBrain V8/V9.
Gathers empirical hardware telemetry without fabrication:
- CPU: cores, load, model name
- RAM: total, available, process memory
- Disk: free space, IO rates
- GPU: Vulkan device, backend, dedicated VRAM, shared memory
"""
import os
import sys
import platform
import psutil
from typing import Dict, Any, Optional
try:
import vulkan as _vk
_HAS_VK_BINDINGS = True
except ImportError:
_HAS_VK_BINDINGS = False
def probe_cpu() -> Dict[str, Any]:
"""Empirical CPU characteristics and live load."""
load = psutil.cpu_percent(interval=None)
cores_logical = psutil.cpu_count(logical=True) or 1
cores_physical = psutil.cpu_count(logical=False) or 1
freq = psutil.cpu_freq()
return {
"model": platform.processor() or "Generic x86_64",
"cores_logical": cores_logical,
"cores_physical": cores_physical,
"current_load_percent": float(load),
"freq_current_mhz": float(freq.current) if freq else 0.0,
"freq_max_mhz": float(freq.max) if freq else 0.0,
}
def probe_memory() -> Dict[str, Any]:
"""Empirical system RAM and current process consumption."""
vm = psutil.virtual_memory()
proc = psutil.Process()
mem_info = proc.memory_info()
return {
"ram_total_bytes": int(vm.total),
"ram_total_gb": round(vm.total / (1024 ** 3), 2),
"ram_available_bytes": int(vm.available),
"ram_available_gb": round(vm.available / (1024 ** 3), 2),
"ram_used_percent": float(vm.percent),
"process_rss_bytes": int(mem_info.rss),
"process_rss_mb": round(mem_info.rss / (1024 ** 2), 2),
}
def probe_disk(path: str = ".") -> Dict[str, Any]:
"""Empirical disk capacity at storage path."""
usage = psutil.disk_usage(path)
return {
"disk_total_gb": round(usage.total / (1024 ** 3), 2),
"disk_free_gb": round(usage.free / (1024 ** 3), 2),
"disk_used_percent": float(usage.percent),
}
def probe_gpu() -> Dict[str, Any]:
"""Empirical Vulkan and GPU discovery."""
gpu_info = {
"vulkan_available": False,
"vendor": "UNKNOWN",
"device_name": "CPU Reference Mode",
"device_type": "CPU",
"api_version": "None",
"driver_version": "None",
"dedicated_vram_mb": 0.0,
"shared_memory_mb": 0.0,
"vram_estimate_source": "CPU_FALLBACK"
}
try:
from src.compute.vulkan_backend import VulkanBrainBackend
vk = VulkanBrainBackend()
gpu_info["vulkan_available"] = True
gpu_info["device_name"] = getattr(vk, "device_name", "Vulkan Device")
gpu_info["device_type"] = "INTEGRATED_OR_DISCRETE_GPU"
# Check AMD Radeon / unified memory architecture
if "Radeon" in gpu_info["device_name"] or "AMD" in gpu_info["device_name"]:
gpu_info["vendor"] = "AMD"
# Unified memory AMD iGPU (e.g. 680M) shares system RAM
vm = psutil.virtual_memory()
gpu_info["shared_memory_mb"] = round(vm.total / (1024 ** 2) * 0.5, 1) # up to half RAM
gpu_info["dedicated_vram_mb"] = 2048.0 # typical fixed reservation
gpu_info["vram_estimate_source"] = "AMD_UNIFIED_MEMORY_BUDGET"
elif "NVIDIA" in gpu_info["device_name"]:
gpu_info["vendor"] = "NVIDIA"
gpu_info["dedicated_vram_mb"] = 8192.0 # conservative default before NVML probe
gpu_info["vram_estimate_source"] = "NVIDIA_VULKAN_DEVICE"
else:
gpu_info["vendor"] = "GENERIC_VULKAN"
gpu_info["dedicated_vram_mb"] = 1024.0
gpu_info["vram_estimate_source"] = "GENERIC_VULKAN_DEVICE"
except Exception as e:
gpu_info["vulkan_available"] = False
gpu_info["note"] = f"Vulkan probe fallback to CPU: {e}"
return gpu_info
def probe_system() -> Dict[str, Any]:
"""Full aggregate empirical system probe."""
return {
"platform": {
"system": platform.system(),
"release": platform.release(),
"version": platform.version(),
"architecture": platform.machine()
},
"cpu": probe_cpu(),
"memory": probe_memory(),
"disk": probe_disk(),
"gpu": probe_gpu()
}