run_frontend_performance.ps1 1.1 KB

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