Crate allocative

Source
Expand description

§Allocative

Crate implements lightweight memory profiler which allows object traversal and size introspection.

An object implementing Allocative trait is introspectable, and this crate provides two utilities to work with such objects:

§Allocative 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 not used.

§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 on 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
  • 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 non-malloc allocations (for example, allocations within bumpalo)
  • Allocative allows profiling of memory for subset of the process data (for example, measure the size of RPC response before serialization)

Macros§

ident_key
Create a const of type Key with the provided ident as the value and return that value. This allows the keys to be placed conveniently inline without any performance hit because unlike calling Key::new this is guaranteed to be evaluated at compile time.

Structs§

FlameGraph
Node in flamegraph tree.
FlameGraphBuilder
Build a flamegraph from given root objects.
Key
Hashed string, which is a key while descending into a tree (e.g. type name or field name).
Visitor

Traits§

Allocative
This trait allows traversal of object graph.

Functions§

register_root
Register global root which can be later traversed by profiler.
size_of_unique
Size of a piece of data and data allocated in unique pointers in the struct.
size_of_unique_allocated_data
Size of data allocated in unique pointers in the struct.

Attribute Macros§

root

Derive Macros§

Allocative