Crates.io | async-alloc-counter |
lib.rs | async-alloc-counter |
version | 0.2.1 |
source | src |
created_at | 2021-10-12 22:17:59.816391 |
updated_at | 2021-10-14 20:49:16.251954 |
description | async-alloc-counter measures max allocations in a future invocation |
homepage | |
repository | https://github.com/Geal/async-alloc-counter |
max_upload_size | |
id | 464266 |
size | 21,372 |
async-alloc-counter measures max allocations in a future invocation
see examples/
for usage
This allocator can be used as follows:
use async_alloc_counter::*;
use futures::FutureExt;
use std::{alloc::System, time::Duration};
// set up the counting allocator
#[global_allocator]
static GLOBAL: AsyncAllocatorCounter<System> = AsyncAllocatorCounter { allocator: System };
#[tokio::main]
async fn main() {
async move {
let mut v: Vec<u8> = Vec::with_capacity(1024);
}.count_allocations()
.map(move |(max, ())| {
println!("future allocated {} max bytes", max);
})
.await
}
Allocation measurement can be stacked:
async move {
println!("wrapping future");
tokio::time::sleep(std::timeDuration::from_secs(1)).await;
let mut v: Vec<u8> = Vec::with_capacity(256);
async move {
let mut v: Vec<u8> = Vec::with_capacity(1024);
}.count_allocations()
.map(move |(max, ())| {
println!("future allocated {} max bytes", max);
})
.await
}.count_allocations()
.map(move |(max, ())| {
println!("warpping future allocated {} max bytes", max);
})
.await
Design inspired by the excellent tracing crate