"""Quick check: what's ACTUALLY happening in the ComfyUI log right now?"""
import paramiko

k = paramiko.Ed25519Key.from_private_key_file(r'C:\Users\fabia\.ssh\id_ed25519')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('192.168.178.150', username='fabian', pkey=k, timeout=10)

def sh(cmd):
    chan = c.get_transport().open_session()
    chan.settimeout(30)
    chan.exec_command(f"/bin/bash -c '{cmd}'")
    out = b""
    while True:
        try:
            chunk = chan.recv(65536)
            if not chunk: break
            out += chunk
        except: break
    chan.close()
    return out.decode(errors='replace').strip()

print("=== FULL LOG (minus ComfyUI-Manager spam) ===")
# Show all lines EXCEPT the registry fetch / manager spam
log = sh("grep -v 'FETCH ComfyRegistry\\|All startup tasks\\|ComfyUI-Manager' /tmp/comfyui.log | tail -50")
print(log)

print("\n=== PROCESS ===")
print(sh("ps aux | grep python3 | grep -v grep"))

print("\n=== GPU sysfs ===")
# Find the actual gpu_busy path
print(sh("find /sys/class/drm/ -name 'gpu_busy_percent' 2>/dev/null"))
print(sh("cat /sys/class/drm/card0/device/gpu_busy_percent 2>/dev/null; cat /sys/class/drm/card1/device/gpu_busy_percent 2>/dev/null"))

print("\n=== rocm-smi ===")
print(sh("rocm-smi 2>/dev/null | head -15"))

print("\n=== OUTPUT DIR ===")
print(sh("ls -la ~/ComfyUI/output/ 2>/dev/null"))

print("\n=== QUEUE ===")
print(sh("curl -s http://127.0.0.1:8188/queue 2>/dev/null"))

print("\n=== Log lines with 'load' or 'sample' or 'error' or '%' ===")
print(sh("grep -iE 'load|sample|error|%|step|Traceback|OOM|killed' /tmp/comfyui.log | tail -30"))

c.close()
