diff --git a/allstarr/Controllers/AdminController.cs b/allstarr/Controllers/AdminController.cs index bf09ec4..ace53d4 100644 --- a/allstarr/Controllers/AdminController.cs +++ b/allstarr/Controllers/AdminController.cs @@ -8,6 +8,7 @@ using allstarr.Services.Common; using allstarr.Filters; using System.Text.Json; using System.Text.RegularExpressions; +using System.Runtime; namespace allstarr.Controllers; @@ -1901,6 +1902,52 @@ public class AdminController : ControllerBase return StatusCode(500, new { error = "Failed to import .env file", details = ex.Message }); } } + + /// + /// Gets detailed memory usage statistics for debugging. + /// + [HttpGet("memory-stats")] + public IActionResult GetMemoryStats() + { + try + { + // Force garbage collection to get accurate numbers + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + var memoryUsage = GC.GetTotalMemory(false); + var gen0 = GC.CollectionCount(0); + var gen1 = GC.CollectionCount(1); + var gen2 = GC.CollectionCount(2); + + // Get process memory info + var process = System.Diagnostics.Process.GetCurrentProcess(); + + return Ok(new { + Timestamp = DateTime.UtcNow, + GCMemoryBytes = memoryUsage, + GCMemoryMB = Math.Round(memoryUsage / (1024.0 * 1024.0), 2), + ProcessWorkingSetBytes = process.WorkingSet64, + ProcessWorkingSetMB = Math.Round(process.WorkingSet64 / (1024.0 * 1024.0), 2), + ProcessPrivateMemoryBytes = process.PrivateMemorySize64, + ProcessPrivateMemoryMB = Math.Round(process.PrivateMemorySize64 / (1024.0 * 1024.0), 2), + ProcessVirtualMemoryBytes = process.VirtualMemorySize64, + ProcessVirtualMemoryMB = Math.Round(process.VirtualMemorySize64 / (1024.0 * 1024.0), 2), + GCCollections = new { + Gen0 = gen0, + Gen1 = gen1, + Gen2 = gen2 + }, + GCMode = GCSettings.IsServerGC ? "Server" : "Workstation", + GCLatencyMode = GCSettings.LatencyMode.ToString() + }); + } + catch (Exception ex) + { + return BadRequest(new { error = ex.Message }); + } + } } public class ConfigUpdateRequest