Status box: show RemSound's own CPU and memory usage (held for next release)

New last status line "CPU usage 2% and memory 184 MB" — CPU as a share of the whole machine
(Task Manager style: process CPU-time delta / wall-clock / logical-core count), memory as the
working set via the same MB-to-GB formatter the totals use. Sampled on the existing once-a-second
status tick with a cached Process handle. Shows on screen and reads/copies with the rest of the
status (Ed's idea).

Held for the next release.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ednunp
2026-06-24 15:22:40 +01:00
co-authored by Claude Opus 4.8
parent be32a060e7
commit 771a358a87
3 changed files with 18 additions and 4 deletions
+16 -2
View File
@@ -269,6 +269,10 @@ public sealed class MainForm : Form
private DateTime? statusConnectedSinceUtc;
// Time of the last "speak status" hotkey press, for double-press-to-copy detection.
private DateTime lastSpeakStatusPressUtc = DateTime.MinValue;
// Process CPU-time at the last status sample, for the status box's CPU-usage line. Cached Process
// handle so the once-a-second status tick doesn't allocate a new one each time.
private TimeSpan lastStatusCpuTime;
private readonly System.Diagnostics.Process statusSelfProcess = System.Diagnostics.Process.GetCurrentProcess();
// Per-list state (used by sync helpers — was per-method in the old dialog).
private bool suppressConnectedCheck;
private bool suppressDiscoveredCheck;
@@ -3397,7 +3401,10 @@ public sealed class MainForm : Form
var nowUtc = DateTime.UtcNow;
var txBytes = sender.BytesSent;
var rxBytes = receiver.BytesReceived;
double txKbs = 0, rxKbs = 0;
statusSelfProcess.Refresh();
var cpuTime = statusSelfProcess.TotalProcessorTime;
var workingSetBytes = statusSelfProcess.WorkingSet64;
double txKbs = 0, rxKbs = 0, cpuPercent = 0;
if (lastStatusSampleUtc != DateTime.MinValue)
{
var elapsed = (nowUtc - lastStatusSampleUtc).TotalSeconds;
@@ -3405,11 +3412,17 @@ public sealed class MainForm : Form
{
txKbs = (txBytes - lastStatusTxBytes) / 1024.0 / elapsed;
rxKbs = (rxBytes - lastStatusRxBytes) / 1024.0 / elapsed;
// CPU as a share of the whole machine (the Task Manager number): the process CPU-time
// delta over wall-clock, divided by the logical-core count.
var cpuDelta = (cpuTime - lastStatusCpuTime).TotalSeconds;
cpuPercent = cpuDelta / elapsed / Math.Max(1, Environment.ProcessorCount) * 100.0;
if (cpuPercent < 0) cpuPercent = 0;
}
}
lastStatusSampleUtc = nowUtc;
lastStatusTxBytes = txBytes;
lastStatusRxBytes = rxBytes;
lastStatusCpuTime = cpuTime;
// Healthy peers from heartbeat. Map each to its display label (the user-friendly
// name from selectedPeerLabels, falling back to the address).
@@ -3473,7 +3486,8 @@ public sealed class MainForm : Form
}
sb.AppendLine($"Receiving {rxKbs:0.0} kB/s; sending {txKbs:0.0} kB/s.");
sb.Append($"Total received {FormatDataSize(receiver.BytesReceived)}; sent {FormatDataSize(sender.BytesSent)}.");
sb.AppendLine($"Total received {FormatDataSize(receiver.BytesReceived)}; sent {FormatDataSize(sender.BytesSent)}.");
sb.Append($"CPU usage {cpuPercent:0}% and memory {FormatDataSize(workingSetBytes)}.");
return sb.ToString();
}