profile_async

Macro profile_async 

Source
macro_rules! profile_async {
    ($operation:expr, $code:expr) => { ... };
}
Expand description

Profile an async code block using RAII timer

This macro creates an async RAII timer that records the duration of async operations. It takes an Operation and an async expression.

§Important

This macro returns a Future that must be awaited to have any effect. If you don’t await the result, the profiling will not happen and you’ll get a compiler warning.

§Example

use quantum_pulse::{profile_async, Category, Operation};
use std::fmt::Debug;

// Define your own operation type
#[derive(Debug)]
enum AppOperation {
    AsyncDatabaseQuery,
}

impl Operation for AppOperation {}

let op = AppOperation::AsyncDatabaseQuery;
// The .await is required!
let result = profile_async!(op, async {
    "query result" // database.async_query("SELECT * FROM users").await
}).await;