Statistics

Network Stats

GetStats() returns a NetworkStats struct, a snapshot of the connection's health at the time of the call. It bundles round-trip time and variance, byte counters, queued and resent command counts, server time, peer information and application-wide counts into one plain struct.

For quality monitoring, a handful of fields carry most of the signal. RoundTripTimeMs and RttVarianceMs measure latency and jitter, a climbing ResentReliableCommands indicates packet loss, and growing QueuedIncomingCommands or QueuedOutgoingCommands are backpressure from a Service() that is not called often enough. The full field table is in the data types reference.

Sampling once per second is plenty for a diagnostics overlay:

C++

NetworkStats stats = client.GetStats();
std::printf("rtt %d ms (+/- %d) | queued in %d out %d | resent %d\n",
            stats.RoundTripTimeMs,
            stats.RttVarianceMs,
            stats.QueuedIncomingCommands,
            stats.QueuedOutgoingCommands,
            stats.ResentReliableCommands);

Traffic Stats

Traffic accounting is opt-in because the counting itself costs a little performance. SetTrafficStatsEnabled(true) starts counting, ResetTrafficStats() clears the counters for a fresh measurement window and ResetTrafficStatsMaximumCounters() re-baselines only the recorded maxima.

GetTrafficStatsIncoming() and GetTrafficStatsOutgoing() each return a TrafficStats with byte and packet counts broken down per command class. GetTrafficStatsGameLevel() returns a TrafficStatsGameLevel, which adds operation, result and event counts plus the longest observed callback timings.

The longest-callback timings in TrafficStatsGameLevel identify your own slow handlers. Every callback runs inside Service(), so anything long-running inside a handler stalls the network pump itself, see Client and Service Loop.

Application Stats

The master server periodically pushes application-wide counts to every connected client: players online, players currently in rooms and the number of rooms. OnAppStatsUpdated() signals that a fresh push arrived; read the values from the next GetStats() snapshot via PlayersOnline, PlayersInGame and GamesRunning.

Diagnostics Output

GetVitalStatsToString(all) returns a one-call textual dump of the vital counters as a single string, with all = true extending the output with additional counters. It exists for bug reports and support tickets: attach the dump instead of transcribing individual stats.

Route the dump through your LogOutput implementation so it lands in the same sink as the SDK's own log lines. See Logging for registering a log output.

Back to top