make script run as standalone

This commit is contained in:
Catalin-Emil Fetoiu 2023-10-31 11:23:27 -07:00
parent ece79e8d59
commit da25b43756
2 changed files with 15 additions and 9 deletions

View File

@ -132,12 +132,9 @@ Install [WPR](https://learn.microsoft.com/en-us/windows-hardware/test/wpt/window
To collect WSL networking logs, do the following steps in an administrative powershell prompt: To collect WSL networking logs, do the following steps in an administrative powershell prompt:
``` ```
$ Invoke-WebRequest 'https://github.com/microsoft/WSL/archive/refs/heads/master.zip' -OutFile .\wsl.zip Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-networking-logs.ps1" -OutFile collect-networking-logs.ps1
$ Expand-Archive .\wsl.zip .\ Set-ExecutionPolicy Bypass -Scope Process -Force
$ Remove-Item .\wsl.zip .\collect-networking-logs.ps1
$ cd .\WSL-master\diagnostics
$ Set-ExecutionPolicy Bypass -Scope Process -Force
$ .\collect-networking-logs.ps1
``` ```
The script will output when log collection starts. Reproduce the problem, then press any key to stop the log collection. The script will output when log collection starts. Reproduce the problem, then press any key to stop the log collection.
The script will output the path of the log file once done. The script will output the path of the log file once done.

View File

@ -8,6 +8,13 @@ Param (
$folder = "WslNetworkingLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss") $folder = "WslNetworkingLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
mkdir -p $folder mkdir -p $folder
$logProfile = "$folder/wsl_networking.wprp"
$networkingBashScript = "$folder/networking.sh"
# Download supporting files
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_networking.wprp" -OutFile $logProfile
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/networking.sh" -OutFile $networkingBashScript
# Retrieve WSL version and wslconfig file # Retrieve WSL version and wslconfig file
get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpackage.txt get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpackage.txt
@ -18,7 +25,7 @@ if (Test-Path $wslconfig)
} }
# Collect Linux network state before the repro # Collect Linux network state before the repro
& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_before.log & wsl.exe -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_before.log
if ($RestartWslReproMode) if ($RestartWslReproMode)
{ {
@ -34,7 +41,6 @@ if ($RestartWslReproMode)
} }
# Start logging. # Start logging.
$logProfile = ".\wsl_networking.wprp"
$wprOutputLog = "$folder/wpr.txt" $wprOutputLog = "$folder/wpr.txt"
wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog
@ -123,7 +129,7 @@ finally
} }
# Collect Linux network state after the repro # Collect Linux network state after the repro
& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_after.log & wsl.exe -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_after.log
# Collect host networking state relevant for WSL # Collect host networking state relevant for WSL
# Using a try/catch for commands below, as some of them do not exist on all OS versions # Using a try/catch for commands below, as some of them do not exist on all OS versions
@ -216,6 +222,9 @@ try
} }
catch {} catch {}
Remove-Item $logProfile
Remove-Item $networkingBashScript
$logArchive = "$(Resolve-Path $folder).zip" $logArchive = "$(Resolve-Path $folder).zip"
Compress-Archive -Path $folder -DestinationPath $logArchive Compress-Archive -Path $folder -DestinationPath $logArchive
Remove-Item $folder -Recurse Remove-Item $folder -Recurse