bevy/crates/bevy_ecs/src/profiler.rs
2020-07-10 01:06:21 -07:00

23 lines
620 B
Rust

use crate::Resources;
use downcast_rs::{impl_downcast, Downcast};
use std::borrow::Cow;
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 Ok(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.start(scope);
}
}
pub fn profiler_stop(resources: &Resources, scope: Cow<'static, str>) {
if let Ok(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.stop(scope);
}
}
impl_downcast!(Profiler);