pub struct MemoryBudget { /* private fields */ }Expand description
Memory budget tracker.
Checks reported memory usage against configured thresholds and produces alerts with recommended degradation levels.
Implementations§
Source§impl MemoryBudget
impl MemoryBudget
Sourcepub fn new(config: MemoryBudgetConfig) -> Self
pub fn new(config: MemoryBudgetConfig) -> Self
Create a new memory budget with the given configuration.
Sourcepub fn check(&mut self, current_bytes: usize) -> Option<GuardrailAlert>
pub fn check(&mut self, current_bytes: usize) -> Option<GuardrailAlert>
Report current memory usage and get an alert if thresholds are exceeded.
Sourcepub fn current_bytes(&self) -> usize
pub fn current_bytes(&self) -> usize
Current memory usage in bytes.
Sourcepub fn peak_bytes(&self) -> usize
pub fn peak_bytes(&self) -> usize
Peak memory usage observed since creation or last reset.
Sourcepub fn usage_fraction(&self) -> f64
pub fn usage_fraction(&self) -> f64
Fraction of soft limit currently used (0.0 = empty, 1.0 = at limit).
Sourcepub fn soft_violations(&self) -> u32
pub fn soft_violations(&self) -> u32
Number of frames where the soft limit was exceeded.
Sourcepub fn hard_violations(&self) -> u32
pub fn hard_violations(&self) -> u32
Number of frames where the hard limit was exceeded.
Sourcepub fn config(&self) -> &MemoryBudgetConfig
pub fn config(&self) -> &MemoryBudgetConfig
Get a reference to the configuration.
Trait Implementations§
Source§impl Clone for MemoryBudget
impl Clone for MemoryBudget
Source§fn clone(&self) -> MemoryBudget
fn clone(&self) -> MemoryBudget
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryBudget
impl RefUnwindSafe for MemoryBudget
impl Send for MemoryBudget
impl Sync for MemoryBudget
impl Unpin for MemoryBudget
impl UnsafeUnpin for MemoryBudget
impl UnwindSafe for MemoryBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more