Skip to main content

Crate libdd_profiling_heap_allocator

Crate libdd_profiling_heap_allocator 

Source
Expand description

Rust GlobalAlloc wrapper that drives libdd-profiling-heap-sampler around each allocation. Wrap any underlying allocator with SampledAllocator; on each alloc/dealloc the sampler’s decision/flag/USDT machinery runs around the inner call.

SampledAllocator is portable across targets, so callers can use it in a single #[global_allocator] static without cfg-gating. The sampling integration (USDT probes via libdd-profiling-heap-sampler) is Linux-only; on every other target the wrapper compiles to a transparent pass-through to the inner allocator.

§Features

  • live-heap (off by default) - enables live-heap tracking: sampled allocations are flagged at alloc time, and that flag is detected again on free, so a profiler can pair each free back to its sample and balance allocs against frees. Off = allocation profiling only.

§Example

use libdd_profiling_heap_allocator::{
    SampledAllocator, is_profiler_attached, set_default_sampling_distance,
};
use std::alloc::System;

#[global_allocator]
static ALLOC: SampledAllocator<System> = SampledAllocator::<System>::DEFAULT;

fn main() {
    // Configure the mean sample distance before the application's
    // allocation-heavy work begins. New threads pick up this value
    // when their sampler state is first initialized.
    set_default_sampling_distance(256 * 1024);

    // ... application runs ...
}

Structs§

SampledAllocator
GlobalAlloc wrapper that routes each alloc/dealloc through libdd-profiling-heap-sampler before forwarding to the inner allocator A.

Functions§

is_profiler_attached
Returns true when an external profiler is currently attached to the allocator’s ddheap:alloc USDT.
set_default_sampling_distance
Set the default mean sample distance (bytes between samples) for the heap sampler.