unkai
Unkai is a tool set for Rust's memory allocation APIs mainly focus on tracking and conditional analyzing / limiting memory usage.
Basic Usage
It's now compatible with two major forms of allocator API in the standard library:
GlobalAlloc: the global memory allocator for all default memory allocation.Allocator: the unstable allocator API (tracking issue) that allows changingAllocatorfor a specific struct likeBoxorVec.
Use with GlobalAlloc
The entrypoint is [UnkaiGlobalAlloc]. Only need to wrap your original global
allocator with [UnkaiGlobalAlloc] like this:
use Jemalloc;
use UnkaiGlobalAlloc;
static UNKAI: = new;
Use with Allocator
Notice that Allocator only available when the unstable feature allocator_api
is enabled via #![feature(allocator_api)]. And enabling unstable feature requires
the nigntly channel Rust toolchain.
The entrypoint is [Unkai]. Example usage:
let mut vec_container: = Vecwith_capacity_in;
assert_eq!;
There is also an example file examples/allocator.rs that shows more usages.
Tracking allocation
TBD
Supported Feature
GlobalAlloc- Capture and record backtrace with memory consumption
Roadmap
GlobalAlloc- Record pointer's lifetime
Allocator- Tree-structured
- Low-overhead in-use statistics
- General
- Prometheus integration
- Build-in report generation
Example
There are some example files under examples/. They are:
allocator.rs: shows the usage ofAllocatorwrapper to track memory consumption at runtime.collections.rs: shows the usage ofGlobalAllocand stack tracking
To run example, use command like the following: