3个不稳定版本
0.2.1 | 2021年10月14日 |
---|---|
0.2.0 | 2021年10月13日 |
0.1.0 | 2021年10月12日 |
#354 in 内存管理
9KB
104 行
async-alloc-counter测量future调用中的最大分配
查看examples/
以了解使用方法
此分配器可以这样使用
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
}
分配测量可以堆叠
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
设计灵感来源于出色的tracing crate
依赖项
~46KB