Add a script to collect WSL logs in a loop (#41240)
* Add a script to collect WSL logs in a loop * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Blue committed
Aug 18, 2026 at 21:38 UTC
5e3e864b5ed9b38d6ca6b06871cff7b4faa17434
1 file changed
+47
diagnostics/rolling-wsl-logs.ps1
new
+47
@@ -0,0 +1,47 @@
1
+param (
2
+ [int] $PeriodSeconds = 3600,
3
+ [ValidateNotNullOrEmpty()]
4
+ [string] $Profile = (Join-Path $PSScriptRoot "wsl.wprp")
5
+)
6
+
7
+Set-StrictMode -Version Latest
8
+$ErrorActionPreference = "Stop"
9
+
10
+trap
11
+{
12
+ try { & wpr.exe -cancel | Out-Null } catch {}
13
+ throw
14
+}
15
+
16
+[console]::TreatControlCAsInput = $true
17
+
18
+
19
+Write-Host "Press any key to exit"
20
+
21
+$running = $true
22
+while($running)
23
+{
24
+ & wpr.exe -start $Profile -filemode
25
+ $rotation = (Get-Date).AddSeconds($PeriodSeconds)
26
+
27
+ while($rotation -Gt (Get-Date))
28
+ {
29
+ if ($Host.UI.RawUI.KeyAvailable)
30
+ {
31
+ $keyPressed = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyUp, IncludeKeyDown")
32
+ if ($keyPressed.KeyDown -eq "True")
33
+ {
34
+ $running = $false
35
+ Write-Host "Exiting"
36
+ break
37
+ }
38
+ }
39
+
40
+ [Threading.Thread]::Sleep(1000)
41
+ }
42
+
43
+ $file = Get-Date ($rotation.ToUniversalTime()) -UFormat '%Y-%m-%d %H-%M-%S'
44
+ $file += ".etl"
45
+ Write-Host Writing logs to $file
46
+ & wpr.exe -stop $file
47
+}
\ No newline at end of file