Utilities developed to measure memory usage in projects with mixed Rust/C++ code while having minimizing performance/memory overhead.

Goals

Requirements

Design

Rust allocator proxy: Tracking Rust allocation is done by adding a proxy, which uses jemalloc and add 32 bytes header to all allocations. See https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html

C allocator proxy: Tracking C allocator is done in by overriding dynamic links to malloc/free/etc. This can be overriden by providing an enviroment variable while running an executable `LD_PRELOAD=./mtrace.so path'.

dump script: * Reads process memory mapping from /proc/<PID>/smaps. * It's able to identify which pages are present by reading from /proc/<PID>/pagemap. * It reads memory using /proc/<PID>/pagemap * Once memory is read, regions of memory allocated by Rust/C code can be identified by looking for MAGIC keyword, which is part of the header.

The core tool is in dump.cpp file. It dumps the program memory and it prints memory statistics.

Modules