| 1 | <# |
| 2 | .SYNOPSIS |
| 3 | Runs benchmark-build.ps1 across several unity-build batch sizes. |
| 4 | |
| 5 | .DESCRIPTION |
| 6 | For each batch size the project is reconfigured, stale unity sources are removed, |
| 7 | and a full benchmark run is performed. Labels are "<Prefix>-<name>", where a batch |
| 8 | size of 0 is labelled "nounity". |
| 9 | |
| 10 | .EXAMPLE |
| 11 | powershell tools\benchmarking\run-unity-batch-sweep.ps1 -Prefix split-before |
| 12 | |
| 13 | .EXAMPLE |
| 14 | powershell tools\benchmarking\run-unity-batch-sweep.ps1 -Prefix wslc -SourceDir test\windows\wslc |
| 15 | #> |
| 16 | [CmdletBinding()] |
| 17 | param( |
| 18 | [Parameter(Mandatory = $true)][string]$Prefix, |
| 19 | [int[]]$BatchSizes = @(0, 2, 4, 8), |
| 20 | [int]$FullBuilds = 10, |
| 21 | [int]$IncrementalBuilds = 100, |
| 22 | [string]$Config = 'debug', |
| 23 | [string]$Target = 'wsltests', |
| 24 | [string]$TargetDir = 'test\windows', |
| 25 | [string]$SourceDir, |
| 26 | [string]$UnityVariable = 'WSL_UNITY_BATCH_SIZE' |
| 27 | ) |
| 28 | |
| 29 | $ErrorActionPreference = 'Stop' |
| 30 | |
| 31 | $repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
| 32 | Push-Location $repoRoot |
| 33 | try |
| 34 | { |
| 35 | if (-not $SourceDir) { $SourceDir = $TargetDir } |
| 36 | |
| 37 | foreach ($batch in $BatchSizes) |
| 38 | { |
| 39 | $name = if ($batch -eq 0) { 'nounity' } else { "batch$batch" } |
| 40 | $label = "$Prefix-$name" |
| 41 | |
| 42 | Write-Host "`n########## $label ($UnityVariable=$batch) ##########" -ForegroundColor Magenta |
| 43 | |
| 44 | & cmake . "-D$UnityVariable=$batch" | Out-Null |
| 45 | if ($LASTEXITCODE -ne 0) { throw "cmake configure failed for batch size $batch." } |
| 46 | |
| 47 | # Generated unity sources are not pruned when the batch size changes, and the batch |
| 48 | # size is shared by every unity-enabled target, so clear all of them. |
| 49 | Get-ChildItem $repoRoot -Directory -Recurse -Filter Unity | |
| 50 | Where-Object { $_.Parent.Name -like '*.dir' } | |
| 51 | ForEach-Object { Remove-Item $_.FullName -Recurse -Force } |
| 52 | |
| 53 | & cmake . "-D$UnityVariable=$batch" | Out-Null |
| 54 | if ($LASTEXITCODE -ne 0) { throw "cmake reconfigure failed for batch size $batch." } |
| 55 | |
| 56 | & powershell -NoProfile -File (Join-Path $PSScriptRoot 'benchmark-build.ps1') ` |
| 57 | -Label $label -FullBuilds $FullBuilds -IncrementalBuilds $IncrementalBuilds ` |
| 58 | -Config $Config -Target $Target -TargetDir $TargetDir -SourceDir $SourceDir |
| 59 | if ($LASTEXITCODE -ne 0) { throw "Benchmark failed for $label." } |
| 60 | } |
| 61 | |
| 62 | Write-Host "`n########## SWEEP COMPLETE ($Prefix) ##########" -ForegroundColor Green |
| 63 | } |
| 64 | finally |
| 65 | { |
| 66 | Pop-Location |
| 67 | } |