Skip to content

cirrus: setup WSL logging #25882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ podman_machine_windows_task:
Get-Volume
main_script: ".\\repo\\contrib\\cirrus\\win-podman-machine-main.ps1"
always:
wsl_logs_artifacts:
path: ./*.zip
# Required for `contrib/cirrus/logformatter` to work properly
html_artifacts:
path: ./*.html
Expand Down
80 changes: 80 additions & 0 deletions contrib/cirrus/win-collect-wsl-logs-start.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#Requires -RunAsAdministrator

[CmdletBinding()]
Param (
$LogProfile = $null
)

Set-StrictMode -Version Latest

$folder = "WslLogs" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
mkdir -p $folder | Out-Null

if ($LogProfile -eq $null -Or ![System.IO.File]::Exists($LogProfile))
{
if ($LogProfile -eq $null)
{
$url = "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl.wprp"
}
elseif ($LogProfile -eq "storage")
{
$url = "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_storage.wprp"
}
else
{
Write-Error "Unknown log profile: $LogProfile"
exit 1
}

$LogProfile = "$folder/wsl.wprp"
try {
Invoke-WebRequest -UseBasicParsing $url -OutFile $LogProfile
}
catch {
throw
}
}

reg.exe export HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss $folder/HKCU.txt 2>&1 | Out-Null
reg.exe export HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Lxss $folder/HKLM.txt 2>&1 | Out-Null
reg.exe export HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\P9NP $folder/P9NP.txt 2>&1 | Out-Null
reg.exe export HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2 $folder/Winsock2.txt 2>&1 | Out-Null
reg.exe export "HKEY_CLASSES_ROOT\CLSID\{e66b0f30-e7b4-4f8c-acfd-d100c46c6278}" $folder/wslsupport-proxy.txt 2>&1 | Out-Null
reg.exe export "HKEY_CLASSES_ROOT\CLSID\{a9b7a1b9-0671-405c-95f1-e0612cb4ce7e}" $folder/wslsupport-impl.txt 2>&1 | Out-Null
Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" > $folder/windows-version.txt

Get-Service wslservice -ErrorAction Ignore | Format-list * -Force > $folder/wslservice.txt

$wslconfig = "$env:USERPROFILE/.wslconfig"
if (Test-Path $wslconfig)
{
Copy-Item $wslconfig $folder | Out-Null
}

get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux -ErrorAction Ignore > $folder/appxpackage.txt
get-acl "C:\ProgramData\Microsoft\Windows\WindowsApps" -ErrorAction Ignore | Format-List > $folder/acl.txt
Get-WindowsOptionalFeature -Online > $folder/optional-components.txt
bcdedit.exe > $folder/bcdedit.txt

$uninstallLogs = "$env:TEMP/wsl-uninstall-logs.txt"
if (Test-Path $uninstallLogs)
{
Copy-Item $uninstallLogs $folder | Out-Null
}

$wprOutputLog = "$folder/wpr.txt"

wpr.exe -start $LogProfile -filemode 2>&1 >> $wprOutputLog
if ($LastExitCode -Ne 0)
{
Write-Host -ForegroundColor Yellow "Log collection failed to start (exit code: $LastExitCode), trying to reset it."
wpr.exe -cancel 2>&1 >> $wprOutputLog

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

Write-Host "WSL Log collection is running."
16 changes: 16 additions & 0 deletions contrib/cirrus/win-collect-wsl-logs-stop.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Requires -RunAsAdministrator

Set-StrictMode -Version Latest

# get the directory that has a name that starts with WslLogs
$folder = Get-ChildItem -Directory | Where-Object { $_.Name -like "WslLogs*" } | Select-Object -First 1
$wprOutputLog = "$folder/wpr.txt"

Write-Host "Saving WSL logs..."
wpr.exe -stop $folder/logs.etl 2>&1 >> $wprOutputLog

$logArchive = "$(Resolve-Path $folder).zip"
Compress-Archive -Path $folder -DestinationPath $logArchive
Remove-Item $folder -Recurse

Write-Host -ForegroundColor Green "Logs saved in: $logArchive"
1 change: 1 addition & 0 deletions contrib/cirrus/win-lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function Run-Command {

if ($Env:CIRRUS_CI -eq "true") {
Invoke-Logformatter $unformattedLog
$PSScriptRoot\win-collect-wsl-logs-stop.ps1
}

Check-Exit 2 "'$command'" "$exitCode"
Expand Down
2 changes: 2 additions & 0 deletions contrib/cirrus/win-podman-machine-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ $Env:TMPDIR = 'Z:\'
$Env:TMP = 'Z:\'
$Env:TEMP = 'Z:\'

$PSScriptRoot\win-collect-wsl-logs-start.ps1

Write-Host "`nRunning podman-machine e2e tests"
Run-Command ".\winmake localmachine"