Crates.io | near-rust-allocator-proxy |
lib.rs | near-rust-allocator-proxy |
version | 0.4.0 |
source | src |
created_at | 2021-02-10 06:14:33.995224 |
updated_at | 2022-01-19 23:53:31.399745 |
description | Rust allocator proxy with added header |
homepage | |
repository | https://github.com/near/near-memory-tracker |
max_upload_size | |
id | 353105 |
size | 19,581 |
Track Rust memory usage by adding a 32 bytes header to all allocations. See https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html
You can use code below to enable usage of this library:
use near_rust_allocator_proxy::allocator::MyAllocator;
use jemallocator::Jemalloc;
#[global_allocator]
static ALLOC: MyAllocator<Jemalloc> = MyAllocator::new(Jemalloc);
thread_memory_usage(tid)
method can be used to get amount of memory allocated by threadPRINT_STACK_TRACE_ON_MEMORY_SPIKE
- if set to true a stack trace will be used on memory spikeENABLE_STACK_TRACE
- if enabled backtrace
will get executed on each allocation and stack pointer will be added to the headerMIN_BLOCK_SIZE
- if allocation size of below MIN_BLOCK_SIZE
, we will only run backtrace
SMALL_BLOCK_TRACE_PROBABILITY
percentage of timeSMALL_BLOCK_TRACE_PROBABILITY
- probability of running a stack trace for small allocationsREPORT_USAGE_INTERVAL
- if printing memory spikes is enabled print if memory usage exceeded this value in bytesPRINT_STACK_TRACE_ON_MEMORY_SPIKE
- if true print stack trace when memory usage exceeds REPORT_USAGE_INTERVAL
on given Rust threadAllocation structure:
#[repr(C)]
struct AllocHeader {
magic: u64,
size: u64,
tid: u64,
stack: [*mut c_void; STACK_SIZE],
}