bevy/crates/bevy_ecs/src/system/profiler.rs
Victor "multun" Collod 1ec7183494 profiling: fix build
2020-08-16 02:06:59 -07:00

26 lines
743 B
Rust

use crate::Resources;
use downcast_rs::{impl_downcast, Downcast};
use std::borrow::Cow;
/// Runs at the start and end of each system
///
/// Profilers are used to collect diagnostics about system execution.
pub trait Profiler: Downcast + Send + Sync + 'static {
fn start(&self, scope: Cow<'static, str>);
fn stop(&self, scope: Cow<'static, str>);
}
pub fn profiler_start(resources: &Resources, scope: Cow<'static, str>) {
if let Some(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.start(scope);
}
}
pub fn profiler_stop(resources: &Resources, scope: Cow<'static, str>) {
if let Some(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.stop(scope);
}
}
impl_downcast!(Profiler);