Skip to content

Commit efe1b4c

Browse files
rayfoRaymond Fowkes
andauthored
Find the necessary version of WPA and the NetBlame plug-in (NetBlameAddIn.dll) (#40)
* Improve how WPA.exe and NetBlameAddIn.dll are found, with updated version requirements. * Clearer warnings --------- Co-authored-by: Raymond Fowkes <[email protected]>
1 parent 4d82b61 commit efe1b4c

File tree

3 files changed

+163
-56
lines changed

3 files changed

+163
-56
lines changed

src/BETA/TraceNetwork.ps1

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,56 @@ $script:PSScriptParams = $script:PSBoundParameters # volatile
148148

149149
. "$ScriptRootPath\INCLUDE.ps1"
150150

151-
$VersionMinForAddin = [Version]'11.0.7' # This version and later use SDK v1.0.7+
152-
$VersionForProcessors = [Version]'11.8.0' # Version 11.8.262 and later requires: -Processors (Earlier versions allow it.)
151+
$VersionMinForAddin = [Version]'11.7.383' # This public WPA version and later use SDK v1.2.2+
152+
$VersionForProcessors = [Version]'11.8.0' # WPA Version 11.8.262 and later requires: -Processors (Earlier versions allow it.)
153153

154-
$AddInPath = "$script:ScriptHomePath\ADDIN" # Uses SDK v1.0.7+
154+
$AddInPaths = @(
155+
"$script:ScriptHomePath\ADDIN" # Released ZIP with NetBlame Plug-in
156+
"$script:ScriptRootPath\NetBlame\bin\*" # Cloned project with built NetBlame Plug-in
157+
)
155158

156159
$WPA_Version_RegPath = "$script:RegPathStatus\WPA-Plugin" # $RegPathStatus also used for SetProfileStartTime, etc.
157160

158161
# Most modern versions of WPA list/accept these plug-in names via: WPA -listplugins -addsearchdir MSO-Scripts\BETA\ADDIN
159162
$ETW_Plugins_Default = 'Event Tracing for Windows','Office_NetBlame'
160163

161164

165+
<#
166+
Find the path that contains the most recent (or 'Release') NetBlame plug-in: NetBlameAddIn.dll
167+
If this installation was downloaded and unzipped from the Release site, then it will be in: BETA\ADDIN
168+
If this installation was cloned and built then it will be in NetBlame\bin\Release|Debug\net8.0
169+
#>
170+
function GetAddinPath
171+
{
172+
# List the various path(s) which contain NetBlameAddIn.dll
173+
174+
$moduleName = 'NetBlameAddIn.dll'
175+
$paths = Resolve-Path -Path $AddInPaths -ErrorAction:SilentlyContinue
176+
$pathIOs = $paths | ForEach-Object { Get-ChildItem -Path $_ -Filter $moduleName -File -Recurse -ErrorAction:SilentlyContinue }
177+
178+
if (!$pathIOs)
179+
{
180+
Write-Err "The `"NetBlame`" WPA Plug-in ($moduleName) was not be found at any of these locations:"
181+
foreach ($path in $AddInPaths) { Write-Err "`t$path" }
182+
foreach ($path in $paths) { Write-Err "`t$($path.Path)" }
183+
184+
Write-Info "Please see: https://github.com/Microsoft/MSO-Scripts/wiki/Network-Activity"
185+
186+
# No reason to go on!
187+
exit 1
188+
}
189+
190+
# Choose the path which contains the most recent NetBlameAddIn.dll, or a recent 'Release' version.
191+
$pathIORel = $pathIOs | Where-Object { $_.FullName -like '*Release*' }
192+
if ($pathIORel) { $pathIOs = $pathIORel } # filter to 'Release' version(s)
193+
$pathIO = $pathIOs | Sort-Object { $_.LastWriteTime } -Descending | Select-Object -First 1
194+
$path = (Split-Path -Path $pathIO.FullName -Parent)
195+
196+
Write-Status "NetBlame Plug-in found at: $path"
197+
return $path
198+
}
199+
200+
162201
<#
163202
Return a quoted, comma-separated string of WPA Plug-ins needed for this script.
164203
Usually: "Event Tracing for Windows","Office_NetBlame"
@@ -168,7 +207,8 @@ function GetPluginsList
168207
Param (
169208
[Version]$WpaVersion
170209
)
171-
[string[]]$ETW_Plugins = GetRegistryValue $WPA_Version_RegPath $WpaVersion.ToString()
210+
[string[]]$ETW_Plugins = $Null
211+
if ($WpaVersion) { $ETW_Plugins = GetRegistryValue $WPA_Version_RegPath $WpaVersion.ToString() }
172212
if (!$ETW_Plugins) { $ETW_Plugins = $ETW_Plugins_Default }
173213

174214
return ($ETW_Plugins | ForEach-Object { "`"$_`"" }) -join ','
@@ -307,30 +347,38 @@ Param ( # $ViewerParams 'parameter splat'
307347
Write-Action "`nThis network analyzer plug-in will not likely work before Windows 10.`n"
308348
}
309349

310-
# The viewer: Windows Performance Analyzer (WPA)
350+
# Find the most recent version of the viewer: Windows Performance Analyzer (WPA)
351+
311352
$WpaPath = GetWptExePath "WPA.exe"
312353
$Version = GetFileVersion $WpaPath
313354

314-
if (!$Version -or ($Version -lt $VersionMinForAddin))
355+
if ((IsRealVersion $Version) -and !$env:WPT_PATH)
315356
{
316-
if ($Version)
317-
{
318-
Write-Err "Found an older version of the Windows Performance Analyzer (WPA): $Version"
319-
}
320-
elseif ($WpaPath -ne 'WPA')
321-
{
322-
Write-Err "Found an unknown version of the Windows Performance Analyzer (WPA)."
323-
}
324-
Write-Err "The minimum required version is: $VersionMinForAddin"
357+
# Find an even newer version, maybe.
325358

326-
if ($WpaPath -ne 'WPA') { WriteWPTInstallMessage "wpa.exe" } # Else GetWptExePath wrote the message
359+
$WpaPath2 = GetWptExePath "WPA.exe" -Silent -AltPath
360+
$Version2 = GetFileVersion $WpaPath2
327361

328-
if ($Version) { exit 1 } # else maybe we found WPA.bat, etc.
362+
if ($Version2 -and ($Version2 -gt $Version))
363+
{
364+
$WpaPath = $WpaPath2
365+
$Version = $Version2
366+
}
329367
}
330368

331-
if (!(Test-Path -PathType container -Path $AddInPath -ErrorAction:SilentlyContinue))
369+
<#
370+
1. Found a recent WPA
371+
2. Found an old WPA
372+
3. Found WPA.bat or stub WPA.exe without 'real' version info
373+
4. Found no WPA (but try to launch "WPA" anyway)
374+
#>
375+
if ((IsRealVersion $Version) -and ($Version -lt $VersionMinForAddin))
332376
{
333-
Write-Err "Could not find the NetBlame add-in path: $AddInPath"
377+
# Case 2: Do not proceed.
378+
379+
Write-Err "Found an older version of the Windows Performance Analyzer (WPA): $Version"
380+
Write-Err "The minimum version for this analysis is: $VersionMinForAddin"
381+
WriteWPTInstallMessage "WPA.exe"
334382
exit 1
335383
}
336384

@@ -349,7 +397,7 @@ Param ( # $ViewerParams 'parameter splat'
349397
$ExtraParams += GetArgs -processors $Processors
350398
}
351399

352-
$ExtraParams += GetArgs -addsearchdir "`"$AddInPath`"" -NoSymbols
400+
$ExtraParams += GetArgs -addsearchdir "`"$(GetAddinPath)`"" -NoSymbols
353401

354402
# Now load LaunchViewerCommand and related.
355403

src/INCLUDE.WPA.ps1

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
# if ($Host.Version.Major -gt 2) {Set-StrictMode -version latest }
1010

11+
# For earlier versions of WPA than this, suggest updating.
12+
# cf. $VersionMinForAddIn - BETA\TraceNetwork.ps1
13+
$VersionMinRecent = [Version]'11.7.383'
14+
1115
<#
1216
The default SymbolDrive needs lots of free space for caching symbol files!
1317
You can reset symbol paths, with X: as the SymbolDrive, by doing this:
@@ -133,7 +137,11 @@ Param (
133137
{
134138
$env:_NT_SYMBOL_PATH = $PdbPathDefault -replace $PDB_CACHE_FOLDER,$script:PdbCacheFolder
135139

136-
Write-Warn "Setting _NT_SYMBOL_PATH = $env:_NT_SYMBOL_PATH"
140+
if (InvokedFromCMD)
141+
{ Write-Warn "Setting _NT_SYMBOL_PATH=$env:_NT_SYMBOL_PATH" }
142+
else
143+
{ Write-Warn "Setting `$Env:_NT_SYMBOL_PATH = '$env:_NT_SYMBOL_PATH'" }
144+
137145
$DriveFreeSpace = GetDriveFreeSpace $script:SymbolDrive
138146
if ($DriveFreeSpace) { $DriveFreeSpace = "($([int]($DriveFreeSpace / 1GB)) GB Free)" }
139147
Write-Warn "NOTE: Cached symbols may consume lots of space on drive $script:SymbolDrive $DriveFreeSpace"
@@ -153,7 +161,11 @@ Param (
153161
{
154162
$env:_NT_SYMCACHE_PATH = $SymCacheDefault -replace $SYM_CACHE_FOLDER,$script:SymCacheFolder
155163

156-
Write-Warn "Setting _NT_SYMCACHE_PATH = $env:_NT_SYMCACHE_PATH"
164+
if (InvokedFromCMD)
165+
{ Write-Warn "Setting _NT_SYMCACHE_PATH=$env:_NT_SYMCACHE_PATH" }
166+
else
167+
{ Write-Warn "Setting `$Env:_NT_SYMCACHE_PATH = '$env:_NT_SYMCACHE_PATH'" }
168+
157169
Write-Warn
158170
}
159171
else
@@ -313,6 +325,8 @@ Param (
313325
# else quick exit
314326
Write-Info # End Progress
315327
$global:LastExitCode = $Process.ExitCode
328+
if (!$global:LastExitCode) { return "Early exit." }
329+
316330
$Code = ('{0:x}' -f $Process.ExitCode)
317331
Write-Status "WPA Early Exit: $Code"
318332
return "Early exit: $Code"
@@ -607,11 +621,11 @@ Param (
607621
# v10.0.15063: -TTI -ClipRundown -Symbols -SymCacheOnly -Profile ...
608622
# v10.5.16+ : -TTI -TLE -ClipRundown -Symbols -SymCacheOnly -Profile ...
609623
# v11.0.7+ : -Processors ... -AddSearchDir ... (modern add-ins)
624+
# v11.7.383 : First public version which uses SDK v1.2.2
610625

611626
$IsModernWPA = ($VersionInfo -ge [Version]'10.0.0') # -Symbols
612627
$IsSymCacheOK = ($VersionInfo -ge [Version]'10.0.15063') # -Symbols -SymCacheOnly
613628
$IsFullWPA = ($VersionInfo -ge [Version]'10.5.16') # ADK for Server 2022, or later
614-
$IsNewerWPA = ($VersionInfo -ge [Version]'11.0.7') # Works with modern add-ins
615629

616630
# Should have previously called EnsureTracePath
617631
if (!$script:TracePath) { EnsureTracePath; Write-Dbg "Trace path not set for default working folder!" }
@@ -713,21 +727,14 @@ Param (
713727
}
714728
}
715729

716-
if (!$IsNewerWPA -and $IsModernWPA)
717-
{
718-
Write-Warn "A newer Windows Performance Analizer (WPA) is available:"
719-
Write-Warn " Windows Store: https://apps.microsoft.com/detail/9n0w1b2bxgnz"
720-
Write-Warn " Windows Performance Toolkit: https://learn.microsoft.com/en-us/windows-hardware/test/wpt/"
721-
Write-Warn "Or set WPT_PATH to the folder of a more recent WPA."
722-
}
723-
724730
Write-Msg "Launching Windows Performance Analyzer (WPA) ..."
725731
WriteCmdVerbose $ViewerPath $ViewerCmd
726732

727733
[DateTime]$PreStartTime = Get-Date
728734

729735
# Launch the viewer without Admin privileges, if possible.
730736

737+
$VersionRun = $Null
731738
$Process = $Null
732739
$ErrResult = $True
733740

@@ -744,6 +751,8 @@ Param (
744751
$Process = GetRunningProcess 'WPA' $PreStartTime
745752
if ($Process)
746753
{
754+
$VersionRun = FileVersionFromFileInfo($Process.MainModule.FileVersionInfo)
755+
747756
$ErrResult = WaitForProcessResponsive $Process
748757
if ($ErrResult) { Write-Status "WPA as Standard User: $ErrResult" }
749758

@@ -777,6 +786,8 @@ Param (
777786

778787
if ($Process)
779788
{
789+
$VersionRun = FileVersionFromFileInfo($Process.MainModule.FileVersionInfo)
790+
780791
$ErrResult = WaitForProcessResponsive $Process
781792
if ($ErrResult) { Write-Status "WPA as Current User: $ErrResult" }
782793

@@ -789,6 +800,18 @@ Param (
789800
}
790801
}
791802

803+
# Test the version of the running WPA, if possible.
804+
805+
if (!(IsRealVersion $VersionRun)) { $VersionRun = $VersionInfo }
806+
if ((IsRealVersion $VersionRun) -and ($VersionRun -lt $VersionMinRecent) -and (CheckOSVersion '10.0.0'))
807+
{
808+
Write-Warn "A newer Windows Performance Analizer (WPA) is available:"
809+
Write-Warn " Windows Store: https://apps.microsoft.com/detail/9n0w1b2bxgnz"
810+
Write-Warn " Windows Performance Toolkit: https://learn.microsoft.com/en-us/windows-hardware/test/wpt/"
811+
Write-Warn "Or set WPT_PATH to the folder of a more recent WPA."
812+
Write-Warn
813+
}
814+
792815
if ($ErrResult)
793816
{
794817
Write-Err (GetCmdVerbose $ViewerPath $ViewerCmd)

0 commit comments

Comments
 (0)