-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates on diagnostics (log + new diagnostics) (#1085)
* move print diagnostics to log * entity count diagnostic * asset count diagnostic * remove useless `pub`s * use `BTreeMap` instead of `HashMap` * get entity count from world * keep ordered list of diagnostics
- Loading branch information
Showing
17 changed files
with
144 additions
and
45 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
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
35 changes: 35 additions & 0 deletions
35
crates/bevy_asset/src/diagnostic/asset_count_diagnostics_plugin.rs
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,35 @@ | ||
use crate::{Asset, Assets}; | ||
use bevy_app::prelude::*; | ||
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics}; | ||
use bevy_ecs::{IntoSystem, Res, ResMut}; | ||
|
||
/// Adds "asset count" diagnostic to an App | ||
#[derive(Default)] | ||
pub struct AssetCountDiagnosticsPlugin<T: Asset> { | ||
marker: std::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> { | ||
fn build(&self, app: &mut AppBuilder) { | ||
app.add_startup_system(Self::setup_system.system()) | ||
.add_system(Self::diagnostic_system.system()); | ||
} | ||
} | ||
|
||
impl<T: Asset> AssetCountDiagnosticsPlugin<T> { | ||
pub fn diagnostic_id() -> DiagnosticId { | ||
DiagnosticId(T::TYPE_UUID) | ||
} | ||
|
||
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) { | ||
diagnostics.add(Diagnostic::new( | ||
Self::diagnostic_id(), | ||
&format!("asset_count {}", std::any::type_name::<T>()), | ||
20, | ||
)); | ||
} | ||
|
||
pub fn diagnostic_system(mut diagnostics: ResMut<Diagnostics>, assets: Res<Assets<T>>) { | ||
diagnostics.add_measurement(Self::diagnostic_id(), assets.len() 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,2 @@ | ||
mod asset_count_diagnostics_plugin; | ||
pub use asset_count_diagnostics_plugin::AssetCountDiagnosticsPlugin; |
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
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
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
29 changes: 29 additions & 0 deletions
29
crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs
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,29 @@ | ||
use crate::{Diagnostic, DiagnosticId, Diagnostics}; | ||
use bevy_app::prelude::*; | ||
use bevy_ecs::{IntoSystem, ResMut, Resources, World}; | ||
|
||
/// Adds "entity count" diagnostic to an App | ||
#[derive(Default)] | ||
pub struct EntityCountDiagnosticsPlugin; | ||
|
||
impl Plugin for EntityCountDiagnosticsPlugin { | ||
fn build(&self, app: &mut AppBuilder) { | ||
app.add_startup_system(Self::setup_system.system()) | ||
.add_system(Self::diagnostic_system.system()); | ||
} | ||
} | ||
|
||
impl EntityCountDiagnosticsPlugin { | ||
pub const ENTITY_COUNT: DiagnosticId = | ||
DiagnosticId::from_u128(187513512115068938494459732780662867798); | ||
|
||
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) { | ||
diagnostics.add(Diagnostic::new(Self::ENTITY_COUNT, "entity_count", 20)); | ||
} | ||
|
||
pub fn diagnostic_system(world: &mut World, resources: &mut Resources) { | ||
if let Some(mut diagnostics) = resources.get_mut::<Diagnostics>() { | ||
diagnostics.add_measurement(Self::ENTITY_COUNT, world.entity_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
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
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
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
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
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
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
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
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