Table of Contents

Class NetworkStatsSampler

Namespace
FishMMO.Client
Assembly
FishMMO.Client.dll

The overlay's memory: the last few snapshots, for rates smoothed over about five seconds, and a minute of one-second wire rates, for the graph.

public sealed class NetworkStatsSampler
Inheritance
NetworkStatsSampler
Inherited Members

Remarks

Smoothing is a longer interval, not an average of short ones. The rate shown is the difference between the newest snapshot and the oldest one still inside SmoothingWindowSeconds, divided by the time between them — the transport's own advice (FishNet.Transporting.WebTransport.TransportTrafficMath.TryComputeRates(in FishNet.Transporting.WebTransport.TransportTrafficSnapshot, in FishNet.Transporting.WebTransport.TransportTrafficSnapshot, out FishNet.Transporting.WebTransport.TransportTrafficRates)). An average of one-second rates would come to the same number with the rounding of every step in it.

A window never spans a change of definition. When a layer's measure changes between two snapshots — the native library starting on the first connect, or a browser's first getStats() answer turning an estimate into a reported figure — the two ends count different things, and the transport refuses to difference them (the layer comes back unavailable). Keeping the older snapshots would leave that layer unknown for the whole window; the window restarts at the new snapshot instead, so the layer is unknown for one sample and then correct. The same happens when two snapshots cannot belong to one process lifetime at all (a backend change, a counter that went backwards).

The graph keeps its gaps. A second whose wire rate could not be computed is stored as NaN and drawn as a break in the line, never as a dip to zero.

Pure: no clock, no Unity object. The overlay feeds it one snapshot a second; tests and the render harness feed it fabricated ones.

Fields

HistoryCapacity

One-second graph points kept: a minute.

public const int HistoryCapacity = 60

Field Value

int

SmoothingWindowSeconds

How far back the smoothed rates reach, seconds.

public const double SmoothingWindowSeconds = 5

Field Value

double

SnapshotCapacity

Snapshots kept: enough for a five-second window at one a second.

public const int SnapshotCapacity = 6

Field Value

int

WindowSlackSeconds

Slack allowed on SmoothingWindowSeconds. Samples are taken on the first frame after each second, so five intervals come to a little over five seconds; without slack the oldest snapshot would fall out of the window by a frame and the average would quietly shorten to four seconds.

public const double WindowSlackSeconds = 0.5

Field Value

double

Properties

Count

Snapshots in the current averaging window.

public int Count { get; }

Property Value

int

HistoryCount

Graph points held, at most HistoryCapacity.

public int HistoryCount { get; }

Property Value

int

Methods

Add(in TransportTrafficSnapshot)

Adds one snapshot: extends the averaging window, or restarts it when the snapshot cannot be compared with the previous one, and appends one point to the graph.

public bool Add(in TransportTrafficSnapshot snapshot)

Parameters

snapshot TransportTrafficSnapshot

A snapshot from FishNet.Transporting.WebTransport.TransportTraffic.Capture(out FishNet.Transporting.WebTransport.TransportTrafficSnapshot).

Returns

bool

False when the snapshot was refused because it carries no backend at all (a default struct); true otherwise.

Clear()

Forgets everything: the window and the graph. The overlay does this each time it opens.

public void Clear()

Remarks

Nothing is sampled while the overlay is hidden, so a window or a graph carried across a hidden spell would join two moments minutes apart as if they were adjacent seconds.

DefinitionChanged(in TransportTrafficSnapshot, in TransportTrafficSnapshot)

True when a layer counts something different in later than in earlier, so no interval may span the two.

public static bool DefinitionChanged(in TransportTrafficSnapshot earlier, in TransportTrafficSnapshot later)

Parameters

earlier TransportTrafficSnapshot
later TransportTrafficSnapshot

Returns

bool

GetHistory(int, out double, out double)

One graph point: wire bytes per second each way, NaN where unknown.

public void GetHistory(int index, out double down, out double up)

Parameters

index int

0 is the oldest point held, HistoryCount - 1 the newest.

down double

Received wire bytes per second.

up double

Sent wire bytes per second.

HistoryPeak()

The highest known point in the graph, either direction, or NaN when none is known.

public double HistoryPeak()

Returns

double

Readout()

The newest snapshot and the smoothed rates, as one value.

public NetworkStatsReadout Readout()

Returns

NetworkStatsReadout

TryGetLatest(out TransportTrafficSnapshot)

The newest snapshot, if there is one.

public bool TryGetLatest(out TransportTrafficSnapshot latest)

Parameters

latest TransportTrafficSnapshot

Returns

bool

TryGetSmoothedRates(out TransportTrafficRates)

The traffic between the oldest snapshot inside the smoothing window and the newest.

public bool TryGetSmoothedRates(out TransportTrafficRates rates)

Parameters

rates TransportTrafficRates

Returns

bool

Remarks

When no older snapshot lies inside the window — a frame hitch longer than the window, so the previous sample is already too old — the previous snapshot is used anyway: an average over a slightly longer interval is still the truth about that interval, and showing nothing would hide a working connection.