diff --git a/MANUAL.md b/MANUAL.md index 04671a5..f9d2c9b 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -188,7 +188,7 @@ The main window has three parts, stacked top to bottom: 1. A **menu bar** at the top with four menus — _File_ , _Record_ , _Options_ and _Help_. See Menus. 2. A **row of tabs** with three tabs — Connectivity, Audio inputs and outputs, Audio profile. Each tab has its own Alt+letter shortcuts that only work when that tab is the one showing — so the same letter can do different things on different tabs without clashing. - 3. A **status line** at the bottom that updates once a second with how long you've been connected, how many peers you have, whether sound is flowing, and connection health. + 3. A **status line** at the bottom that updates once a second with how long you've been connected, how many peers you have, whether sound is flowing, connection health, and RemSound's own CPU and memory usage. Tab| What it's for ---|--- diff --git a/readme.html b/readme.html index 0a63e21..4154b2e 100644 --- a/readme.html +++ b/readme.html @@ -219,7 +219,7 @@ ul, ol { padding-left: 1.4em; }
  1. A menu bar at the top with four menus — File, Record, Options and Help. See Menus.
  2. A row of tabs with three tabs — Connectivity, Audio inputs and outputs, Audio profile. Each tab has its own Alt+letter shortcuts that only work when that tab is the one showing — so the same letter can do different things on different tabs without clashing.
  3. -
  4. A status line at the bottom that updates once a second with how long you've been connected, how many peers you have, whether sound is flowing, and connection health.
  5. +
  6. A status line at the bottom that updates once a second with how long you've been connected, how many peers you have, whether sound is flowing, connection health, and RemSound's own CPU and memory usage.
diff --git a/src/RemSound.App/MainForm.cs b/src/RemSound.App/MainForm.cs index 5c4947a..0c69d32 100644 --- a/src/RemSound.App/MainForm.cs +++ b/src/RemSound.App/MainForm.cs @@ -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(); }