pub struct AllocationHistogram { /* private fields */ }Expand description
Tracks allocation size distribution in power-of-2 buckets.
Bucket i covers the byte range [2^(i+4), 2^(i+5)), so:
- Bucket 0: [16, 32)
- Bucket 1: [32, 64)
- …
- Bucket 31: [2^35, ∞) (32 GiB and above)
Allocations smaller than 16 bytes are placed in bucket 0.
Implementations§
Source§impl AllocationHistogram
impl AllocationHistogram
Sourcepub fn bucket_index(size: usize) -> usize
pub fn bucket_index(size: usize) -> usize
Computes the bucket index for a given allocation size.
Sizes below 16 bytes map to bucket 0. The bucket index is derived from the position of the highest set bit, offset by 4 (since bucket 0 starts at 2^4 = 16).
Sourcepub fn bucket_range(index: usize) -> (usize, usize)
pub fn bucket_range(index: usize) -> (usize, usize)
Returns the (inclusive-min, exclusive-max) byte range for a bucket.
For the last bucket (index 31), the max is usize::MAX since it
covers all sizes >= 2^35.
Sourcepub fn bucket_counts(&self) -> &[u64; 32]
pub fn bucket_counts(&self) -> &[u64; 32]
Returns a reference to the raw bucket counts.
Sourcepub fn total_allocations(&self) -> u64
pub fn total_allocations(&self) -> u64
Returns the total number of allocations recorded.
Sourcepub fn percentile(&self, p: f64) -> usize
pub fn percentile(&self, p: f64) -> usize
Computes the approximate allocation size at the given percentile.
p should be in the range [0.0, 100.0]. Returns the lower bound of
the bucket that contains the p-th percentile allocation.
Returns 0 if no allocations have been recorded.
Trait Implementations§
Source§impl Clone for AllocationHistogram
impl Clone for AllocationHistogram
Source§fn clone(&self) -> AllocationHistogram
fn clone(&self) -> AllocationHistogram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more