5 releases

0.3.3 Feb 20, 2024
0.3.2 Feb 9, 2024
0.3.1 Oct 17, 2023
0.3.0 Jun 5, 2023
0.2.0 Nov 5, 2022

#15 in #memory-size

Download history 62/week @ 2024-01-03 118/week @ 2024-01-10 89/week @ 2024-01-17 55/week @ 2024-01-24 78/week @ 2024-01-31 218/week @ 2024-02-07 344/week @ 2024-02-14 732/week @ 2024-02-21 1006/week @ 2024-02-28 921/week @ 2024-03-06 795/week @ 2024-03-13 957/week @ 2024-03-20 1086/week @ 2024-03-27 880/week @ 2024-04-03 770/week @ 2024-04-10 473/week @ 2024-04-17

3,399 downloads per month
Used in 16 crates (via allocative)

MIT/Apache

15KB
344 lines

Allocative: memory profiler for Rust

This crate implements a lightweight memory profiler which allows object traversal and memory size introspection.

Usage

Allocative trait (typically implemented with proc-macro) is introspectable: Allocative values can be traversed and their size and sizes of referenced objects can be collected.

This crate provides a few utilities to work with such objects, the main of such utilities is flame graph builder which produces flame graph (see the crate documentation) like this:

sample-flamegraph.png

How it is different from other call-stack malloc profilers like jemalloc heap profiler

Allocative is not a substitute for call stack malloc profiler, it provides a different view of memory usage.

Here are some differences between allocative and call-stack malloc profiler:

  • Allocative requires implementation of Allocative trait for each type which needs to be measured, and some setup in the program to enable it is needed
  • Allocative flamegraph shows object by object tree, not by call stack
  • Allocative shows gaps in allocated memory, e.g. spare capacity of collections or too large padding in structs or enums
  • Allocative allows profiling of non-malloc allocations (for example, allocations within bumpalo bumps)
  • Allocative allows profiling of memory for subset of the process data (for example, measure the size of RPC response before serialization)

Runtime overhead

When allocative is used, binary size is slightly increased due to implementations of Allocative trait, but it has no runtime/memory overhead when it is enabled but not used.

Source code

Note there are several copies of this project on GitHub due to how Meta monorepo is synchronized to GitHub. The main copy is facebookexperimental/allocative.

License

Allocative is both MIT and Apache License, Version 2.0 licensed, as found in the LICENSE-MIT and LICENSE-APACHE files.

Dependencies

~310–760KB
~18K SLoC