canic_core/macros/
perf.rs1#[macro_export]
8macro_rules! perf {
9 ($($label:tt)*) => {{
10 $crate::perf::PERF_LAST.with(|last| {
11 let now = $crate::cdk::api::performance_counter(1);
12 let then = *last.borrow();
13 let delta = now.saturating_sub(then);
14 *last.borrow_mut() = now;
15
16 let label = format!($($label)*);
17 let delta_fmt = $crate::utils::instructions::format_instructions(delta);
18 let now_fmt = $crate::utils::instructions::format_instructions(now);
19
20 $crate::perf::record(&label, delta);
21 $crate::cdk::println!(
22 "{}: '{}' used {}i since last (total: {}i)",
23 module_path!(),
24 label,
25 delta_fmt,
26 now_fmt
27 );
28 });
29 }};
30}
31
32#[macro_export]
40macro_rules! perf_defer {
41 () => {
42 $crate::export::defer::defer!({
43 let end = $crate::cdk::api::performance_counter(1);
44 let end_fmt = $crate::utils::instructions::format_instructions(end);
45
46 $crate::cdk::println!("{} used {}i in this call", module_path!(), end_fmt,)
47 });
48 };
49}