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