### Display Heap Statistics and Histograms Source: https://docs.rs/crate/heapster Example output generated by the fmt feature, showing allocation counts, averages, and power-of-two size distribution histograms. ```text alloc_count: 10,949,628 alloc_avg: 2.45 KiB dealloc_count: 10,949,372 dealloc_avg: 4.09 KiB realloc_growth_count: 365,968 realloc_growth_avg: 49.12 KiB realloc_move_count: 351,933 realloc_move_avg: 7.21 KiB use_curr: 260.39 KiB use_max: 25.01 MiB alloc_histogram: [ 4 B .. 8 B): 2 █ [ 8 B .. 16 B): 642,064 ███████████ [ 16 B .. 32 B): 155 █ [ 32 B .. 64 B): 1,639,279 █████████████████████████████ [ 64 B .. 128 B): 1,926,643 ██████████████████████████████████ [ 128 B .. 256 B): 1,123,746 ████████████████████ [ 256 B .. 512 B): 1,284,154 ██████████████████████ [ 512 B .. 1 KiB): 2,246,658 ████████████████████████████████████████ [ 1 KiB .. 2 KiB): 1,283,935 ██████████████████████ [ 2 KiB .. 4 KiB): 160,612 ██ [ 4 KiB .. 8 KiB): 411 █ [ 8 KiB .. 16 KiB): 320,985 █████ [ 16 KiB .. 32 KiB): 1 █ [ 32 KiB .. 64 KiB): 1 █ [ 64 KiB .. 128 KiB): 320,982 █████ realloc_growth_histogram: [ 1 B .. 2 B): 16 █ [ 2 B .. 4 B): 0 [ 4 B .. 8 B): 0 [ 8 B .. 16 B): 0 [ 16 B .. 32 B): 0 [ 32 B .. 64 B): 25,477 ███ [ 64 B .. 128 B): 14,976 █ [ 128 B .. 256 B): 4,411 █ [ 256 B .. 512 B): 106 █ [ 512 B .. 1 KiB): 0 [ 1 KiB .. 2 KiB): 0 [ 2 KiB .. 4 KiB): 0 [ 4 KiB .. 8 KiB): 0 [ 8 KiB .. 16 KiB): 0 [ 16 KiB .. 32 KiB): 0 [ 32 KiB .. 64 KiB): 320,982 ████████████████████████████████████████ ``` -------------------------------- ### Initialize Global Allocator Source: https://docs.rs/crate/heapster Wrap the system allocator with Heapster to begin tracking heap metrics. ```rust use heapster::Heapster; use std::alloc::System; #[global_allocator] static GLOBAL: Heapster = Heapster::new(System); fn main() { // ... do some heavy work ... // See what has transpired in the heap println!("{}", GLOBAL.stats()); } ``` -------------------------------- ### Add Heapster Dependency Source: https://docs.rs/crate/heapster Include the heapster crate in your project's Cargo.toml file. ```toml [dependencies] heapster = { version = "0.X" } ``` -------------------------------- ### Measure Heap Usage Source: https://docs.rs/crate/heapster Use the measure method to capture heap statistics for a specific closure execution. ```rust let (result, heap_diff) = GLOBAL.measure(|| operation_to_measure()); assert!(heap_diff.alloc_count < 10, "Regression: The operation allocated too many times!"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.