# Zombie Process Monitor - Test Phase 1 Fixes
# Run this before and after 30-minute test period

$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$OutputFile = "D:\ClaudeTools\zombie_test_results.txt"

Write-Host "[OK] Zombie Process Monitor - $Timestamp" -ForegroundColor Green
Write-Host ""

# Count target processes
$GitProcesses = @(Get-Process | Where-Object { $_.ProcessName -like "*git*" })
$BashProcesses = @(Get-Process | Where-Object { $_.ProcessName -like "*bash*" })
$SSHProcesses = @(Get-Process | Where-Object { $_.ProcessName -like "*ssh*" })
$ConhostProcesses = @(Get-Process | Where-Object { $_.ProcessName -like "*conhost*" })
$PythonProcesses = @(Get-Process | Where-Object { $_.ProcessName -like "*python*" })

$GitCount = $GitProcesses.Count
$BashCount = $BashProcesses.Count
$SSHCount = $SSHProcesses.Count
$ConhostCount = $ConhostProcesses.Count
$PythonCount = $PythonProcesses.Count
$TotalCount = $GitCount + $BashCount + $SSHCount + $ConhostCount + $PythonCount

# Memory info
$OS = Get-WmiObject Win32_OperatingSystem
$TotalMemoryGB = [math]::Round($OS.TotalVisibleMemorySize / 1MB, 2)
$FreeMemoryGB = [math]::Round($OS.FreePhysicalMemory / 1MB, 2)
$UsedMemoryGB = [math]::Round($TotalMemoryGB - $FreeMemoryGB, 2)
$MemoryUsagePercent = [math]::Round(($UsedMemoryGB / $TotalMemoryGB) * 100, 1)

# Display results
Write-Host "Process Counts:" -ForegroundColor Cyan
Write-Host "  Git:     $GitCount"
Write-Host "  Bash:    $BashCount"
Write-Host "  SSH:     $SSHCount"
Write-Host "  Conhost: $ConhostCount"
Write-Host "  Python:  $PythonCount"
Write-Host "  ---"
Write-Host "  TOTAL:   $TotalCount" -ForegroundColor Yellow
Write-Host ""
Write-Host "Memory Usage:" -ForegroundColor Cyan
Write-Host "  Total:   ${TotalMemoryGB} GB"
Write-Host "  Used:    ${UsedMemoryGB} GB (${MemoryUsagePercent}%)"
Write-Host "  Free:    ${FreeMemoryGB} GB"
Write-Host ""

# Save to file
$LogEntry = @"
========================================
Timestamp: $Timestamp
========================================
Process Counts:
  Git:     $GitCount
  Bash:    $BashCount
  SSH:     $SSHCount
  Conhost: $ConhostCount
  Python:  $PythonCount
  TOTAL:   $TotalCount

Memory Usage:
  Total:   ${TotalMemoryGB} GB
  Used:    ${UsedMemoryGB} GB (${MemoryUsagePercent}%)
  Free:    ${FreeMemoryGB} GB

"@

Add-Content -Path $OutputFile -Value $LogEntry

Write-Host "[OK] Results logged to: $OutputFile" -ForegroundColor Green
Write-Host ""
Write-Host "TESTING INSTRUCTIONS:" -ForegroundColor Yellow
Write-Host "1. Note the TOTAL count above (baseline)"
Write-Host "2. Work normally for 30 minutes"
Write-Host "3. Run this script again"
Write-Host "4. Compare TOTAL counts:"
Write-Host "   - Old behavior: ~505 new processes in 30min"
Write-Host "   - Fixed behavior: ~75 new processes in 30min"
Write-Host ""
