#!/bin/bash
# Deep process diagnosis
PID=$(pgrep -f 'python main.py' | head -1)
if [ -z "$PID" ]; then
    echo "NO PROCESS FOUND"
    exit 1
fi

echo "=== Process $PID ==="
ps -p $PID -o pid,pcpu,pmem,vsz,rss,state --no-header

echo ""
echo "=== Process state ==="
cat /proc/$PID/status | grep -E 'State|Threads|VmRSS|VmSwap|voluntary|nonvoluntary'

echo ""
echo "=== Waiting on ==="
cat /proc/$PID/wchan 2>/dev/null
echo ""

echo ""
echo "=== Thread CPU usage ==="
ps -p $PID -L -o tid,pcpu,state --no-header | sort -k2 -rn | head -10

echo ""
echo "=== Strace (2 sec) ==="
timeout 2 strace -p $PID -c 2>&1 | head -30

echo ""
echo "=== Log file check ==="
wc -c /home/fabian/comfyui7.log
ls -la /home/fabian/comfyui7.log
