Engineering / 03

Traffic, process lifetimes
and temporary control.

TrafficMonitor extensions connect the numbers on screen to their owners—and leave a recovery path for settings that can outlive the window.

C++ · C# · ETW · Hardware lifecycle6 min read + demonstrations

A desktop monitor starts by answering a simple question: which program is using the network? Adding a quiet-mode switch changes the responsibility. The same software can now leave a fan or processor policy in a different state after its window disappears.

These extensions to TrafficMonitor span both sides of that boundary. They add application traffic, process trees and persistent usage history, alongside recoverable hardware control built on LibreHardwareMonitor. The host and hardware libraries are upstream foundations; the work here concerns attribution, data lifetime and restoration.

The connection between them is easy to miss. A number needs an identifiable owner. A setting needs an identifiable owner too—and a way to return control when that owner is gone.

Decide what the number on screen means

In Application Traffic, Program view groups instances by normalized executable identity. PID view separates those instances. Process tree view adds another distinction: a process’s own traffic versus the traffic of its whole subtree.

Those are different questions about the same activity. If a parent contributes 12 KiB/s and its child contributes 28 KiB/s, the parent’s subtree is 40 KiB/s. Adding the parent subtree to the child row would count the child twice.

Interface map · illustrative data

Three views of the same traffic.

Two process instances belong to one program. A tree adds descendants; a PID row describes only itself.

Program

Group by executable identity

Example program
40 KiB/s
Today
96 MiB

Daily usage belongs to the program.

PID

Separate process instances

Process 42
12 KiB/s
Process 73
28 KiB/s

Per-PID daily totals are not stored.

Process tree

Own rate / subtree rate

42 · parent
12 / 40
↳ 73 · child
28 / 28

Summing subtree rates would count the child twice.

Interface counters → Adapter Totals / CalendarETW events → Application Ranking
Explanatory rendering of the implemented views, with invented values. It is not an application screenshot. Adapter totals and process attribution use different collectors.

The Today value belongs to saved program-level byte deltas. A PID child has no daily total because history is not retained at that level. Showing a dash preserves the meaning of the data better than borrowing a plausible-looking total from its program group.

Network Usage adds Adapter Totals, Adapter Calendar and Application Ranking. The first two use network-interface counters; the third uses process events from ETW, the operating system’s event tracing facility. Selecting an adapter does not filter that ETW collector. Virtual interfaces, retransmits, shared services and attribution gaps can therefore produce different totals.

A useful dashboard explains these distinctions at the point of reading. It cannot make unlike accounting systems agree by putting their numbers in adjacent columns.

A process ID is only half an identity

Suppose an editor exits and a downloader later receives the same PID. This synthetic example exposes a real collector problem: joining observations by PID alone would join two different lifetimes.

ProcessNetworkMonitor pairs the PID with its creation time. Program grouping uses normalized executable identity, while unresolved processes remain in an unknown bucket. A parent must also be verified before a process is attached to its tree.

Interactive explanation

The same PID can belong to a different process.

This synthetic sequence shows why process identity includes creation time, not just a number.

PROCESS TRAFFICsnapshot / 17
IdentityReceivedSent
42 @ t₀64 KiB8 KiB

The history belongs to the process instance that started at t₀.

A new immutable snapshot is published; the UI reads it without holding the worker's update lock.

Schematic with invented traffic values to explain identity handling, not a screenshot or performance measurement.

The same identity rule follows an observation into an action. Context menus can terminate a process, a program group or a verified tree after confirmation. Targets are copied before the confirmation, then creation time is checked again immediately before termination. Reuse of a PID causes refusal; an unverifiable tree branch is omitted and reported.

The small delay introduced by a confirmation dialog is enough for the world to change. Verifying the target afterward makes the action refer to the process the user selected.

Publish a view the interface can keep

ETW callbacks accumulate integer byte counters for TCP and UDP activity, including IPv4, IPv6 and retransmits. Executable lookup and parent-process work stay outside the callback and aggregation lock. The collector’s short critical path is concerned with accounting, not preparing a window.

After aggregation, the sampler builds a complete immutable snapshot outside the counter lock. The interface obtains it through an atomic shared-pointer load. It can read a consistent view without holding the collector’s update lock or copying every process vector. If publication fails, the last usable snapshot remains available.

The hardware interface uses the same lifetime principle. Forms receive a HardwareUiSnapshot containing copied topology and values. Polling and settings transactions retain serialized access to the live hardware objects. Closing a window does not transfer ownership of those live objects to its former controls.

Normal shutdown also has a lifetime requirement: the worker must exit before its plugin and interface targets are destroyed. A wait timeout produces a diagnostic and retains those objects. Unloading code while a worker can still call it would turn delayed shutdown into a memory-lifetime failure.

History extends the view across restarts. ProcessTrafficHistory stores integer byte deltas with their sampling dates, rather than reconstructing usage from rounded display rates. A delayed display refresh therefore cannot move yesterday’s bytes into today’s bucket.

Persistence, capacity and collector diagnostics

History uses versioned, checksummed snapshot files with a primary, a recovery backup, asynchronous saving and atomic replacement. Limits are 64 MiB of payload and 500,000 records; backup and temporary files need additional storage. Expired dates can be pruned at capacity, and rejected additions are counted. Existing accepted records can still accumulate bytes when larger display metadata is rejected.

Clearing history coordinates with queued saves so an older save cannot restore cleared data. The ETW collector separately reports capacity, deferred lookups, dropped events and tracing losses. Recovering a crash-orphaned tracing session requires checking its component identity and flags under an ownership mutex.

Before changing a setting, save the way back

Observation tolerates an old snapshot while a new one is being prepared. Hardware control has a stronger obligation: a temporary setting may outlive the process that requested it.

Quiet mode therefore begins with a read-only preflight. Required temperature telemetry, current processor-policy values and their exact power-scheme identity must be available. Before a software fan-control write, a durable lease records every target fan-control sensor. Original processor settings are likewise committed before mutation.

The external HardwareMonitorFanGuard must start successfully before quiet mode is armed. Its owner is identified by PID and creation time—the same pair needed by the traffic collector. A stale heartbeat while that exact owner remains alive is diagnostic; it does not authorize a second controller to compete with it.

The lease is a record of unfinished restoration. If a named target disappears or cannot be verified, the record remains pending. Finding another functioning fan does not discharge the obligation to the missing one.

Normal shutdown and recovery obligations

From temporary control to verified restoration

  1. 01
    Stop new work

    Cancel polling and join the worker.

  2. 02
    Restore control

    Return fan registers to their firmware-owned mode; restore the saved processor-policy values to their original scheme.

  3. 03
    Read back the state

    A successful write is not proof of successful restoration.

  4. 04
    Release the lease

    Only after the relevant restoration gates succeed.

The fan guard and CPU power recovery have separate conditions. One successful cleanup path does not certify the other.

Restoration has to be observed

For the supported Smart Fan controller path, releasing fan control means reading the register, changing the firmware-mode bits while preserving unrelated bits, checking the readback, and successfully releasing the shared hardware mutex. A successful write call covers only part of that sequence.

Processor recovery has its own gate. Saved values must return to their original power schemes and be verified there. If the active scheme changes, recovery does not reactivate the old scheme; it restores its recorded values before capturing and applying settings in the new one.

restore every recorded fan target
verify firmware mode and hardware-mutex release
restore processor values to their recorded schemes
verify those values
clear the lease only when the required gates have passed

Invalid processor restore data does not justify withholding fan release. It does, however, prevent the entire lease from being cleared. Keeping the two outcomes separate allows useful recovery to proceed while preserving the unresolved obligation.

Thermal policy during a control session

During operation, thermal protection filters temperature noise and predicts 2.5 seconds ahead. Emergency bands respond to actual overshoot, followed by a recovery ramp after a safe dwell. These are operating-system performance controls, not a guarantee of a fixed package-wattage limit.

The window can close before the job is finished

The traffic views and quiet mode make two promises of different strength. Traffic attribution must keep its accounting and process lifetimes straight. Temporary control must also leave a recoverable record outside the window that requested it.

Both are reflected in the implementation: identity checks before process actions, immutable views for the interface, dated counters for history, and verified restoration before a lease disappears. The remaining limits are concrete. Shared services constrain attribution, uncancellable shell-icon lookup can delay shutdown, and hardware recovery depends on supported access to the recorded targets.

Checked-in tests cover identity, snapshot ownership, history limits, fan targets, register readback, mutex release, power-scheme restoration and thermal recovery. A native-dialog harness uses synthetic data without ETW or hardware initialization. These were inspected, not run for this article; the diagrams here explain the mechanisms with synthetic values.