1use std::marker::PhantomData;
2use std::{borrow::Cow, time::Instant};
3use tracing::debug;
4
5#[cfg(debug_assertions)]
6pub struct Timer<'a> {
7 func_name: Cow<'a, str>,
8 start: Instant,
9}
10
11#[cfg(debug_assertions)]
12impl<'a> Timer<'a> {
13 pub fn new(func_name: impl Into<Cow<'a, str>>) -> Self {
14 Self {
15 func_name: func_name.into(),
16 start: Instant::now(),
17 }
18 }
19}
20
21#[cfg(debug_assertions)]
22impl<'a> Drop for Timer<'a> {
23 fn drop(&mut self) {
24 let elapsed = self.start.elapsed();
25 debug!(target: "luna_orm", fn_name= ?self.func_name, elapsed = ?elapsed);
26 }
27}
28
29#[cfg(not(debug_assertions))]
30pub struct Timer<'a> {
31 _phantom: PhantomData<&'a ()>,
32}
33
34#[cfg(not(debug_assertions))]
35impl<'a> Timer<'a> {
36 pub fn new(func_name: impl Into<Cow<'a, str>>) -> Self {
37 Self {
38 _phantom: PhantomData,
39 }
40 }
41}