Skip to content

Commit 6983a3b

Browse files
committed
utils: Cleanup timing functions in build.ps1.
1 parent 72867f3 commit 6983a3b

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

utils/build.ps1

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,40 @@ $KnownNDKs = @{
381381
}
382382
}
383383

384-
385384
$IsCrossCompiling = $HostArchName -ne $BuildArchName
386385

387386
$TimingData = New-Object System.Collections.Generic.List[System.Object]
388387

388+
function Add-TimingData {
389+
param(
390+
[Parameter(Mandatory)]
391+
[string] $Arch,
392+
[Parameter(Mandatory)]
393+
[string] $Platform,
394+
[Parameter(Mandatory)]
395+
[string] $BuildStep,
396+
[Parameter(Mandatory)]
397+
[System.TimeSpan] $ElapsedTime
398+
)
399+
400+
$TimingData.Add([PSCustomObject]@{
401+
Arch = $Arch
402+
Platform = $Platform
403+
"Build Step" = $BuildStep
404+
"Elapsed Time" = $ElapsedTime.ToString()
405+
})
406+
}
407+
408+
function Write-Summary {
409+
Write-Host "Summary:" -ForegroundColor Cyan
410+
411+
# Sort timing data by elapsed time (descending)
412+
$TimingData `
413+
| Select-Object "Build Step",Platform,Arch,"Elapsed Time" `
414+
| Sort-Object -Descending -Property "Elapsed Time" `
415+
| Format-Table -AutoSize
416+
}
417+
389418
function Get-AndroidNDK {
390419
$NDK = $KnownNDKs[$AndroidNDKVersion]
391420
if (-not $NDK) { throw "Unsupported Android NDK version" }
@@ -458,9 +487,20 @@ $WindowsSDKArchs = @($WindowsSDKs | ForEach-Object {
458487
})
459488

460489
# Build functions
461-
function Invoke-BuildStep([string]$Name) {
490+
function Invoke-BuildStep([string] $Name) {
491+
if ($Summary) {
492+
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
493+
}
494+
462495
& $Name @Args
496+
497+
if ($Summary) {
498+
Add-TimingData $BuildArch.LLVMName "Windows" ($Name -replace "Build-","") $Stopwatch.Elapsed
499+
}
463500
if ($Name.Replace("Build-", "") -eq $BuildTo) {
501+
if ($Summary) {
502+
Write-Summary
503+
}
464504
exit 0
465505
}
466506
}
@@ -732,6 +772,7 @@ function Invoke-VsDevShell($Arch) {
732772
}
733773

734774
function Get-Dependencies {
775+
Write-Host "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Fetch-Dependencies ..." -ForegroundColor Cyan
735776
$ProgressPreference = "SilentlyContinue"
736777

737778
$WebClient = New-Object Net.WebClient
@@ -949,12 +990,7 @@ function Get-Dependencies {
949990
Write-Host ""
950991
}
951992
if ($Summary) {
952-
$TimingData.Add([PSCustomObject]@{
953-
Arch = $BuildArch.LLVMName
954-
Platform = 'Windows'
955-
Checkout = 'Get-Dependencies'
956-
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
957-
})
993+
Add-TimingData $BuildArch.LLVMName "Windows" "Get-Dependencies" $Stopwatch.Elapsed
958994
}
959995
}
960996

@@ -1078,8 +1114,6 @@ function Build-CMakeProject {
10781114
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building '$Src' to '$Bin' ..."
10791115
}
10801116

1081-
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
1082-
10831117
# Enter the developer command shell early so we can resolve cmake.exe
10841118
# for version checks.
10851119
Invoke-IsolatingEnvVars {
@@ -1400,15 +1434,6 @@ function Build-CMakeProject {
14001434
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Finished building '$Src' to '$Bin' in $($Stopwatch.Elapsed)"
14011435
Write-Host ""
14021436
}
1403-
1404-
if ($Summary) {
1405-
$TimingData.Add([PSCustomObject]@{
1406-
Arch = $Arch.LLVMName
1407-
Platform = $Platform
1408-
Checkout = $Src.Replace($SourceCache, '')
1409-
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
1410-
})
1411-
}
14121437
}
14131438

14141439
enum SPMBuildAction {
@@ -1494,12 +1519,7 @@ function Build-SPMProject {
14941519
}
14951520

14961521
if ($Summary) {
1497-
$TimingData.Add([PSCustomObject]@{
1498-
Arch = $Arch.LLVMName
1499-
Checkout = $Src.Replace($SourceCache, '')
1500-
Platform = "Windows"
1501-
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
1502-
})
1522+
Add-TimingData $BuildArch.LLVMName "Windows" $Src.Replace($SourceCache, '') $Stopwatch.Elapsed
15031523
}
15041524
}
15051525

@@ -3352,6 +3372,6 @@ if (-not $IsCrossCompiling) {
33523372
exit 1
33533373
} finally {
33543374
if ($Summary) {
3355-
$TimingData | Select-Object Platform,Arch,Checkout,"Elapsed Time" | Sort-Object -Descending -Property "Elapsed Time" | Format-Table -AutoSize
3375+
Write-Summary
33563376
}
33573377
}

0 commit comments

Comments
 (0)