Skip to content

Commit 5ba5355

Browse files
extra logging
1 parent f3ebe7a commit 5ba5355

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ function Get-CIPPTenantAlignment {
134134
# Measure template processing
135135
$sw = [System.Diagnostics.Stopwatch]::StartNew()
136136
$TemplateProcessingCount = 0
137+
$TemplateSectionTimings = @{
138+
TenantScopeSetup = 0
139+
StandardsDataExtraction = 0
140+
StandardsSetBuilding = 0
141+
TenantComparison = 0
142+
}
137143
# Process each template against all tenants
138144
foreach ($Template in $Templates) {
139145
$TemplateProcessingCount++
@@ -142,6 +148,8 @@ function Get-CIPPTenantAlignment {
142148
continue
143149
}
144150

151+
# Measure tenant scope setup
152+
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
145153
# Check if template has tenant assignments (scope)
146154
$TemplateAssignedTenants = @()
147155
$AppliestoAllTenants = $false
@@ -164,7 +172,11 @@ function Get-CIPPTenantAlignment {
164172
} else {
165173
$AppliestoAllTenants = $true
166174
}
175+
$swTemplate.Stop()
176+
$TemplateSectionTimings.TenantScopeSetup += $swTemplate.ElapsedMilliseconds
167177

178+
# Measure standards data extraction
179+
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
168180
$StandardsData = foreach ($StandardKey in $TemplateStandards.PSObject.Properties.Name) {
169181
$StandardConfig = $TemplateStandards.$StandardKey
170182
$StandardId = "standards.$StandardKey"
@@ -234,7 +246,11 @@ function Get-CIPPTenantAlignment {
234246
}
235247
}
236248
}
249+
$swTemplate.Stop()
250+
$TemplateSectionTimings.StandardsDataExtraction += $swTemplate.ElapsedMilliseconds
237251

252+
# Measure standards set building
253+
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
238254
$AllStandards = $StandardsData.StandardId
239255
$AllStandardsArray = @($AllStandards)
240256
$ReportingDisabledStandards = ($StandardsData | Where-Object { -not $_.ReportingEnabled }).StandardId
@@ -245,7 +261,11 @@ function Get-CIPPTenantAlignment {
245261
foreach ($item in $TemplateAssignedTenants) { [void]$set.Add($item) }
246262
$set
247263
} else { $null }
264+
$swTemplate.Stop()
265+
$TemplateSectionTimings.StandardsSetBuilding += $swTemplate.ElapsedMilliseconds
248266

267+
# Measure tenant comparison processing
268+
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
249269
foreach ($TenantName in $TenantStandards.Keys) {
250270
# Check tenant scope with HashSet and cache tenant data
251271
if (-not $AppliestoAllTenants) {
@@ -368,12 +388,23 @@ function Get-CIPPTenantAlignment {
368388

369389
$Results.Add($Result)
370390
}
391+
$swTemplate.Stop()
392+
$TemplateSectionTimings.TenantComparison += $swTemplate.ElapsedMilliseconds
371393
}
372394
$sw.Stop()
373395
$SectionTimings['TemplateProcessing'] = $sw.ElapsedMilliseconds
374396
Write-Verbose "Template processing took: $($sw.ElapsedMilliseconds)ms for $TemplateProcessingCount templates"
375397
Write-Information "Processed $TemplateProcessingCount templates in $($sw.ElapsedMilliseconds)ms"
376398

399+
# Output template sub-section timings
400+
Write-Verbose 'Template processing breakdown:'
401+
Write-Information 'Template processing breakdown:'
402+
foreach ($Section in $TemplateSectionTimings.GetEnumerator() | Sort-Object Value -Descending) {
403+
$Percentage = if ($sw.ElapsedMilliseconds -gt 0) { [math]::Round(($Section.Value / $sw.ElapsedMilliseconds) * 100, 2) } else { 0 }
404+
Write-Verbose " $($Section.Key): $($Section.Value)ms ($Percentage%)"
405+
Write-Information " $($Section.Key): $($Section.Value)ms ($Percentage%)"
406+
}
407+
377408
# Output timing summary
378409
$OverallStopwatch.Stop()
379410
Write-Information '=== Get-CIPPTenantAlignment Performance Summary ==='

0 commit comments

Comments
 (0)