Skip to content

Commit 87ed36a

Browse files
benhillisBen Hillis
andauthored
diagnostics: combine wprp files in a single one with profiles (#14048)
* diagnostics: combine wprp files in a single one with profiles --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent 21e60dc commit 87ed36a

File tree

9 files changed

+512
-807
lines changed

9 files changed

+512
-807
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ python3 distributions/validate.py distributions/DistributionInfo.json
173173
wpr -start diagnostics\wsl.wprp -filemode
174174
# [reproduce issue]
175175
wpr -stop logs.ETL
176+
177+
# Available profiles:
178+
# - WSL (default) - General WSL tracing
179+
# - WSL-Storage - Enhanced storage tracing
180+
# - WSL-Networking - Comprehensive networking tracing
181+
# - WSL-HvSocket - HvSocket-specific tracing
182+
# Example: wpr -start diagnostics\wsl.wprp!WSL -filemode
176183
```
177184

178185
### Log Analysis Tools

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ Set-ExecutionPolicy Bypass -Scope Process -Force
7979
```
8080
The script will output the path of the log file once done.
8181

82+
For specific scenarios, you can use different log profiles:
83+
- `.\collect-wsl-logs.ps1 -LogProfile storage` - Enhanced storage tracing
84+
- `.\collect-wsl-logs.ps1 -LogProfile networking` - Networking-focused tracing
85+
- `.\collect-wsl-logs.ps1 -LogProfile hvsocket` - HvSocket-specific tracing
86+
- `.\collect-networking-logs.ps1` - Alternative script for networking tracing
87+
8288
### 10) Reporting a Windows crash (BSOD)
8389

8490
To collect a kernel crash dump, first run the following command in an elevated command prompt:

diagnostics/collect-networking-logs.ps1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,23 @@ function Collect-WindowsNetworkState {
124124
$folder = "WslNetworkingLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
125125
mkdir -p $folder
126126

127-
$logProfile = "$folder/wsl_networking.wprp"
127+
$wprpFile = "$folder/wsl.wprp"
128+
$wprpProfile = "WSL-Networking"
128129
$networkingBashScript = "$folder/networking.sh"
129130

130131
# Detect the super user first.
131132
# Actually it's not definite that the super user is named "root". Instead, a user with uid=0 is what we are looking for. See #11693.
132133
$superUser = & wsl.exe -- id -nu 0 # user name of the super user.
133134

134135
# Copy/Download supporting files
135-
if (Test-Path "$PSScriptRoot/wsl_networking.wprp")
136+
if (Test-Path "$PSScriptRoot/wsl.wprp")
136137
{
137-
Copy-Item "$PSScriptRoot/wsl_networking.wprp" $logProfile
138+
Copy-Item "$PSScriptRoot/wsl.wprp" $wprpFile
138139
}
139140
else
140141
{
141-
Write-Host -ForegroundColor Yellow "wsl_networking.wprp not found in the current directory. Downloading it from GitHub."
142-
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_networking.wprp" -OutFile $logProfile
142+
Write-Host -ForegroundColor Yellow "wsl.wprp not found in the current directory. Downloading it from GitHub."
143+
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl.wprp" -OutFile $wprpFile
143144
}
144145

145146
if (Test-Path "$PSScriptRoot/networking.sh")
@@ -183,13 +184,13 @@ if ($RestartWslReproMode)
183184
# Start logging.
184185
$wprOutputLog = "$folder/wpr.txt"
185186

186-
wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog
187+
wpr.exe -start "$wprpFile!$wprpProfile" -filemode 2>&1 >> $wprOutputLog
187188
if ($LastExitCode -Ne 0)
188189
{
189190
Write-Host -ForegroundColor Yellow "Log collection failed to start (exit code: $LastExitCode), trying to reset it."
190191
wpr.exe -cancel 2>&1 >> $wprOutputLog
191192

192-
wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog
193+
wpr.exe -start "$wprpFile!$wprpProfile" -filemode 2>&1 >> $wprOutputLog
193194
if ($LastExitCode -Ne 0)
194195
{
195196
Write-Host -ForegroundColor Red "Couldn't start log collection (exitCode: $LastExitCode)"
@@ -309,7 +310,7 @@ if (Test-Path $setupApiPath)
309310
Copy-Item $setupApiPath $folder
310311
}
311312

312-
Remove-Item $logProfile
313+
Remove-Item $wprpFile
313314
Remove-Item $networkingBashScript
314315

315316
$logArchive = "$(Resolve-Path $folder).zip"

diagnostics/collect-wsl-logs.ps1

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,44 @@ Set-StrictMode -Version Latest
1111
$folder = "WslLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
1212
mkdir -p $folder | Out-Null
1313

14-
if ($LogProfile -eq $null -Or ![System.IO.File]::Exists($LogProfile))
14+
# Check if LogProfile is a custom file path or a profile name
15+
if ($LogProfile -ne $null -And [System.IO.File]::Exists($LogProfile))
1516
{
16-
if ($LogProfile -eq $null)
17+
# User provided a custom .wprp file path - use it directly
18+
$wprpFile = $LogProfile
19+
$wprpProfile = $null # Use default profile in the file
20+
}
21+
else
22+
{
23+
# Map log profile names to WPRP profile names
24+
$wprpProfile = "WSL"
25+
if ($LogProfile -eq "storage")
1726
{
18-
$url = "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl.wprp"
27+
$wprpProfile = "WSL-Storage"
1928
}
20-
elseif ($LogProfile -eq "storage")
29+
elseif ($LogProfile -eq "networking")
2130
{
22-
$url = "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_storage.wprp"
31+
$wprpProfile = "WSL-Networking"
2332
}
2433
elseif ($LogProfile -eq "hvsocket")
2534
{
26-
$url = "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_hvsocket.wprp"
35+
$wprpProfile = "WSL-HvSocket"
2736
}
28-
else
37+
elseif ($LogProfile -ne $null)
2938
{
30-
Write-Error "Unknown log profile: $LogProfile"
39+
Write-Error "Unknown log profile: $LogProfile. Valid options are: storage, networking, hvsocket, or a path to a custom .wprp file"
3140
exit 1
3241
}
3342

34-
$LogProfile = "$folder/wsl.wprp"
35-
try {
36-
Invoke-WebRequest -UseBasicParsing $url -OutFile $LogProfile
43+
# Use the consolidated wsl.wprp file, attempt to use local copy first.
44+
$wprpFile = "$folder/wsl.wprp"
45+
if (Test-Path "$PSScriptRoot/wsl.wprp")
46+
{
47+
Copy-Item "$PSScriptRoot/wsl.wprp" $wprpFile
3748
}
38-
catch {
39-
throw
49+
else
50+
{
51+
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl.wprp" -OutFile $wprpFile
4052
}
4153
}
4254

@@ -71,13 +83,23 @@ if (Test-Path $uninstallLogs)
7183

7284
$wprOutputLog = "$folder/wpr.txt"
7385

74-
wpr.exe -start $LogProfile -filemode 2>&1 >> $wprOutputLog
86+
# Build wpr command - if wprpProfile is set, use profile syntax, otherwise use file only
87+
if ($wprpProfile -ne $null)
88+
{
89+
$wprCommand = "$wprpFile!$wprpProfile"
90+
}
91+
else
92+
{
93+
$wprCommand = $wprpFile
94+
}
95+
96+
wpr.exe -start $wprCommand -filemode 2>&1 >> $wprOutputLog
7597
if ($LastExitCode -Ne 0)
7698
{
7799
Write-Host -ForegroundColor Yellow "Log collection failed to start (exit code: $LastExitCode), trying to reset it."
78100
wpr.exe -cancel 2>&1 >> $wprOutputLog
79101

80-
wpr.exe -start $LogProfile -filemode 2>&1 >> $wprOutputLog
102+
wpr.exe -start $wprCommand -filemode 2>&1 >> $wprOutputLog
81103
if ($LastExitCode -Ne 0)
82104
{
83105
Write-Host -ForegroundColor Red "Couldn't start log collection (exitCode: $LastExitCode)"

0 commit comments

Comments
 (0)