$ErrorActionPreference = "Stop" $reportDir = Join-Path $PSScriptRoot "reports" $htmlReport = Join-Path $reportDir "frontend-performance-report.html" $csvPrefix = Join-Path $reportDir "frontend-performance" $pendingFile = Join-Path $reportDir "frontend_performance_pending.txt" New-Item -ItemType Directory -Path $reportDir -Force | Out-Null $locust = Get-Command locust -ErrorAction SilentlyContinue if ($null -eq $locust) { @( "ServicePilot 前端性能测试未执行", "原因:当前环境未安装 Locust 命令。", "安装命令:pip install -r requirements.txt", "执行命令:powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1", "预期输出:reports/frontend-performance-report.html 与 reports/frontend-performance_*.csv" ) | Set-Content -Path $pendingFile -Encoding UTF8 Write-Host "Locust 未安装,已生成待执行说明:$pendingFile" exit 1 } & $locust.Source -f "$PSScriptRoot\locustfile_frontend.py" ` --host "http://127.0.0.1:4301" ` --headless ` -u 30 ` -r 5 ` -t 3m ` --html "$htmlReport" ` --csv "$csvPrefix"