update
This commit is contained in:
parent
2cfb6107c7
commit
40d8916906
|
|
@ -231,56 +231,61 @@ 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:
|
try:
|
||||||
# Parse the most recent complete match
|
data = json.loads(line)
|
||||||
raw_json = matches[-1][0]
|
except:
|
||||||
data = json.loads(raw_json)
|
continue
|
||||||
|
|
||||||
if "engines" in data:
|
engines = data.get("engines")
|
||||||
eng = data["engines"]
|
if not engines:
|
||||||
|
continue
|
||||||
|
|
||||||
# Helper to find keys regardless of index (e.g. Render/3D/0)
|
|
||||||
def get_busy(name):
|
def get_busy(name):
|
||||||
for k, v in eng.items():
|
for k, v in engines.items():
|
||||||
if name in k:
|
if name in k:
|
||||||
return v.get("busy", 0.0)
|
return float(v.get("busy", 0.0))
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
r = get_busy("Render")
|
||||||
|
v = get_busy("Video")
|
||||||
|
b = get_busy("Blitter")
|
||||||
|
e = get_busy("VideoEnhance")
|
||||||
|
|
||||||
with gpu_lock:
|
with gpu_lock:
|
||||||
gpu_data["Render/3D"] = get_busy("Render/3D")
|
gpu_data["Render/3D"] = r
|
||||||
gpu_data["Video"] = get_busy("Video")
|
gpu_data["Video"] = v
|
||||||
gpu_data["Blitter"] = get_busy("Blitter")
|
gpu_data["Blitter"] = b
|
||||||
gpu_data["VideoEnhance"] = get_busy("VideoEnhance")
|
gpu_data["VideoEnhance"] = e
|
||||||
|
gpu_data["total"] = max(r, v, b, e)
|
||||||
|
|
||||||
# Total is the peak engine usage
|
proc.wait()
|
||||||
vals = [v for k, v in gpu_data.items() if k != "total"]
|
|
||||||
gpu_data["total"] = max(vals) if vals else 0.0
|
|
||||||
|
|
||||||
# Clean buffer to prevent memory growth
|
|
||||||
buffer = buffer[buffer.rfind("}")+1:]
|
|
||||||
except (json.JSONDecodeError, ValueError):
|
|
||||||
continue
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
threading.Thread(target=gpu_monitor, daemon=True).start()
|
threading.Thread(target=gpu_monitor, daemon=True).start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue