@@ -581,6 +581,7 @@ $WindowsSDKBuilds = @($WindowsSDKArchitectures | ForEach-Object {
581
581
# # Helpers for logging and timing build steps.
582
582
583
583
$TimingData = New-Object System.Collections.Generic.List[System.Object ]
584
+ $CurrentOperation = $null
584
585
585
586
function Add-TimingData {
586
587
param
@@ -589,16 +590,86 @@ function Add-TimingData {
589
590
[Hashtable ] $Platform ,
590
591
[Parameter (Mandatory )]
591
592
[string ] $BuildStep ,
592
- [Parameter (Mandatory )]
593
- [System.TimeSpan ] $ElapsedTime
593
+ [PSCustomObject ] $Parent = $null
594
594
)
595
595
596
- $TimingData .Add ( [PSCustomObject ]@ {
596
+ $TimingEntry = [PSCustomObject ]@ {
597
597
Arch = $Platform.Architecture.LLVMName
598
598
Platform = $Platform.OS.ToString ()
599
599
" Build Step" = $BuildStep
600
- " Elapsed Time" = $ElapsedTime
601
- })
600
+ " Elapsed Time" = [TimeSpan ]::Zero
601
+ " Child Time" = [TimeSpan ]::Zero
602
+ Parent = $Parent
603
+ Children = @ ()
604
+ }
605
+
606
+ if ($Parent ) {
607
+ $Parent.Children += $TimingEntry
608
+ }
609
+
610
+ $TimingData.Add ($TimingEntry )
611
+ return $TimingEntry
612
+ }
613
+
614
+ function Record-OperationTime {
615
+ param
616
+ (
617
+ [Parameter (Mandatory )]
618
+ [Hashtable ] $Platform ,
619
+ [Parameter (Mandatory )]
620
+ [string ] $BuildStep ,
621
+ [Parameter (Mandatory )]
622
+ [ScriptBlock ] $ScriptBlock
623
+ )
624
+ if (! $Summary ) {
625
+ & $ScriptBlock
626
+ return
627
+ }
628
+
629
+ $Stopwatch = [Diagnostics.Stopwatch ]::StartNew()
630
+ $TimingEntry = Add-TimingData $Platform $BuildStep $script :CurrentOperation
631
+ $script :CurrentOperation = $TimingEntry
632
+
633
+ try {
634
+ & $ScriptBlock
635
+ } finally {
636
+ $Stopwatch.Stop ()
637
+ $TimingEntry ." Elapsed Time" = $Stopwatch.Elapsed
638
+ if ($TimingEntry.Parent ) {
639
+ $TimingEntry.Parent ." Child Time" = $TimingEntry.Parent ." Child Time" .Add($Stopwatch.Elapsed )
640
+ }
641
+ $script :CurrentOperation = $TimingEntry.Parent
642
+ }
643
+ }
644
+
645
+ function Flatten-TimingEntry {
646
+ param (
647
+ [Parameter (Mandatory )]
648
+ [PSCustomObject ] $Entry ,
649
+ [Parameter (Mandatory )]
650
+ [TimeSpan ] $TotalTime ,
651
+ [int ] $Depth = 0
652
+ )
653
+
654
+ $Indent = " " * $Depth
655
+ $Percentage = [math ]::Round(($Entry ." Elapsed Time" .TotalSeconds / $TotalTime.TotalSeconds ) * 100 , 1 )
656
+ $FormattedTime = " {0:hh\:mm\:ss\.ff}" -f $Entry ." Elapsed Time"
657
+ $SelfTime = $Entry ." Elapsed Time" .Subtract($Entry ." Child Time" )
658
+ $FormattedSelfTime = " {0:hh\:mm\:ss\.ff}" -f $SelfTime
659
+
660
+ [PSCustomObject ]@ {
661
+ " Total Time" = $FormattedTime
662
+ " Self Time" = $FormattedSelfTime
663
+ " %" = " $Percentage %"
664
+ " Build Step" = " $Indent $ ( $Entry .' Build Step' ) "
665
+ Platform = $Entry.Platform
666
+ Arch = $Entry.Arch
667
+ }
668
+
669
+ $SortedChildren = $Entry.Children | Sort-Object - Descending - Property " Elapsed Time"
670
+ foreach ($Child in $SortedChildren ) {
671
+ Flatten- TimingEntry $Child $TotalTime ($Depth + 1 )
672
+ }
602
673
}
603
674
604
675
function Write-Summary {
@@ -611,31 +682,27 @@ function Write-Summary {
611
682
612
683
$TotalTime = [TimeSpan ]::Zero
613
684
foreach ($Entry in $TimingData ) {
614
- $TotalTime = $TotalTime.Add ($Entry ." Elapsed Time" )
615
- }
616
-
617
- $SortedData = $TimingData | ForEach-Object {
618
- $Percentage = [math ]::Round(($_ .(" Elapsed Time" ).TotalSeconds / $TotalTime.TotalSeconds ) * 100 , 1 )
619
- $FormattedTime = " {0:hh\:mm\:ss\.ff}" -f $_ ." Elapsed Time"
620
- [PSCustomObject ]@ {
621
- " Build Step" = $_ ." Build Step"
622
- Platform = $_.Platform
623
- Arch = $_.Arch
624
- " Elapsed Time" = $FormattedTime
625
- " %" = " $Percentage %"
685
+ if (-not $Entry.Parent ) {
686
+ $TotalTime = $TotalTime.Add ($Entry ." Elapsed Time" )
626
687
}
627
- } | Sort-Object - Descending - Property " Elapsed Time"
688
+ }
689
+
690
+ $RootEntries = $TimingData | Where-Object { -not $_.Parent } | Sort-Object - Descending - Property " Elapsed Time"
691
+ $Result = foreach ($RootEntry in $RootEntries ) {
692
+ Flatten- TimingEntry $RootEntry $TotalTime
693
+ }
628
694
629
695
$FormattedTotalTime = " {0:hh\:mm\:ss\.ff}" -f $TotalTime
630
696
$TotalRow = [PSCustomObject ]@ {
697
+ " Total Time" = $FormattedTotalTime
698
+ " Self Time" = $FormattedTotalTime
699
+ " %" = " 100.0%"
631
700
" Build Step" = " TOTAL"
632
701
Platform = " "
633
702
Arch = " "
634
- " Elapsed Time" = $FormattedTotalTime
635
- " %" = " 100.0%"
636
703
}
637
704
638
- @ ($SortedData ) + $TotalRow | Format-Table - AutoSize
705
+ @ ($Result ) + $TotalRow | Format-Table - AutoSize
639
706
}
640
707
641
708
function Get-AndroidNDK {
@@ -720,10 +787,6 @@ function Invoke-BuildStep {
720
787
[Object []] $RemainingArgs
721
788
)
722
789
723
- if ($Summary ) {
724
- $Stopwatch = [Diagnostics.Stopwatch ]::StartNew()
725
- }
726
-
727
790
$SplatArgs = @ {}
728
791
if ($RemainingArgs ) {
729
792
$Enumerator = $RemainingArgs.GetEnumerator ()
@@ -750,10 +813,8 @@ function Invoke-BuildStep {
750
813
}
751
814
}
752
815
753
- & $Name $Platform @SplatArgs
754
-
755
- if ($Summary ) {
756
- Add-TimingData $Platform $Name $Stopwatch.Elapsed
816
+ Record- OperationTime $Platform $Name {
817
+ & $Name $Platform @SplatArgs
757
818
}
758
819
}
759
820
@@ -1044,7 +1105,7 @@ function Invoke-VsDevShell([Hashtable] $Platform) {
1044
1105
}
1045
1106
}
1046
1107
1047
- function Get-Dependencies {
1108
+ function Get-Dependencies-Impl {
1048
1109
Write-Host " [$ ( [DateTime ]::Now.ToString(" yyyy-MM-dd HH:mm:ss" )) ] Get-Dependencies ..." - ForegroundColor Cyan
1049
1110
$ProgressPreference = " SilentlyContinue"
1050
1111
@@ -1285,8 +1346,11 @@ function Get-Dependencies {
1285
1346
Write-Host - ForegroundColor Cyan " [$ ( [DateTime ]::Now.ToString(" yyyy-MM-dd HH:mm:ss" )) ] Get-Dependencies took $ ( $Stopwatch.Elapsed ) "
1286
1347
Write-Host " "
1287
1348
}
1288
- if ($Summary ) {
1289
- Add-TimingData $BuildPlatform " Get-Dependencies" $Stopwatch.Elapsed
1349
+ }
1350
+
1351
+ function Get-Dependencies {
1352
+ Record- OperationTime $BuildPlatform " Get-Dependencies" {
1353
+ Get-Dependencies - Impl
1290
1354
}
1291
1355
}
1292
1356
0 commit comments