-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
7 changed files
with
129 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,20 @@ | ||
mod diagnostic; | ||
pub mod diagnostics; | ||
mod print_diagnostics_plugin; | ||
mod frame_time_diagnostics_plugin; | ||
pub use diagnostic::*; | ||
pub use diagnostic::*; | ||
pub use frame_time_diagnostics_plugin::FrameTimeDiagnosticsPlugin; | ||
pub use print_diagnostics_plugin::PrintDiagnosticsPlugin; | ||
|
||
use bevy_app::{AppBuilder, AppPlugin}; | ||
use diagnostics::{print_diagnostics_system, PrintDiagnosticsState}; | ||
use legion::prelude::IntoSystem; | ||
use std::time::Duration; | ||
|
||
pub struct PrintDiagnostics { | ||
pub wait_duration: Duration, | ||
pub filter: Option<Vec<DiagnosticId>>, | ||
} | ||
|
||
pub struct DiagnosticsPlugin { | ||
pub print_diagnostics: Option<PrintDiagnostics>, | ||
} | ||
pub struct PrintDiagnostics {} | ||
|
||
impl Default for DiagnosticsPlugin { | ||
fn default() -> Self { | ||
DiagnosticsPlugin { | ||
print_diagnostics: Some(PrintDiagnostics { | ||
wait_duration: Duration::from_secs_f64(1.0), | ||
filter: None, | ||
}), | ||
} | ||
} | ||
} | ||
#[derive(Default)] | ||
pub struct DiagnosticsPlugin; | ||
|
||
impl AppPlugin for DiagnosticsPlugin { | ||
fn build(&self, app: &mut AppBuilder) { | ||
app.init_resource::<Diagnostics>(); | ||
if let Some(ref print_diagnostics) = self.print_diagnostics { | ||
app.add_resource(PrintDiagnosticsState::new(print_diagnostics.wait_duration)) | ||
.add_system(print_diagnostics_system.system()); | ||
} | ||
} | ||
} |
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,110 @@ | ||
use super::{Diagnostic, DiagnosticId, Diagnostics}; | ||
use bevy_app::{stage, AppPlugin}; | ||
use bevy_core::time::Time; | ||
use legion::prelude::*; | ||
use std::time::Duration; | ||
|
||
pub struct PrintDiagnosticsPlugin { | ||
pub debug: bool, | ||
pub wait_duration: Duration, | ||
pub filter: Option<Vec<DiagnosticId>>, | ||
} | ||
|
||
pub struct PrintDiagnosticsState { | ||
elapsed: f64, | ||
wait_seconds: f64, | ||
filter: Option<Vec<DiagnosticId>>, | ||
} | ||
|
||
impl Default for PrintDiagnosticsPlugin { | ||
fn default() -> Self { | ||
PrintDiagnosticsPlugin { | ||
debug: false, | ||
wait_duration: Duration::from_secs(1), | ||
filter: None, | ||
} | ||
} | ||
} | ||
|
||
impl AppPlugin for PrintDiagnosticsPlugin { | ||
fn build(&self, app: &mut bevy_app::AppBuilder) { | ||
app.add_resource(PrintDiagnosticsState { | ||
elapsed: 0.0, | ||
wait_seconds: self.wait_duration.as_secs_f64(), | ||
filter: self.filter.clone(), | ||
}); | ||
|
||
if self.debug { | ||
app.add_system_to_stage( | ||
stage::POST_UPDATE, | ||
Self::print_diagnostics_debug_system.system(), | ||
); | ||
} else { | ||
app.add_system_to_stage(stage::POST_UPDATE, Self::print_diagnostics_system.system()); | ||
} | ||
} | ||
} | ||
|
||
impl PrintDiagnosticsPlugin { | ||
pub fn filtered(filter: Vec<DiagnosticId>) -> Self { | ||
PrintDiagnosticsPlugin { | ||
filter: Some(filter), | ||
..Default::default() | ||
} | ||
} | ||
|
||
fn print_diagnostic(diagnostic: &Diagnostic) { | ||
if let Some(value) = diagnostic.value() { | ||
print!("{:<20}: {:<19.6}", diagnostic.name, value); | ||
if let Some(average) = diagnostic.average() { | ||
print!(" (avg {:.6})", average); | ||
} | ||
|
||
println!("\n"); | ||
} | ||
} | ||
|
||
pub fn print_diagnostics_system( | ||
mut state: ResourceMut<PrintDiagnosticsState>, | ||
time: Resource<Time>, | ||
diagnostics: Resource<Diagnostics>, | ||
) { | ||
state.elapsed += time.delta_seconds_f64; | ||
if state.elapsed >= state.wait_seconds { | ||
state.elapsed = 0.0; | ||
println!("Diagnostics:"); | ||
println!("{}", "-".repeat(50)); | ||
if let Some(ref filter) = state.filter { | ||
for diagnostic in filter.iter().map(|id| diagnostics.get(*id).unwrap()) { | ||
Self::print_diagnostic(diagnostic); | ||
} | ||
} else { | ||
for diagnostic in diagnostics.iter() { | ||
Self::print_diagnostic(diagnostic); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn print_diagnostics_debug_system( | ||
mut state: ResourceMut<PrintDiagnosticsState>, | ||
time: Resource<Time>, | ||
diagnostics: Resource<Diagnostics>, | ||
) { | ||
state.elapsed += time.delta_seconds_f64; | ||
if state.elapsed >= state.wait_seconds { | ||
state.elapsed = 0.0; | ||
println!("Diagnostics (Debug):"); | ||
println!("{}", "-".repeat(30)); | ||
if let Some(ref filter) = state.filter { | ||
for diagnostic in filter.iter().map(|id| diagnostics.get(*id).unwrap()) { | ||
println!("{:#?}\n", diagnostic); | ||
} | ||
} else { | ||
for diagnostic in diagnostics.iter() { | ||
println!("{:#?}\n", diagnostic); | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod wgpu_resource; | ||
pub use wgpu_resource::WgpuResourceDiagnosticPlugin; | ||
mod wgpu_resource_diagnostics_plugin; | ||
pub use wgpu_resource_diagnostics_plugin::WgpuResourceDiagnosticsPlugin; |
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