dbg_instrument

Macro dbg_instrument 

Source
macro_rules! dbg_instrument {
    ($fut:expr) => { ... };
    ($log:literal, $fut:expr) => { ... };
}
Expand description

Debug log how long a future took to execute

When debug_assertions are enabled, does a log::debug!() with the file!(), line!(), and elapsed time. Without debug_assertions, simply is a no-op which executes future normally.

The argument to the function must be a unexecuted future. It will return a future you must await on. This allows you to use the created instrumenting future later if desired since it doesn’t await immediately.

There is also an optional one with a custom log message. elapsed is provided as a keyword arg to the literal, so you must use it somewhere in there.

If you need custom behavior, you can make a custom instrumenting future using InstrumentFuture

Examples:

let my_fut: impl Future<Output = ()> = foobar();
dbg_instrument!(my_fut).await;

let f = 0;
dbg_instrument!("custom_log_message {f}: {elapsed:?}").await;