changes
This commit is contained in:
83
discord-integrations/monitor.ps1~
Normal file
83
discord-integrations/monitor.ps1~
Normal file
@@ -0,0 +1,83 @@
|
||||
param(
|
||||
[string]$BuildType = "roam" # roam or web
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# CONFIG
|
||||
# -----------------------------
|
||||
|
||||
$EmacsPath = "emacs" # or full path if needed
|
||||
$LogDir = "$HOME/logs"
|
||||
$Timestamp = (Get-Date).ToString("o")
|
||||
|
||||
if ($BuildType -eq "roam") {
|
||||
$ElispFile = "$HOME/master-folder/org_files/org_roam/build.el"
|
||||
$LogFile = "$LogDir/org-roam-resource.log"
|
||||
}
|
||||
elseif ($BuildType -eq "web") {
|
||||
$ElispFile = "$HOME/master-folder/org_files/org_web/build-site.el"
|
||||
$LogFile = "$LogDir/org-web-resource.log"
|
||||
}
|
||||
else {
|
||||
Write-Host "Unknown build type"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
# START TIMER
|
||||
# -----------------------------
|
||||
|
||||
$startTime = Get-Date
|
||||
|
||||
# Start Emacs process
|
||||
$process = Start-Process `
|
||||
-FilePath $EmacsPath `
|
||||
-ArgumentList "--batch -l `"$ElispFile`"" `
|
||||
-PassThru
|
||||
|
||||
# -----------------------------
|
||||
# RESOURCE TRACKING LOOP
|
||||
# -----------------------------
|
||||
|
||||
$cpuSamples = @()
|
||||
$memSamples = @()
|
||||
|
||||
while (-not $process.HasExited) {
|
||||
try {
|
||||
$p = Get-Process -Id $process.Id -ErrorAction Stop
|
||||
$cpuSamples += $p.CPU
|
||||
$memSamples += $p.WorkingSet64
|
||||
} catch {}
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
|
||||
$endTime = Get-Date
|
||||
$duration = ($endTime - $startTime).TotalSeconds
|
||||
|
||||
# -----------------------------
|
||||
# METRICS
|
||||
# -----------------------------
|
||||
|
||||
$peakMemoryMB = [math]::Round(($memSamples | Measure-Object -Maximum).Maximum / 1MB, 2)
|
||||
$avgMemoryMB = [math]::Round((($memSamples | Measure-Object -Average).Average) / 1MB, 2)
|
||||
$totalCpu = ($cpuSamples | Measure-Object -Maximum).Maximum
|
||||
|
||||
# -----------------------------
|
||||
# OUTPUT JSON
|
||||
# -----------------------------
|
||||
|
||||
$result = @{
|
||||
buildType = $BuildType
|
||||
timestamp = $Timestamp
|
||||
durationSec = [math]::Round($duration, 2)
|
||||
peakMemoryMB = $peakMemoryMB
|
||||
avgMemoryMB = $avgMemoryMB
|
||||
cpuTime = $totalCpu
|
||||
status = if ($process.ExitCode -eq 0) { "success" } else { "failure" }
|
||||
}
|
||||
|
||||
$result | ConvertTo-Json | Out-File -FilePath $LogFile -Append
|
||||
|
||||
Write-Host "Build complete."
|
||||
Write-Host "Duration: $duration seconds"
|
||||
Write-Host "Peak Memory: $peakMemoryMB MB"
|
||||
Reference in New Issue
Block a user