Skip to content

Commit cd8bd55

Browse files
rayfoRaymond Fowkes
andauthored
Substantial refinements to Network Tracing / NetBlame Plug-in (#45)
* Fix link to (releases) * Better find XPerf.exe, Handle 0x80071069, etc. * Substantial refinements to NetBlame WPA Network add-in v1.6.0 --------- Co-authored-by: Raymond Fowkes <REFowkes@frontier.com>
1 parent 9e3db58 commit cd8bd55

29 files changed

Lines changed: 1977 additions & 864 deletions

src/BETA/GetSymbols.bat

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ REM Licensed under the MIT License.
66
REM Download symbols based on those referenced in the given ETW log file (.etl).
77
REM Optionally limit downloads to the given modules (faster).
88
REM EnvVar OVerbose=1 : report commands executed
9+
REM EnvVar WPT_PATH : find XPerf here
910

1011
setlocal
1112

@@ -37,6 +38,9 @@ call :SetSymDir
3738
if not defined _NT_SYMBOL_PATH set _NT_SYMBOL_PATH=%SYMPATH_DFT%
3839
if not defined _NT_SYMCACHE_PATH set _NT_SYMCACHE_PATH=%SYMCACHE_DFT%
3940

41+
if defined WPT_PATH set path=%WPT_PATH:"=%;%path%
42+
if defined OVerbose echo XPERF: & where xperf & echo:
43+
4044
REM Older versions of XPerf.exe copy PDB files to the current directory, which will be _SYMDIR.
4145

4246
pushd "%_SYMDIR%"
@@ -50,7 +54,7 @@ echo:
5054

5155
rem XPerf.exe is often adjacent to WPA.exe, or available in the ADK / Windows Performance Toolkit: https://aka.ms/adk
5256

53-
set _filter=findstr /r "bytes.*SYMSRV.*RESULT..0x00000000"
57+
set _filter=findstr /r /c:"[0-9] bytes -"
5458
set _filter1=2^>^&1 ^| %_filter%
5559
set _filter2=2^^^>^^^&1 ^^^| %_filter%
5660

@@ -230,4 +234,10 @@ echo Download all referenced modules, or (faster) the modules listed and depende
230234
echo See: https://github.com/microsoft/MSO-Scripts/wiki/Advanced-Symbols#deeper
231235
echo See: https://github.com/microsoft/MSO-Scripts/wiki/Symbol-Resolution#native
232236
echo See: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/xperf/symbols
237+
echo:
238+
echo Optional Environment Variables:
239+
echo _NT_SYMBOL_PATH=cache*%SystemDrive%\Symbols;srv*https://msdl.microsoft.com/download/symbols
240+
echo _NT_SYMCACHE_PATH=%SystemDrive%\SymCache
241+
echo WPT_PATH=^<path containing XPerf.exe^> (no quotes)
242+
echo OVerbose=1 (diagnostic output)
233243
exit /b 1

src/BETA/TraceNetwork.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ Param ( # $ViewerParams 'parameter splat'
377377
# Case 2: Do not proceed.
378378

379379
Write-Err "Found an older version of the Windows Performance Analyzer (WPA): $Version"
380+
Write-Err "`"$WpaPath`""
380381
Write-Err "The minimum version for this analysis is: $VersionMinForAddin"
381382
WriteWPTInstallMessage "WPA.exe"
382383
exit 1
@@ -390,9 +391,9 @@ Param ( # $ViewerParams 'parameter splat'
390391
$ExtraParams = $Null
391392
$Processors = $Null
392393

393-
if (!$Version -or ($Version -ge $VersionForProcessors) -or !$WpaPath.EndsWith('.exe'))
394+
if (!$Version -or !(IsRealVersion $Version) -or ($Version -ge $VersionForProcessors))
394395
{
395-
# Required for WPA.bat or WPA.exe v11.8+ to bypass the New WPA Launcher
396+
# Required for WPA.bat or WindowsApps\WPA.exe (stub) or WPA.exe v11.8+ to bypass the New WPA Launcher.
396397
$Processors = GetPluginsList $Version
397398
$ExtraParams += GetArgs -processors $Processors
398399
}

src/INCLUDE.WPA.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function LaunchAsStandardUser
402402
$ArgList = $ArgList -replace '(?<!\\)"', "'"
403403
}
404404

405-
Write-Status "Launching WPA as Standard User (non-Admin):`n" $ProcessCommand.FilePath $ArgList
405+
Write-Status "Launching as Standard User (non-Admin):`n" $ProcessCommand.FilePath $ArgList
406406

407407
ResetError
408408
$ErrorDefault = "Failed to run: $($Args[0])"
@@ -467,7 +467,7 @@ Param(
467467
# If the viewer command is WPA.bat or something other than WPA.exe or "WPA.exe", don't maximize that window.
468468
if ($Viewer.TrimEnd('"') -notlike '*.exe') { $ProcessCommand.WindowStyle = "Minimized" }
469469

470-
Write-Status "Launching WPA as Current User."
470+
Write-Status "Launching as Current User."
471471

472472
ResetError
473473
$Process = $Null
@@ -496,7 +496,7 @@ function BackgroundResolveSymbols
496496
Param (
497497
[string]$ETL
498498
)
499-
$XPerfPath = GetWptExePath 'XPerf.exe' -silent
499+
$XPerfPath = GetWptExePath 'XPerf.exe' -TestRun -Shallow
500500

501501
if (!$XPerfPath)
502502
{
@@ -524,7 +524,7 @@ Param (
524524
$XPerfCmd = "`"$XPerfPath`" -tle -tti -i `"$ETL`" -symbols verbose -a symcache -build"
525525
$XPerfCmdEnv = "$(ReplaceEnv $XPerfPath) -tle -tti -i $(ReplaceEnv $ETL) -symbols verbose -a symcache -build"
526526

527-
$OutFilter = <# $XPerfCmd #> '2>&1 | findstr /r "bytes.*SYMSRV.*RESULT..0x00000000"'
527+
$OutFilter = <# $XPerfCmd #> '2>&1 | findstr /r /c:"[0-9] bytes -"'
528528
$XPerfFiltered = "$XPerfCmd $OutFilter"
529529
$XPerfFilterEnv = "$XPerfCmdEnv $OutFilter"
530530

src/INCLUDE.ps1

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ function HandleChangeThreadMode
728728
{
729729
Write-Err "Windows Performance Recorder (WPR): Internal COM Error"
730730
Write-Warn "This issue usually resolves by restarting Windows."
731-
Write-Warn "If this occurs frequently, make sure that you have a very recent version of WPR:`n"
731+
Write-Warn "If this occurs frequently, make sure that you have a very recent version of WPR."
732+
if (!$script:WPR_PreWin10) { Write-Warn "The current version is: $script:WPR_Win10Ver" }
733+
Write-Warn 'https://devblogs.microsoft.com/performance-diagnostics/wpr-start-and-stop-commands/#:~:text=0x80010106'
732734
WriteWPTInstallMessage "WPR.exe"
733735
}
734736

@@ -872,6 +874,28 @@ Param (
872874
}
873875

874876

877+
<#
878+
0x80071069: The instance name passed was not recognized as valid by a WMI data provider.
879+
#>
880+
function HandleAbortedTrace
881+
{
882+
Param (
883+
$WprParams
884+
)
885+
Write-Err (GetCmdVerbose $script:WPR_Path $WprParams)
886+
887+
Write-Err "`nWPR returned error 0x80071069: The instance name passed was not recognized as valid by a WMI data provider.`n"
888+
889+
Write-Warn "This sometimes means that there is not enough space on the disk for the .ETL log file."
890+
Write-Warn "Intermediate trace files are stored here:"
891+
Write-Warn "`"$env:TRACE_PATH`""
892+
Write-Warn
893+
Write-Warn "Try running 'cleanmgr' or clearing space on the disk."
894+
Write-Warn "Or set the TRACE_PATH environment variable to a folder on another drive."
895+
Write-Warn "Or simply try again to capture the trace using -Loop : TraceCPU Start -Loop ..."
896+
}
897+
898+
875899
<#
876900
Use WMI (deprecated after PSv2) to return the SID of the logged-on user for the current Windows Session.
877901
Return: $Null if failure; $False if it's unchanged from the current context; [string]SID if success.
@@ -1865,17 +1889,19 @@ Param (
18651889

18661890
if ($TestRun)
18671891
{
1892+
# Skip stray, obviously old installations.
1893+
$fileVer = GetFileVersion $ExePath
1894+
if ($fileVer -and ($fileVer.Major -lt [Environment]::OSVersion.Version.Major))
1895+
{
1896+
Write-Status "Found old v$fileVer at: $ExePath"
1897+
return $False
1898+
}
1899+
18681900
try
18691901
{
18701902
$Null = & $ExePath -? 2>$Null | Out-Null # silent mode for PSv2+
1871-
if ($?) { $TestRun = $False } # Success!
18721903
}
18731904
catch
1874-
{
1875-
# Do not flag success.
1876-
}
1877-
1878-
if ($TestRun)
18791905
{
18801906
Write-Status "Test run failed: $ExePath"
18811907
return $False
@@ -1906,23 +1932,26 @@ Param (
19061932
Get the full path of the given executable from the Windows Performance Toolkit: WPA.exe, WPR.exe, etc.
19071933
This path can be customized with the WPT_PATH environment variable. ($Env:WPT_PATH may get cleared if it is invalid.)
19081934
ISSUE Win10/11+: WPR.exe exists in: $Env:windir\system32\wpr.exe Should this script search for another (newer?) version?
1935+
Consider Win10 installed with: WPR v10.0.19041 This is subject to: Error 0x80010106
1936+
https://devblogs.microsoft.com/performance-diagnostics/wpr-start-and-stop-commands/#:~:text=0x80010106
19091937
#>
19101938
function GetWptExePath
19111939
{
19121940
Param (
19131941
[string]$Exe,
19141942
[switch]$Silent,
1943+
[switch]$Shallow,
19151944
[switch]$AltPath,
19161945
[switch]$TestRun
19171946
)
1918-
# Test the optional environment variable
1947+
# Test the optional environment variable. (Use the binary found on this path if at all possible.)
19191948
# This is set by the user. All others are set by the system or by an installer.
19201949

19211950
if ($env:WPT_PATH)
19221951
{
19231952
$WptPath = $env:WPT_PATH.Trim('"').TrimEnd('\')
19241953
$WptPath = "$WptPath\$Exe"
1925-
if (TestExePath $WptPath $TestRun ([ref]$AltPath)) { return $WptPath }
1954+
if (TestExePath $WptPath -TestRun:$False ([ref]$AltPath)) { return $WptPath }
19261955

19271956
# Sanity check: If $env:WPT_PATH does not exist then reset is to null for this script.
19281957
if (!(Test-Path -PathType container -Path $env:WPT_PATH -ErrorAction:SilentlyContinue)) { $env:WPT_PATH = $Null }
@@ -1931,9 +1960,9 @@ Param (
19311960
# Test Windows Apps (not executable stubs)
19321961

19331962
# $Exe should exist in the folder registered under WPA.exe
1934-
$PathReg = $Null
1963+
$WptPath = $PathReg = $Null
19351964
$WpaOpenPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\wpa.exe"
1936-
$WptPath = GetRegistryValue $WpaOpenPath "Path"
1965+
if (!$Shallow) { $WptPath = GetRegistryValue $WpaOpenPath "Path" }
19371966
if ($WptPath)
19381967
{
19391968
$WptPath = $PathReg = "$WptPath\$Exe"
@@ -1970,10 +1999,14 @@ Param (
19701999

19712000
# App store paths require Admin privilege to walk, unless you land directly on the app folder.
19722001
# Look up the path of the app folder(s) via the registry.
2002+
# This may only work for WPA.
19732003

1974-
$WildPath = 'Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\Microsoft.WindowsPerformanceAnalyzer*'
1975-
[string[]] $RegPaths = Get-Item -Path $WildPath -ErrorAction:SilentlyContinue
1976-
2004+
[string[]]$RegPaths = $Null
2005+
if (!$Shallow)
2006+
{
2007+
$WildPath = 'Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\Microsoft.WindowsPerformanceAnalyzer*'
2008+
$RegPaths = Get-Item -Path $WildPath -ErrorAction:SilentlyContinue
2009+
}
19772010
foreach ($RegPath in $RegPaths)
19782011
{
19792012
$Path = GetRegistryValue "Registry::$RegPath" 'PackageRootFolder'
@@ -1989,11 +2022,10 @@ Param (
19892022

19902023
# Test the system path, which may include WindowsApps (executable stubs, NO VERSION)
19912024

1992-
$PathApps= $Null
19932025
$WptCmd = Get-Command -TotalCount 1 -CommandType Application $Exe -ErrorAction:SilentlyContinue
1994-
if ($WptCmd)
2026+
foreach ($Cmd in $WptCmd)
19952027
{
1996-
$WptPath = $PathApps = $WptCmd.Path
2028+
$WptPath = $PathApps = $Cmd.Path
19972029
if (TestExePath $WptPath $TestRun ([ref]$AltPath)) { return $WptPath }
19982030
}
19992031

@@ -2002,7 +2034,7 @@ Param (
20022034
if ($Env:LOCALAPPDATA)
20032035
{
20042036
$WptPath = "$Env:LOCALAPPDATA\Microsoft\WindowsApps\$Exe"
2005-
if (($WptPath -ne $PathApps) -and (TestExePath $WptPath $TestRun ([ref]$AltPath))) { return $WptPath }
2037+
if (!($WptCmd -contains $WptPath) -and (TestExePath $WptPath $TestRun ([ref]$AltPath))) { return $WptPath }
20062038
}
20072039

20082040
# Try the Side-by-Side path for WPR
@@ -3211,6 +3243,18 @@ Param (
32113243
return [ResultValue]::Error
32123244
}
32133245

3246+
0x80071069 # The instance name passed was not recognized as valid by a WMI data provider.
3247+
{
3248+
HandleAbortedTrace $WprParams
3249+
3250+
Write-Msg "`nCanceling..."
3251+
$Null = InvokeWPR -Cancel -InstanceName $InstanceName
3252+
3253+
ListRunningProfiles
3254+
3255+
return [ResultValue]::Error
3256+
}
3257+
32143258
default
32153259
{
32163260
Write-Err $script:WPR_Path @WprParams

0 commit comments

Comments
 (0)