instrument

Macro instrument 

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

Debug log how long a future took to execute

As opposed to dbg_instrument!, this always logs regardless whether debug_assertions are enabled or not

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();
instrument!(my_fut).await;

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