127 lines
4.0 KiB
PowerShell
127 lines
4.0 KiB
PowerShell
param(
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$ComfyUIPath
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Resolve-ComfyRoot {
|
|
param([string]$InputPath)
|
|
|
|
$candidates = @()
|
|
|
|
if (![string]::IsNullOrWhiteSpace($InputPath)) {
|
|
$candidates += (Resolve-Path $InputPath).Path
|
|
}
|
|
|
|
# If run from a ComfyUI root, use current directory.
|
|
$candidates += (Get-Location).Path
|
|
|
|
# If script lives under <portable-root>\scripts, parent is a likely portable root.
|
|
$scriptDir = Split-Path -Parent $MyInvocation.ScriptName
|
|
if ($scriptDir) {
|
|
$candidates += $scriptDir
|
|
$candidates += (Split-Path -Parent $scriptDir)
|
|
}
|
|
|
|
foreach ($candidate in $candidates | Select-Object -Unique) {
|
|
if ([string]::IsNullOrWhiteSpace($candidate)) {
|
|
continue
|
|
}
|
|
|
|
# Inner ComfyUI root: contains custom_nodes and user.
|
|
if ((Test-Path (Join-Path $candidate "custom_nodes")) -and (Test-Path (Join-Path $candidate "user"))) {
|
|
return @{
|
|
Root = $candidate
|
|
ComfyUI = $candidate
|
|
CrashRoot = $candidate
|
|
}
|
|
}
|
|
|
|
# Portable outer root: contains ComfyUI\custom_nodes.
|
|
$inner = Join-Path $candidate "ComfyUI"
|
|
if ((Test-Path (Join-Path $inner "custom_nodes")) -and (Test-Path (Join-Path $inner "user"))) {
|
|
return @{
|
|
Root = $candidate
|
|
ComfyUI = $inner
|
|
CrashRoot = $candidate
|
|
}
|
|
}
|
|
}
|
|
|
|
throw "Could not resolve ComfyUI root. Pass -ComfyUIPath pointing to either the ComfyUI folder or the portable folder that contains ComfyUI."
|
|
}
|
|
|
|
$paths = Resolve-ComfyRoot -InputPath $ComfyUIPath
|
|
$root = $paths.Root
|
|
$comfyRoot = $paths.ComfyUI
|
|
$crashRoot = $paths.CrashRoot
|
|
|
|
$ts = Get-Date -Format "yyyyMMdd-HHmmss"
|
|
$dump = Join-Path $crashRoot "_crashlogs\$ts"
|
|
|
|
New-Item -ItemType Directory -Path $dump -Force | Out-Null
|
|
|
|
# Copy ComfyUI log if present.
|
|
$possibleLogs = @(
|
|
(Join-Path $comfyRoot "user\comfyui.log"),
|
|
(Join-Path $comfyRoot "comfyui.log")
|
|
)
|
|
|
|
foreach ($logPath in $possibleLogs) {
|
|
if (Test-Path $logPath) {
|
|
Copy-Item $logPath (Join-Path $dump ("comfyui-" + (Split-Path $logPath -Leaf))) -Force
|
|
}
|
|
}
|
|
|
|
# Capture recent Application events.
|
|
Get-WinEvent -FilterHashtable @{
|
|
LogName = 'Application'
|
|
StartTime = (Get-Date).AddHours(-4)
|
|
} -ErrorAction SilentlyContinue |
|
|
Where-Object {
|
|
$_.Message -match 'python|Comfy|torch|cuda|nvidia|OpenCV|Application Error|Windows Error Reporting'
|
|
} |
|
|
Select-Object TimeCreated, ProviderName, Id, LevelDisplayName, Message |
|
|
Format-List |
|
|
Out-File (Join-Path $dump "windows-application-events.txt") -Encoding UTF8
|
|
|
|
# Capture recent System/GPU/driver events.
|
|
Get-WinEvent -FilterHashtable @{
|
|
LogName = 'System'
|
|
StartTime = (Get-Date).AddHours(-4)
|
|
} -ErrorAction SilentlyContinue |
|
|
Where-Object {
|
|
$_.ProviderName -match 'Display|nvlddmkm|NVIDIA|Kernel|WHEA' -or
|
|
$_.Message -match 'display driver|nvlddmkm|NVIDIA|LiveKernelEvent|hardware error|reset|virtual memory'
|
|
} |
|
|
Select-Object TimeCreated, ProviderName, Id, LevelDisplayName, Message |
|
|
Format-List |
|
|
Out-File (Join-Path $dump "windows-system-gpu-events.txt") -Encoding UTF8
|
|
|
|
# Capture current memory/pagefile state.
|
|
Get-CimInstance Win32_PageFileUsage |
|
|
Select-Object Name, AllocatedBaseSize, CurrentUsage, PeakUsage |
|
|
Format-List |
|
|
Out-File (Join-Path $dump "pagefile-usage.txt") -Encoding UTF8
|
|
|
|
Get-CimInstance Win32_OperatingSystem |
|
|
Select-Object TotalVisibleMemorySize, FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory |
|
|
Format-List |
|
|
Out-File (Join-Path $dump "memory-state.txt") -Encoding UTF8
|
|
|
|
# Optional GPU snapshot.
|
|
$nvidiaSmi = Get-Command nvidia-smi -ErrorAction SilentlyContinue
|
|
if ($nvidiaSmi) {
|
|
& nvidia-smi | Out-File (Join-Path $dump "nvidia-smi.txt") -Encoding UTF8
|
|
}
|
|
|
|
# Basic path snapshot.
|
|
@"
|
|
Resolved root: $root
|
|
Resolved ComfyUI folder: $comfyRoot
|
|
Crash output folder: $dump
|
|
"@ | Out-File (Join-Path $dump "resolved-paths.txt") -Encoding UTF8
|
|
|
|
Write-Host "Crash dump saved to: $dump"
|