-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use bevy::{prelude::*, diagnostic::*}; | ||
use crate::prelude::*; | ||
|
||
/// Adds diagnostics about various | ||
pub struct ConnectionDiagnosticPlugin; | ||
|
||
impl Plugin for ConnectionDiagnosticPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_diagnostic(Diagnostic::new(Self::COUNT) | ||
.with_smoothing_factor(0.0) | ||
.with_max_history_length(1)); | ||
|
||
app.add_systems(Update, diagnostic_system); | ||
} | ||
} | ||
|
||
impl ConnectionDiagnosticPlugin { | ||
/// Diagnostic path for the amount of connections (entities with [`NetworkPeer`]) | ||
pub const COUNT: DiagnosticPath = DiagnosticPath::const_new("connection_count"); | ||
} | ||
|
||
fn diagnostic_system( | ||
mut diagnostics: Diagnostics, | ||
query: Query<(), With<NetworkPeer>>, | ||
) { | ||
diagnostics.add_measurement(&ConnectionDiagnosticPlugin::COUNT, || query.iter().count() as f64); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use bevy::{prelude::*, diagnostic::*}; | ||
use crate::prelude::*; | ||
|
||
/// Adds diagnostics about how many messages are being sent. | ||
pub struct MessageCountDiagnosticsPlugin; | ||
|
||
impl Plugin for MessageCountDiagnosticsPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_diagnostic(Diagnostic::new(Self::INCOMING_COUNT)); | ||
app.register_diagnostic(Diagnostic::new(Self::OUTGOING_COUNT)); | ||
|
||
app.add_systems(Update, diagnostic_system); | ||
} | ||
} | ||
|
||
impl MessageCountDiagnosticsPlugin { | ||
/// The number of incoming messages in queues for all peers. | ||
pub const INCOMING_COUNT: DiagnosticPath = DiagnosticPath::const_new("incoming_message_count"); | ||
|
||
/// The number of outgoing messages in queues for all peers. | ||
pub const OUTGOING_COUNT: DiagnosticPath = DiagnosticPath::const_new("outgoing_message_count"); | ||
} | ||
|
||
type QueryFilter = (Or<(With<NetworkMessages<Incoming>>, With<NetworkMessages<Outgoing>>)>, With<NetworkPeer>); | ||
|
||
fn diagnostic_system( | ||
mut diagnostics: Diagnostics, | ||
query: Query<(Option<&NetworkMessages<Incoming>>, Option<&NetworkMessages<Outgoing>>), QueryFilter>, | ||
) { | ||
let mut incoming_count: usize = 0; | ||
let mut outgoing_count: usize = 0; | ||
|
||
for (incoming, outgoing) in query.iter() { | ||
if let Some(incoming) = incoming { | ||
incoming_count += incoming.count(); | ||
} | ||
|
||
if let Some(outgoing) = outgoing { | ||
outgoing_count += outgoing.count(); | ||
} | ||
} | ||
|
||
diagnostics.add_measurement(&MessageCountDiagnosticsPlugin::INCOMING_COUNT, || incoming_count as f64); | ||
diagnostics.add_measurement(&MessageCountDiagnosticsPlugin::OUTGOING_COUNT, || outgoing_count as f64); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Diagnostics about various parts of Stardust. | ||
mod connections; | ||
mod messages; | ||
|
||
pub use connections::*; | ||
pub use messages::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters