Files
rfcp/installer/test-coverage-monitor.bat
2026-02-01 14:26:17 +02:00

283 lines
11 KiB
Batchfile

@echo off
title RFCP Coverage API Test + Resource Monitor
setlocal EnableDelayedExpansion
echo ============================================
echo RFCP Coverage API Test + Resource Monitor
echo ============================================
echo.
set API=http://127.0.0.1:8888
set RESULTS_DIR=%~dp0test-results
set TIMESTAMP=%date:~-4%%date:~3,2%%date:~0,2%-%time:~0,2%%time:~3,2%
set TIMESTAMP=%TIMESTAMP: =0%
:: Create results directory
if not exist "%RESULTS_DIR%" mkdir "%RESULTS_DIR%"
:: Log file for this run
set LOG_FILE=%RESULTS_DIR%\test-run-%TIMESTAMP%.log
echo Test started: %date% %time% > "%LOG_FILE%"
echo. >> "%LOG_FILE%"
:: ===========================================
:: SYSTEM INFO
:: ===========================================
echo [SYSTEM] Collecting system info...
echo. >> "%LOG_FILE%"
echo === SYSTEM INFO === >> "%LOG_FILE%"
:: CPU info (PowerShell — wmic deprecated in Win11)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_Processor).Name"') do (
echo CPU: %%a >> "%LOG_FILE%"
echo CPU: %%a
)
:: RAM info (PowerShell)
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).TotalVisibleMemorySize"') do (
set /a RAM_GB=%%a/1024/1024
echo RAM: !RAM_GB! GB >> "%LOG_FILE%"
echo RAM: !RAM_GB! GB
)
:: GPU info (PowerShell)
echo GPU: >> "%LOG_FILE%"
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_VideoController).Name"') do (
echo %%a >> "%LOG_FILE%"
echo %%a
)
echo. >> "%LOG_FILE%"
echo.
:: ===========================================
:: PRE-TEST BASELINE
:: ===========================================
echo [BASELINE] Capturing baseline resource usage...
:: Get baseline memory
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do (
set /a BASELINE_FREE_MB=%%a/1024
)
echo Free RAM before: %BASELINE_FREE_MB% MB
echo Baseline free RAM: %BASELINE_FREE_MB% MB >> "%LOG_FILE%"
:: Count rfcp processes
set RFCP_COUNT=0
for /f %%a in ('tasklist /FI "IMAGENAME eq rfcp-server.exe" 2^>nul ^| find /c "rfcp-server"') do set RFCP_COUNT=%%a
echo RFCP processes: %RFCP_COUNT%
echo Baseline RFCP processes: %RFCP_COUNT% >> "%LOG_FILE%"
echo. >> "%LOG_FILE%"
:: ===========================================
:: TEST 1: Health check
:: ===========================================
echo.
echo [TEST 1] Health check...
echo === TEST 1: Health Check === >> "%LOG_FILE%"
curl -s -o nul -w "HTTP %%{http_code}\n" %API%/api/health
curl -s -w "HTTP %%{http_code}" %API%/api/health >> "%LOG_FILE%"
echo. >> "%LOG_FILE%"
:: ===========================================
:: TEST 2: System info
:: ===========================================
echo.
echo [TEST 2] Backend system info:
echo === TEST 2: Backend System Info === >> "%LOG_FILE%"
curl -s %API%/api/system/info
curl -s %API%/api/system/info >> "%LOG_FILE%"
echo.
echo. >> "%LOG_FILE%"
:: ===========================================
:: TEST 3: Fast preset
:: ===========================================
echo.
echo [TEST 3] Coverage - Fast preset (2km, 500m res)
echo Expected: ^< 1 second
echo === TEST 3: Fast Preset === >> "%LOG_FILE%"
:: Capture start memory
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a START_FREE=%%a/1024
set START_TIME=%time%
curl -s -w "\nTime: %%{time_total}s | HTTP: %%{http_code}" ^
-X POST %API%/api/coverage/calculate ^
-H "Content-Type: application/json" ^
-d "{\"sites\": [{\"lat\": 50.45, \"lon\": 30.52, \"height\": 30, \"power\": 43, \"gain\": 15, \"frequency\": 1800}], \"settings\": {\"radius\": 2000, \"resolution\": 500, \"preset\": \"fast\"}}" ^
-o "%RESULTS_DIR%\coverage-fast.json"
set END_TIME=%time%
:: Capture end memory
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a END_FREE=%%a/1024
set /a MEM_USED=START_FREE-END_FREE
echo.
echo Memory delta: %MEM_USED% MB
echo Time: %START_TIME% - %END_TIME% >> "%LOG_FILE%"
echo Memory delta: %MEM_USED% MB >> "%LOG_FILE%"
echo. >> "%LOG_FILE%"
:: ===========================================
:: TEST 4: Standard preset
:: ===========================================
echo.
echo [TEST 4] Coverage - Standard preset (5km, 300m res)
echo Expected: 30-45 seconds
echo === TEST 4: Standard Preset === >> "%LOG_FILE%"
:: Monitor resources during test
echo Starting resource monitor...
start /b cmd /c "for /l %%i in (1,1,120) do (for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory" 2^>nul') do echo [%%i] Free: %%a KB >> "%RESULTS_DIR%\monitor-standard.log") & timeout /t 1 /nobreak >nul 2>&1"
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a START_FREE=%%a/1024
curl -s -w "\nTime: %%{time_total}s | HTTP: %%{http_code}" ^
-X POST %API%/api/coverage/calculate ^
-H "Content-Type: application/json" ^
-d "{\"sites\": [{\"lat\": 50.45, \"lon\": 30.52, \"height\": 30, \"power\": 43, \"gain\": 15, \"frequency\": 1800}], \"settings\": {\"radius\": 5000, \"resolution\": 300, \"preset\": \"standard\"}}" ^
-o "%RESULTS_DIR%\coverage-standard.json"
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a END_FREE=%%a/1024
set /a MEM_USED=START_FREE-END_FREE
set /a PEAK_FROM_BASELINE=BASELINE_FREE_MB-END_FREE
echo.
echo Memory delta: %MEM_USED% MB (peak from baseline: %PEAK_FROM_BASELINE% MB)
echo Memory delta: %MEM_USED% MB >> "%LOG_FILE%"
:: Count RFCP processes
for /f %%a in ('tasklist /FI "IMAGENAME eq rfcp-server.exe" 2^>nul ^| find /c "rfcp-server"') do set RFCP_COUNT=%%a
echo RFCP processes: %RFCP_COUNT%
echo RFCP processes: %RFCP_COUNT% >> "%LOG_FILE%"
echo. >> "%LOG_FILE%"
:: ===========================================
:: TEST 5: Detailed preset (the big one!)
:: ===========================================
echo.
echo [TEST 5] Coverage - Detailed preset (5km, 300m res)
echo Expected: ^< 90 seconds (was 300s timeout)
echo THIS IS THE VECTORIZATION TEST!
echo === TEST 5: Detailed Preset (VECTORIZATION TEST) === >> "%LOG_FILE%"
:: Start intensive resource monitor
echo Starting intensive resource monitor (every 2s)...
start /b cmd /c "for /l %%i in (1,1,180) do (for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory" 2^>nul') do echo [%%i] Free: %%a KB >> "%RESULTS_DIR%\monitor-detailed.log") & timeout /t 2 /nobreak >nul 2>&1"
:: CPU monitor (approximate via tasklist)
start /b cmd /c "for /l %%i in (1,1,180) do (for /f "skip=2 tokens=5" %%c in ('tasklist /FI "IMAGENAME eq rfcp-server.exe" /FO LIST 2^>nul ^| findstr "Mem"') do echo [%%i] RFCP Mem: %%c >> "%RESULTS_DIR%\monitor-rfcp.log") & timeout /t 2 /nobreak >nul 2>&1"
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a START_FREE=%%a/1024
set START_DETAIL=%time%
echo Start time: %START_DETAIL%
curl -s -w "\nTime: %%{time_total}s | HTTP: %%{http_code}" ^
-X POST %API%/api/coverage/calculate ^
-H "Content-Type: application/json" ^
-d "{\"sites\": [{\"lat\": 50.45, \"lon\": 30.52, \"height\": 30, \"power\": 43, \"gain\": 15, \"frequency\": 1800}], \"settings\": {\"radius\": 5000, \"resolution\": 300, \"preset\": \"detailed\"}}" ^
-o "%RESULTS_DIR%\coverage-detailed.json" ^
2>&1
set END_DETAIL=%time%
echo End time: %END_DETAIL%
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a END_FREE=%%a/1024
set /a MEM_USED=START_FREE-END_FREE
set /a PEAK_FROM_BASELINE=BASELINE_FREE_MB-END_FREE
echo.
echo Memory delta: %MEM_USED% MB (peak from baseline: %PEAK_FROM_BASELINE% MB)
echo Start: %START_DETAIL% >> "%LOG_FILE%"
echo End: %END_DETAIL% >> "%LOG_FILE%"
echo Memory delta: %MEM_USED% MB >> "%LOG_FILE%"
:: Check result
if exist "%RESULTS_DIR%\coverage-detailed.json" (
findstr /C:"timeout" "%RESULTS_DIR%\coverage-detailed.json" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
echo RESULT: TIMEOUT - Vectorization didn't help enough
echo RESULT: TIMEOUT >> "%LOG_FILE%"
) else (
findstr /C:"points" "%RESULTS_DIR%\coverage-detailed.json" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
echo RESULT: SUCCESS - Calculation completed!
echo RESULT: SUCCESS >> "%LOG_FILE%"
:: Extract point count
for /f "tokens=2 delims=:" %%a in ('findstr /C:"count" "%RESULTS_DIR%\coverage-detailed.json"') do (
echo Points calculated: %%a
echo Points: %%a >> "%LOG_FILE%"
)
) else (
echo RESULT: ERROR - Check JSON file
echo RESULT: ERROR >> "%LOG_FILE%"
)
)
)
:: ===========================================
:: POST-TEST CLEANUP CHECK
:: ===========================================
echo.
echo [CLEANUP] Checking post-test state...
echo === POST-TEST CLEANUP === >> "%LOG_FILE%"
timeout /t 3 /nobreak >nul
:: Count RFCP processes
for /f %%a in ('tasklist /FI "IMAGENAME eq rfcp-server.exe" 2^>nul ^| find /c "rfcp-server"') do set RFCP_COUNT=%%a
echo RFCP processes after test: %RFCP_COUNT%
echo RFCP processes after: %RFCP_COUNT% >> "%LOG_FILE%"
:: Memory recovery
for /f %%a in ('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"') do set /a FINAL_FREE=%%a/1024
set /a MEM_NOT_FREED=BASELINE_FREE_MB-FINAL_FREE
echo Free RAM now: %FINAL_FREE% MB (baseline was: %BASELINE_FREE_MB% MB)
echo Memory not freed: %MEM_NOT_FREED% MB
echo Final free RAM: %FINAL_FREE% MB >> "%LOG_FILE%"
echo Memory not freed: %MEM_NOT_FREED% MB >> "%LOG_FILE%"
if %MEM_NOT_FREED% GTR 500 (
echo WARNING: Possible memory leak - %MEM_NOT_FREED% MB not freed!
echo WARNING: Memory leak detected >> "%LOG_FILE%"
)
if %RFCP_COUNT% GTR 1 (
echo WARNING: Multiple RFCP processes still running!
echo WARNING: Multiple processes >> "%LOG_FILE%"
)
:: ===========================================
:: SUMMARY
:: ===========================================
echo.
echo ============================================
echo TEST SUMMARY
echo ============================================
echo.
echo Results saved to: %RESULTS_DIR%
echo Log file: %LOG_FILE%
echo.
echo Files created:
echo - coverage-fast.json
echo - coverage-standard.json
echo - coverage-detailed.json
echo - monitor-standard.log (memory during standard)
echo - monitor-detailed.log (memory during detailed)
echo - monitor-rfcp.log (rfcp process memory)
echo.
echo === SUMMARY === >> "%LOG_FILE%"
echo Test completed: %date% %time% >> "%LOG_FILE%"
echo ============================================
pause