use cubecl_common::benchmark::ProfileDuration;
use std::time::Instant;
#[derive(Debug, Default)]
pub struct KernelTimestamps {
start: Option<Instant>,
}
impl KernelTimestamps {
pub fn start(&mut self) {
if self.start.is_some() {
panic!("Recursive kernel timestamps are not supported.");
}
self.start = Some(std::time::Instant::now());
}
pub fn stop(&mut self) -> ProfileDuration {
ProfileDuration::from_duration(
self.start
.take()
.expect("Stopped timestamp before starting one.")
.elapsed(),
)
}
}