#!/bin/bash
# Monitor progress over 10 seconds
pid=$(pgrep -f "python.*main.py" | head -1)
if [ -z "$pid" ]; then
    echo "NO PROCESS"
    exit 1
fi

for i in 1 2 3; do
    echo "=== Check $i ($(date +%H:%M:%S)) ==="
    ticks=$(cat /proc/$pid/task/41104/stat 2>/dev/null | awk '{print $14+$15}')
    rss=$(cat /proc/$pid/status 2>/dev/null | grep VmRSS | awk '{print $2}')
    state=$(cat /proc/$pid/task/41104/stat 2>/dev/null | awk '{print $3}')
    vram=$(rocm-smi --showmeminfo vram 2>/dev/null | grep "Used" | awk '{print $NF}')
    echo "  TID 41104: state=$state ticks=$ticks RSS=${rss}KB VRAM=${vram}B"
    
    # Check log for any new output
    tail -3 /home/fabian/comfyui7.log 2>/dev/null
    echo ""
    sleep 5
done
