alloc-metrics 0.1.1

A global allocator that tracks allocation metrics
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented2 out of 6 items with examples
  • Size
  • Source code size: 25.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.8 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dragazo/alloc-metrics
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dragazo

Description

alloc-metrics is a simple crate that adds a new global allocator type that tracks the total number of allocations and actual bytes allocated. In typical programs, this could be useful to get a plot of memory utilization over time for debugging purposes, or could be used in interpreter runtimes to limit the amount of memory a script is allowed to use.

Setup

To get started using alloc-metrics, you must first set the global allocator for your project:

use alloc_metrics::MetricAlloc;

#[global_allocator]
static GLOBAL: MetricAlloc<std::alloc::System> = MetricAlloc::new(std::alloc::System);

Note that the [MetricAlloc] type is able to wrap any existing global allocator type. Thus, you can compose the features of alloc-metrics with any other global allocator you want.

Features

  • thread: gives access to thread-local allocation metrics (requires std).
  • global: gives access to global allocation metrics.

no-std

This crate is fully compatible in no-std environments by disabling default features:

alloc-metrics = { version = "...", default-features = false, features = ["global"] }

Note that we re-enabled the global feature so that we still have access to global allocation metrics (see feature list above).