Skip to content

Commit 4465517

Browse files
remove profiling
1 parent 2b67016 commit 4465517

File tree

1 file changed

+0
-85
lines changed

1 file changed

+0
-85
lines changed

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

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,11 @@ function Get-CIPPTenantAlignment {
2424
[Parameter(Mandatory = $false)]
2525
[string]$TemplateId
2626
)
27-
28-
# Initialize overall stopwatch
29-
$OverallStopwatch = [System.Diagnostics.Stopwatch]::StartNew()
30-
$SectionTimings = @{}
31-
32-
# Measure template table initialization
33-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
3427
$TemplateTable = Get-CippTable -tablename 'templates'
3528
$TemplateFilter = "PartitionKey eq 'StandardsTemplateV2'"
3629
$TenantGroups = Get-TenantGroups
37-
$sw.Stop()
38-
$SectionTimings['TemplateTableInit'] = $sw.ElapsedMilliseconds
39-
Write-Verbose "Template table initialization took: $($sw.ElapsedMilliseconds)ms"
4030

4131
try {
42-
# Measure template loading
43-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
4432
# Get all standard templates
4533
$Templates = (Get-CIPPAzDataTableEntity @TemplateTable -Filter $TemplateFilter) | ForEach-Object {
4634
$JSON = $_.JSON
@@ -56,18 +44,12 @@ function Get-CIPPTenantAlignment {
5644
$Data
5745
}
5846
}
59-
$sw.Stop()
60-
$SectionTimings['TemplateLoading'] = $sw.ElapsedMilliseconds
61-
Write-Verbose "Template loading took: $($sw.ElapsedMilliseconds)ms"
62-
Write-Information "Loaded $($Templates.Count) templates in $($sw.ElapsedMilliseconds)ms"
6347

6448
if (-not $Templates) {
6549
Write-Warning 'No templates found matching the criteria'
6650
return @()
6751
}
6852

69-
# Measure standards data retrieval
70-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
7153
# Get standards comparison data
7254
$StandardsTable = Get-CippTable -TableName 'CippStandardsReports'
7355
#this if statement is to bring down performance when running scheduled checks, we have to revisit this to a better query due to the extreme size this can get.
@@ -77,13 +59,7 @@ function Get-CIPPTenantAlignment {
7759
$filter = "PartitionKey ne 'StandardReport' and PartitionKey ne ''"
7860
}
7961
$AllStandards = Get-CIPPAzDataTableEntity @StandardsTable -Filter $filter
80-
$sw.Stop()
81-
$SectionTimings['StandardsDataRetrieval'] = $sw.ElapsedMilliseconds
82-
Write-Verbose "Standards data retrieval took: $($sw.ElapsedMilliseconds)ms"
83-
Write-Information "Retrieved $($AllStandards.Count) standards records in $($sw.ElapsedMilliseconds)ms"
8462

85-
# Measure tenant filtering
86-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
8763
# Filter by tenant if specified
8864
$Standards = if ($TenantFilter) {
8965
$AllStandards
@@ -92,12 +68,6 @@ function Get-CIPPTenantAlignment {
9268
$AllStandards | Where-Object { $_.PartitionKey -in $Tenants.defaultDomainName }
9369
}
9470
$TagTemplates = Get-CIPPAzDataTableEntity @TemplateTable
95-
$sw.Stop()
96-
$SectionTimings['TenantFiltering'] = $sw.ElapsedMilliseconds
97-
Write-Verbose "Tenant filtering and tag template loading took: $($sw.ElapsedMilliseconds)ms"
98-
99-
# Measure tenant data structure building
100-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
10171
# Build tenant standards data structure
10272
$tenantData = @{}
10373
foreach ($Standard in $Standards) {
@@ -125,32 +95,16 @@ function Get-CIPPTenantAlignment {
12595
}
12696
}
12797
$TenantStandards = $tenantData
128-
$sw.Stop()
129-
$SectionTimings['TenantDataStructureBuilding'] = $sw.ElapsedMilliseconds
130-
Write-Verbose "Tenant data structure building took: $($sw.ElapsedMilliseconds)ms"
131-
Write-Information "Built data structure for $($tenantData.Count) tenants in $($sw.ElapsedMilliseconds)ms"
13298

13399
$Results = [System.Collections.Generic.List[object]]::new()
134100

135-
# Measure template processing
136-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
137-
$TemplateProcessingCount = 0
138-
$TemplateSectionTimings = @{
139-
TenantScopeSetup = 0
140-
StandardsDataExtraction = 0
141-
StandardsSetBuilding = 0
142-
TenantComparison = 0
143-
}
144101
# Process each template against all tenants
145102
foreach ($Template in $Templates) {
146-
$TemplateProcessingCount++
147103
$TemplateStandards = $Template.standards
148104
if (-not $TemplateStandards) {
149105
continue
150106
}
151107

152-
# Measure tenant scope setup
153-
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
154108
# Check if template has tenant assignments (scope)
155109
$TemplateAssignedTenants = @()
156110
$AppliestoAllTenants = $false
@@ -173,11 +127,7 @@ function Get-CIPPTenantAlignment {
173127
} else {
174128
$AppliestoAllTenants = $true
175129
}
176-
$swTemplate.Stop()
177-
$TemplateSectionTimings.TenantScopeSetup += $swTemplate.ElapsedMilliseconds
178130

179-
# Measure standards data extraction
180-
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
181131
$StandardsData = foreach ($StandardKey in $TemplateStandards.PSObject.Properties.Name) {
182132
$StandardConfig = $TemplateStandards.$StandardKey
183133
$StandardId = "standards.$StandardKey"
@@ -247,11 +197,7 @@ function Get-CIPPTenantAlignment {
247197
}
248198
}
249199
}
250-
$swTemplate.Stop()
251-
$TemplateSectionTimings.StandardsDataExtraction += $swTemplate.ElapsedMilliseconds
252200

253-
# Measure standards set building
254-
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
255201
$AllStandards = $StandardsData.StandardId
256202
$AllStandardsArray = @($AllStandards)
257203
$ReportingDisabledStandards = ($StandardsData | Where-Object { -not $_.ReportingEnabled }).StandardId
@@ -262,11 +208,7 @@ function Get-CIPPTenantAlignment {
262208
foreach ($item in $TemplateAssignedTenants) { [void]$set.Add($item) }
263209
$set
264210
} else { $null }
265-
$swTemplate.Stop()
266-
$TemplateSectionTimings.StandardsSetBuilding += $swTemplate.ElapsedMilliseconds
267211

268-
# Measure tenant comparison processing
269-
$swTemplate = [System.Diagnostics.Stopwatch]::StartNew()
270212
foreach ($TenantName in $TenantStandards.Keys) {
271213
# Check tenant scope with HashSet and cache tenant data
272214
if (-not $AppliestoAllTenants) {
@@ -389,34 +331,7 @@ function Get-CIPPTenantAlignment {
389331

390332
$Results.Add($Result)
391333
}
392-
$swTemplate.Stop()
393-
$TemplateSectionTimings.TenantComparison += $swTemplate.ElapsedMilliseconds
394-
}
395-
$sw.Stop()
396-
$SectionTimings['TemplateProcessing'] = $sw.ElapsedMilliseconds
397-
Write-Verbose "Template processing took: $($sw.ElapsedMilliseconds)ms for $TemplateProcessingCount templates"
398-
Write-Information "Processed $TemplateProcessingCount templates in $($sw.ElapsedMilliseconds)ms"
399-
400-
# Output template sub-section timings
401-
Write-Verbose 'Template processing breakdown:'
402-
Write-Information 'Template processing breakdown:'
403-
foreach ($Section in $TemplateSectionTimings.GetEnumerator() | Sort-Object Value -Descending) {
404-
$Percentage = if ($sw.ElapsedMilliseconds -gt 0) { [math]::Round(($Section.Value / $sw.ElapsedMilliseconds) * 100, 2) } else { 0 }
405-
Write-Verbose " $($Section.Key): $($Section.Value)ms ($Percentage%)"
406-
Write-Information " $($Section.Key): $($Section.Value)ms ($Percentage%)"
407-
}
408-
409-
# Output timing summary
410-
$OverallStopwatch.Stop()
411-
Write-Information '=== Get-CIPPTenantAlignment Performance Summary ==='
412-
Write-Information "Total execution time: $($OverallStopwatch.ElapsedMilliseconds)ms"
413-
Write-Verbose 'Section timings:'
414-
foreach ($Section in $SectionTimings.GetEnumerator() | Sort-Object Value -Descending) {
415-
$Percentage = [math]::Round(($Section.Value / $OverallStopwatch.ElapsedMilliseconds) * 100, 2)
416-
Write-Verbose " $($Section.Key): $($Section.Value)ms ($Percentage%)"
417-
Write-Information " $($Section.Key): $($Section.Value)ms ($Percentage%)"
418334
}
419-
Write-Information '========================================'
420335

421336
return $Results
422337
} catch {

0 commit comments

Comments
 (0)