diagnostic filtering
This commit is contained in:
parent
ac5b6c5046
commit
6f32d18dc5
@ -42,6 +42,7 @@ pub fn frame_time_diagnostic_system(
|
||||
pub struct PrintDiagnosticsState {
|
||||
elapsed: f64,
|
||||
wait_seconds: f64,
|
||||
filter: Option<Vec<DiagnosticId>>,
|
||||
}
|
||||
|
||||
impl PrintDiagnosticsState {
|
||||
@ -49,8 +50,28 @@ impl PrintDiagnosticsState {
|
||||
PrintDiagnosticsState {
|
||||
elapsed: 0.,
|
||||
wait_seconds: wait.as_secs_f64(),
|
||||
filter: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_filtered(wait: Duration, filter: Vec<DiagnosticId>) -> Self {
|
||||
PrintDiagnosticsState {
|
||||
elapsed: 0.,
|
||||
wait_seconds: wait.as_secs_f64(),
|
||||
filter: Some(filter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_diagnostic(diagnostic: &Diagnostic) {
|
||||
if let Some(value) = diagnostic.value() {
|
||||
print!("{:<10}: {:<9.6}", diagnostic.name, value);
|
||||
if let Some(average) = diagnostic.average() {
|
||||
print!(" (avg {:.6})", average);
|
||||
}
|
||||
|
||||
println!("\n");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_diagnostics_system(
|
||||
@ -61,14 +82,13 @@ pub fn print_diagnostics_system(
|
||||
state.elapsed += time.delta_seconds_f64;
|
||||
if state.elapsed >= state.wait_seconds {
|
||||
state.elapsed = 0.0;
|
||||
for diagnostic in diagnostics.iter() {
|
||||
if let Some(value) = diagnostic.value() {
|
||||
print!("{:<10}: {:<9.6}", diagnostic.name, value);
|
||||
if let Some(average) = diagnostic.average() {
|
||||
print!(" (avg {:.6})", average);
|
||||
}
|
||||
|
||||
println!("\n");
|
||||
if let Some(ref filter) = state.filter {
|
||||
for diagnostic in filter.iter().map(|id| diagnostics.get(*id).unwrap()) {
|
||||
print_diagnostic(diagnostic);
|
||||
}
|
||||
} else {
|
||||
for diagnostic in diagnostics.iter() {
|
||||
print_diagnostic(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,8 +102,14 @@ pub fn print_diagnostics_debug_system(
|
||||
state.elapsed += time.delta_seconds_f64;
|
||||
if state.elapsed >= state.wait_seconds {
|
||||
state.elapsed = 0.0;
|
||||
for diagnostic in diagnostics.iter() {
|
||||
println!("{:#?}\n", diagnostic);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,17 +10,23 @@ use diagnostics::{
|
||||
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_wait_duration: Duration,
|
||||
pub print_diagnostics: bool,
|
||||
pub print_diagnostics: Option<PrintDiagnostics>,
|
||||
pub add_defaults: bool,
|
||||
}
|
||||
|
||||
impl Default for DiagnosticsPlugin {
|
||||
fn default() -> Self {
|
||||
DiagnosticsPlugin {
|
||||
print_wait_duration: Duration::from_secs_f64(1.0),
|
||||
print_diagnostics: false,
|
||||
print_diagnostics: Some(PrintDiagnostics {
|
||||
wait_duration: Duration::from_secs_f64(1.0),
|
||||
filter: None,
|
||||
}),
|
||||
add_defaults: true,
|
||||
}
|
||||
}
|
||||
@ -34,8 +40,8 @@ impl AppPlugin for DiagnosticsPlugin {
|
||||
.add_system(frame_time_diagnostic_system.system());
|
||||
}
|
||||
|
||||
if self.print_diagnostics {
|
||||
app.add_resource(PrintDiagnosticsState::new(self.print_wait_duration))
|
||||
if let Some(ref print_diagnostics) = self.print_diagnostics {
|
||||
app.add_resource(PrintDiagnosticsState::new(print_diagnostics.wait_duration))
|
||||
.add_system(print_diagnostics_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,7 @@ use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_default_plugins()
|
||||
.add_plugin(DiagnosticsPlugin {
|
||||
print_diagnostics: true,
|
||||
..Default::default()
|
||||
})
|
||||
.add_plugin(DiagnosticsPlugin::default())
|
||||
.add_startup_system(setup)
|
||||
.add_system(move_system.system())
|
||||
.run();
|
||||
|
||||
@ -54,9 +54,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
||||
..Default::default()
|
||||
})
|
||||
// 2d camera
|
||||
.add_entity(Camera2dEntity {
|
||||
..Default::default()
|
||||
})
|
||||
.add_entity(Camera2dEntity::default())
|
||||
// left vertical fill
|
||||
.add_entity(UiEntity {
|
||||
node: Node::new(
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_ui::{ColorMaterial, Rect};
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_default_plugins()
|
||||
.add_startup_system(setup)
|
||||
.add_system(placement_system.system())
|
||||
.add_plugin(DiagnosticsPlugin {
|
||||
print_diagnostics: true,
|
||||
..Default::default()
|
||||
})
|
||||
.add_plugin(DiagnosticsPlugin::default())
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -27,10 +23,7 @@ fn placement_system(
|
||||
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut builder = world.build();
|
||||
builder.add_entity(Camera2dEntity {
|
||||
camera: Camera::new(CameraType::default_orthographic()),
|
||||
..Default::default()
|
||||
});
|
||||
builder.add_entity(Camera2dEntity::default());
|
||||
|
||||
let mut materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
let mut prev = Vec2::default();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user