#!/bin/bash
# Monitor GPU clocks during inference test

echo "Starting GPU monitoring during inference..."
echo "=========================================="

# Start GPU monitoring in background
(
    while true; do
        echo "--- $(date +%H:%M:%S) ---"
        rocm-smi --showclocks --showuse 2>/dev/null | grep -E "sclk|mclk|GPU use"
        sleep 0.5
    done
) > /tmp/gpu_monitor.log &
MONITOR_PID=$!

echo "Monitor started (PID: $MONITOR_PID)"
echo ""

# Run test
echo "Submitting test job..."
curl -s -X POST http://localhost:8765/api/speak \
    -H "Content-Type: application/json" \
    -d '{"text": "Comprehensive performance test to monitor GPU clock speeds and utilization during Soprano and RVC processing."}' \
    > /dev/null

echo "Job submitted, waiting 10 seconds..."
sleep 10

# Stop monitoring
kill $MONITOR_PID 2>/dev/null

echo ""
echo "=========================================="
echo "GPU Monitoring Results:"
echo "=========================================="
cat /tmp/gpu_monitor.log

echo ""
echo "=========================================="
echo "Performance Results:"
echo "=========================================="
sleep 1
tail -10 /tmp/soprano_timing_debug.txt
