pub struct InferenceMemoryTracker {
pub events: Vec<AllocEvent>,
pub regions: HashMap<u64, RegionInfo>,
pub live_bytes: u64,
pub peak_bytes: u64,
pub stats: TrackerStats,
}Expand description
Tracks memory allocations made during a single inference session.
Record AllocEvents via InferenceMemoryTracker::record, then query
the current state via InferenceMemoryTracker::snapshot,
InferenceMemoryTracker::leaked_regions, and
InferenceMemoryTracker::memory_by_rule.
Fields§
§events: Vec<AllocEvent>Full, ordered event log.
regions: HashMap<u64, RegionInfo>Map from region_id to its RegionInfo.
live_bytes: u64Current live byte total.
peak_bytes: u64Highest live_bytes value seen so far.
stats: TrackerStatsAggregate counters.
Implementations§
Source§impl InferenceMemoryTracker
impl InferenceMemoryTracker
Sourcepub fn record(&mut self, event: AllocEvent)
pub fn record(&mut self, event: AllocEvent)
Records an event and updates internal state accordingly.
AllocEvent::Alloc: inserts a newRegionInfo, increaseslive_bytes, and updatespeak_bytes.AllocEvent::Free: marks the region freed and decreaseslive_bytes. Silently ignored when the region is not found or already freed (double-free).AllocEvent::Checkpoint: just appended to the event log.
Sourcepub fn snapshot(&self) -> MemorySnapshot
pub fn snapshot(&self) -> MemorySnapshot
Returns a snapshot of the current memory state.
leaked_bytes is the sum of size_bytes for every region that has
never been freed.
Sourcepub fn memory_by_rule(&self, rule_id: u64) -> u64
pub fn memory_by_rule(&self, rule_id: u64) -> u64
Returns the total bytes currently held by live regions associated with
the given rule_id.
Sourcepub fn leaked_regions(&self) -> Vec<&RegionInfo>
pub fn leaked_regions(&self) -> Vec<&RegionInfo>
Returns references to all regions that have not been freed.
Sourcepub fn stats(&self) -> &TrackerStats
pub fn stats(&self) -> &TrackerStats
Returns a reference to the aggregate counters.
Trait Implementations§
Source§impl Debug for InferenceMemoryTracker
impl Debug for InferenceMemoryTracker
Auto Trait Implementations§
impl Freeze for InferenceMemoryTracker
impl RefUnwindSafe for InferenceMemoryTracker
impl Send for InferenceMemoryTracker
impl Sync for InferenceMemoryTracker
impl Unpin for InferenceMemoryTracker
impl UnsafeUnpin for InferenceMemoryTracker
impl UnwindSafe for InferenceMemoryTracker
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more