This commit is contained in:
devdatt 2026-02-18 04:28:36 +05:30
parent 2cfb6107c7
commit 40d8916906
1 changed files with 46 additions and 41 deletions

77
setup.sh Normal file → Executable file
View File

@ -231,57 +231,62 @@ gpu_lock = threading.Lock()
def gpu_monitor(): def gpu_monitor():
global gpu_data global gpu_data
# Use -s 1000 for 1-second updates
cmd = ["/usr/sbin/intel_gpu_top", "-J", "-s", "1000"] # auto-detect path
binary = "/usr/bin/intel_gpu_top"
if not os.path.exists(binary):
binary = "intel_gpu_top"
cmd = [binary, "-J", "-s", "1000"]
while True: while True:
try: try:
p = subprocess.Popen( proc = subprocess.Popen(
cmd, cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, stderr=subprocess.PIPE,
text=True, text=True,
bufsize=1 bufsize=1
) )
buffer = "" for line in proc.stdout:
for line in p.stdout: line = line.strip()
buffer += line if not line:
if "}" in line: continue
# Regex extracts the object between curly braces that contains "engines"
matches = re.findall(r'({[^{}]*("engines")[^{}]*})', buffer, re.DOTALL)
if matches:
try:
# Parse the most recent complete match
raw_json = matches[-1][0]
data = json.loads(raw_json)
if "engines" in data: try:
eng = data["engines"] data = json.loads(line)
except:
continue
# Helper to find keys regardless of index (e.g. Render/3D/0) engines = data.get("engines")
def get_busy(name): if not engines:
for k, v in eng.items(): continue
if name in k:
return v.get("busy", 0.0)
return 0.0
with gpu_lock: def get_busy(name):
gpu_data["Render/3D"] = get_busy("Render/3D") for k, v in engines.items():
gpu_data["Video"] = get_busy("Video") if name in k:
gpu_data["Blitter"] = get_busy("Blitter") return float(v.get("busy", 0.0))
gpu_data["VideoEnhance"] = get_busy("VideoEnhance") return 0.0
# Total is the peak engine usage r = get_busy("Render")
vals = [v for k, v in gpu_data.items() if k != "total"] v = get_busy("Video")
gpu_data["total"] = max(vals) if vals else 0.0 b = get_busy("Blitter")
e = get_busy("VideoEnhance")
with gpu_lock:
gpu_data["Render/3D"] = r
gpu_data["Video"] = v
gpu_data["Blitter"] = b
gpu_data["VideoEnhance"] = e
gpu_data["total"] = max(r, v, b, e)
proc.wait()
# Clean buffer to prevent memory growth
buffer = buffer[buffer.rfind("}")+1:]
except (json.JSONDecodeError, ValueError):
continue
except Exception: except Exception:
time.sleep(2) pass
time.sleep(2)
threading.Thread(target=gpu_monitor, daemon=True).start() threading.Thread(target=gpu_monitor, daemon=True).start()