From 93d29268dd25d41481b1c6fe9b7dd313d09e0f94 Mon Sep 17 00:00:00 2001 From: Zaine Arch Date: Wed, 11 Feb 2026 17:52:11 +0000 Subject: [PATCH] changes --- discord-integrations/monitor.ps1 | 83 +++++++++++++++++++++ discord-integrations/monitor.ps1~ | 83 +++++++++++++++++++++ discord-integrations/org_logs_to_discord.py | 1 - 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 discord-integrations/monitor.ps1 create mode 100644 discord-integrations/monitor.ps1~ diff --git a/discord-integrations/monitor.ps1 b/discord-integrations/monitor.ps1 new file mode 100644 index 0000000..930195b --- /dev/null +++ b/discord-integrations/monitor.ps1 @@ -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/lisp/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" diff --git a/discord-integrations/monitor.ps1~ b/discord-integrations/monitor.ps1~ new file mode 100644 index 0000000..7b10b43 --- /dev/null +++ b/discord-integrations/monitor.ps1~ @@ -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" diff --git a/discord-integrations/org_logs_to_discord.py b/discord-integrations/org_logs_to_discord.py index 4839288..cd2d2fb 100755 --- a/discord-integrations/org_logs_to_discord.py +++ b/discord-integrations/org_logs_to_discord.py @@ -88,7 +88,6 @@ def format_ts(ts): def delete_and_recreate_log_files(): log_files = [ - CALIBRE_LOG, ROAM_LOG, WEB_LOG ]