use crate::EmeraldError;
use super::profile_cache::ProfileCache;
pub type ProfileFloat = f64;
pub type ProfileName = String;
pub struct Profiler<'c> {
profile_cache: &'c mut ProfileCache,
profile_name: ProfileName,
now: ProfileFloat,
}
impl<'c> Profiler<'c> {
pub(crate) fn new<T: Into<ProfileName>>(
profile_cache: &'c mut ProfileCache,
profile_name: T,
now: ProfileFloat,
) -> Self {
Self {
profile_cache,
profile_name: profile_name.into(),
now,
}
}
pub fn start_frame(&mut self) -> Result<(), EmeraldError> {
self.profile_cache
.start_frame(self.profile_name.clone(), self.now)
}
pub fn finish_frame(&mut self) -> Result<ProfileFloat, EmeraldError> {
self.profile_cache
.finish_frame(self.profile_name.clone(), self.now)
}
}