From 3692955f9f5c15af6449c06137f58e84231d801f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Mon, 16 Dec 2024 10:34:34 +0100 Subject: [PATCH] Fix client diagnostics (#377) Bevy diagnostics (measurements) should only record the change in the value since lass time the measurements were collected. _Not_ the life-time total. --- CHANGELOG.md | 4 ++++ src/client.rs | 2 +- src/client/diagnostics.rs | 24 ++++++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31019760..6d4a8c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Report bevy diagnostics correctly as a delta since last measurement collection. + ## [0.29.0] - 2024-12-02 ### Added diff --git a/src/client.rs b/src/client.rs index 6fa3fadd..7ba3e882 100644 --- a/src/client.rs +++ b/src/client.rs @@ -801,7 +801,7 @@ pub(super) struct BufferedMutate { /// /// See also [`ClientDiagnosticsPlugin`](diagnostics::ClientDiagnosticsPlugin) /// for automatic integration with Bevy diagnostics. -#[derive(Default, Resource, Debug)] +#[derive(Clone, Copy, Default, Resource, Debug)] pub struct ClientReplicationStats { /// Incremented per entity that changes. pub entities_changed: usize, diff --git a/src/client/diagnostics.rs b/src/client/diagnostics.rs index b35902ba..73df8e7b 100644 --- a/src/client/diagnostics.rs +++ b/src/client/diagnostics.rs @@ -107,6 +107,7 @@ impl ClientDiagnosticsPlugin { fn add_measurements( mut diagnostics: Diagnostics, stats: Res, + mut last_stats: Local, client: Res, ) { diagnostics.add_measurement(&Self::RTT, || client.rtt()); @@ -114,13 +115,24 @@ impl ClientDiagnosticsPlugin { diagnostics.add_measurement(&Self::SENT_BPS, || client.sent_bps()); diagnostics.add_measurement(&Self::RECEIVED_BPS, || client.received_bps()); - diagnostics.add_measurement(&Self::ENTITIES_CHANGED, || stats.entities_changed as f64); + diagnostics.add_measurement(&Self::ENTITIES_CHANGED, || { + (stats.entities_changed - last_stats.entities_changed) as f64 + }); diagnostics.add_measurement(&Self::COMPONENTS_CHANGED, || { - stats.components_changed as f64 + (stats.components_changed - last_stats.components_changed) as f64 + }); + diagnostics.add_measurement(&Self::MAPPINGS, || { + (stats.mappings - last_stats.mappings) as f64 + }); + diagnostics.add_measurement(&Self::DESPAWNS, || { + (stats.despawns - last_stats.despawns) as f64 + }); + diagnostics.add_measurement(&Self::REPLICATION_MESSAGES, || { + (stats.messages - last_stats.messages) as f64 + }); + diagnostics.add_measurement(&Self::REPLICATION_BYTES, || { + (stats.bytes - last_stats.bytes) as f64 }); - diagnostics.add_measurement(&Self::MAPPINGS, || stats.mappings as f64); - diagnostics.add_measurement(&Self::DESPAWNS, || stats.despawns as f64); - diagnostics.add_measurement(&Self::REPLICATION_MESSAGES, || stats.messages as f64); - diagnostics.add_measurement(&Self::REPLICATION_BYTES, || stats.bytes as f64); + *last_stats = *stats; } }