Crates.io | async-instrumenter |
lib.rs | async-instrumenter |
version | 0.1.4 |
source | src |
created_at | 2023-08-17 00:25:36.739499 |
updated_at | 2023-08-17 01:08:49.472246 |
description | A wrapper over futures which allows to time how long the future takes to execute |
homepage | |
repository | https://github.com/MolotovCherry/async-instrumenter |
max_upload_size | |
id | 946499 |
size | 42,949 |
This Rust library offers a useful future which allows you to time exactly how long any particular future took to execute.
Please note that this is only as accurate as Rust's Instant
type. So while it offers a good benchmark of how long, it is limited to how precise std/os/hardware is measuring the time. (If you know of a more accurate implementation, I am all ears)
Usage couldn't be simpler:
async fn sleep() {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
// debug log our `sleep()` future with a custom log message
// will only print debug log if `debug_assertions` are enabled
//
// elapsed arg must be used
dbg_instrument!("sleep() took {elapsed:?}", sleep()).await;
// same as above, except with a predefined macro provided log
// message
dbg_instrument!(sleep()).await;
// will always print a debug log message regardless of
// `debug_assertions` status
//
// elapsed arg must be used
instrument!("{elapsed:?}", sleep()).await;
// same as above, except with a predefined macro provided
// log message
instrument!(sleep()).await;
// we can also manually create an instrumenting future if
//we require custom behavior or access to the elapsed data
let res = InstrumentFuture::new(sleep()).await;
println!("took {:?} with result {:?}", res.elapsed, res.result);