Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Lite/Services/CollectionBackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -114,6 +115,13 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

/* Periodic retention cleanup */
RunRetentionIfDue();

/* Log process memory at the end of each cycle. Lets bug reporters
self-report memory without Task Manager, gives us a continuous
memory trace for diagnosis, and surfaces regressions in the log
that would otherwise need external sampling to detect. Three
property reads — negligible overhead at 1-minute cadence. */
LogProcessMemory();
}

try
Expand Down Expand Up @@ -182,4 +190,22 @@ private void RunRetentionIfDue()
}
}

private void LogProcessMemory()
{
try
{
using var process = Process.GetCurrentProcess();
var wsMb = process.WorkingSet64 / 1024 / 1024;
var privMb = process.PrivateMemorySize64 / 1024 / 1024;
var gcMb = GC.GetTotalMemory(forceFullCollection: false) / 1024 / 1024;
_logger?.LogInformation(
"Process memory: WS={WorkingSetMb} MB, Private={PrivateMb} MB, GC heap={GcMb} MB",
wsMb, privMb, gcMb);
}
catch (Exception ex)
{
_logger?.LogDebug(ex, "Failed to read process memory stats");
}
}

}
Loading