Skip to content

Commit b68d903

Browse files
Add initial script and step to SmokeTest job to analyze dependencies and package sizes
Provides a more human readible way to understand our package sizes and dependencies against a baseline blank application See more info in #3600 for potential improvements
1 parent 36ccb53 commit b68d903

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

SmokeTests/SmokeTestAnalysis.ps1

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
$ErrorActionPreference = "Stop"
2+
$ProgressPreference="SilentlyContinue"
3+
4+
Write-Host "Running Smoke Test Package Analyis"
5+
Write-Host "----------------------------------"
6+
7+
# Our script is at our SmokeTest root, we want to look for the AppPackages folder
8+
$PackagePath = $PSScriptRoot + "\AppPackages\"
9+
$FilePattern = "SmokeTest_{0}_x86_bundle.msixupload"
10+
$BaselineName = $FilePattern -f "UWPBaseline"
11+
$TempFolder = "ExplodedArchive"
12+
13+
function Expand-MsixUploadPackage {
14+
param (
15+
[string]$PackageFile,
16+
[string]$Destination
17+
)
18+
19+
$ZipUpload = $PackageFile.Replace("msixupload", "zip")
20+
21+
Move-Item $PackageFile -Destination $ZipUpload
22+
23+
Expand-Archive $ZipUpload -DestinationPath $Destination
24+
25+
Move-Item $ZipUpload -Destination $PackageFile
26+
27+
Push-Location $Destination
28+
29+
$Bundle = (Get-ChildItem "*.msixbundle").Name
30+
$ZipBundle = $Bundle.Replace("msixbundle", "zip")
31+
32+
Move-Item $Bundle -Destination $ZipBundle
33+
34+
Expand-Archive $ZipBundle -DestinationPath .
35+
36+
Remove-Item $ZipBundle
37+
38+
$msix = (Get-ChildItem "*.msix").Name
39+
$ZipMSIX = $msix.Replace("msix", "zip")
40+
41+
Move-Item $msix -Destination $ZipMSIX
42+
43+
Expand-Archive $ZipMSIX -DestinationPath . -Force # Force here as we have some duplicate file names we don't really care about from parent archives
44+
45+
Remove-Item $ZipMSIX
46+
47+
Pop-Location
48+
}
49+
50+
if (Test-Path $PackagePath)
51+
{
52+
Push-Location $PackagePath
53+
54+
Write-Host "Extracting Baseline..."
55+
56+
# TODO: Theoretically we could grab bits from the bin directory instead of having to expand each package, not sure about what we ignore though
57+
Expand-MsixUploadPackage $BaselineName -Destination $TempFolder
58+
59+
# Get all the base file info only (grab stuff in directories but not the directories themselves)
60+
$BaselineFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Exclude "SmokeTest*"
61+
$SmokeTestFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Include "SmokeTest*"
62+
63+
$BaselineFootprint = ($BaselineFiles | Measure-Object -Property Length -sum).Sum + ($SmokeTestFiles | Measure-Object -Property Length -sum).Sum
64+
Write-Host ("Baseline Footprint: {0:n0} bytes" -f $BaselineFootprint)
65+
Write-Host "-----------------------------------------"
66+
67+
$PackageList = Get-ChildItem "$PackagePath*.msixupload" -Exclude $BaselineName
68+
69+
#$i = 0
70+
foreach ($Package in $PackageList)
71+
{
72+
#Write-Progress -Id 0 -Activity "Comparing Against Baseline..." -Status "Prepping Package" -PercentComplete (($i++ / $PackageList.count)*100) -CurrentOperation $Package.Name
73+
74+
# Make sure we've cleaned-up the last archive
75+
Remove-Item $TempFolder -Recurse -Force
76+
77+
#$ProgressPreference="SilentlyContinue"
78+
Expand-MsixUploadPackage $Package.Name -Destination $TempFolder
79+
#$ProgressPreference="Continue"
80+
81+
[System.Collections.ArrayList]$PackageFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Exclude "SmokeTest*"
82+
$PackageSmokeTestFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Include "SmokeTest*"
83+
84+
# TODO: Make function or regex better to extra package name more easily based on a template string at the top or something...
85+
Write-Host ("{0} Additional Footprint: {1:n0} bytes" -f $Package.Name.substring(10, $Package.Name.Length - 32), (($PackageFiles | Measure-Object -Property Length -sum).Sum + ($PackageSmokeTestFiles | Measure-Object -Property Length -sum).Sum - $BaselineFootprint))
86+
87+
# Quick check on the base exe file/symbols differences
88+
foreach ($file in $SmokeTestFiles)
89+
{
90+
$match = $null
91+
$match = $PackageSmokeTestFiles | Where-Object {$_.Extension -eq $file.Extension}
92+
if ($null -ne $match)
93+
{
94+
Write-Host (" App Diff: ({0}) = {1:n0}" -f $file.Extension, ($match.Length - $file.Length)) -ForegroundColor DarkCyan
95+
}
96+
}
97+
98+
#$j = 0
99+
foreach ($file in $BaselineFiles)
100+
{
101+
#Write-Progress -Id 1 -ParentId 0 -Activity "Comparing Against Baseline..." -Status "Comparing Package" -PercentComplete (($j++ / $BaselineFiles.count)*100) -CurrentOperation $file.Name
102+
103+
$match = $null
104+
$match = $PackageFiles | Where-Object {$_.Name -eq $file.Name}
105+
if ($null -ne $match)
106+
{
107+
# File was in baseline, but has a different size
108+
if ($match.Length -ne $file.Length)
109+
{
110+
Write-Host (" Size Diff: {0} = {1:n0}" -f $file.Name, ($match.Length - $file.Length)) -ForegroundColor Magenta
111+
}
112+
113+
# Remove checked files (performance) and also remaining are new
114+
$PackageFiles.Remove($match)
115+
}
116+
}
117+
118+
# List remaining (new) files to this package
119+
foreach ($file in $PackageFiles)
120+
{
121+
Write-Host (" Additional: {0} = {1:n0}" -f $file.Name, $file.Length) -ForegroundColor Yellow
122+
}
123+
124+
# TODO: Especially if we add comparison to the main branch, we should format as an actual table and colorize via VT: https://stackoverflow.com/a/49038815/8798708
125+
126+
#Write-Progress -Id 1 -ParentId 0 -Activity "Comparing Against Baseline..." -Completed
127+
Write-Host "-----------------------------------------"
128+
Write-Host
129+
}
130+
131+
#Write-Progress -Id 0 -Activity "Comparing Against Baseline..." -Completed
132+
133+
# Clean-up
134+
Remove-Item $TempFolder -Recurse -Force
135+
136+
Pop-Location
137+
}
138+
else
139+
{
140+
Write-Error "Path $PackagePath not found for analysis!"
141+
}

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ jobs:
127127
pathToPublish: $(build.artifactstagingdirectory)\SmokeTestBundles
128128
artifactType: container
129129
artifactName: SmokeTestBundles
130+
131+
- powershell: .\SmokeTests\SmokeTestAnalysis.ps1
132+
displayName: Analyze Package Sizes

0 commit comments

Comments
 (0)