pub struct MemoryTracker { /* private fields */ }Expand description
Tracks tensor memory allocations for profiling.
Call [alloc] when a tensor is created and [dealloc] when freed.
§Example
use shrew::profiler::MemoryTracker;
let mut mem = MemoryTracker::new();
mem.alloc("weight", 1024 * 4);
mem.alloc("bias", 128 * 4);
assert_eq!(mem.current_bytes(), 1024 * 4 + 128 * 4);
mem.dealloc("bias");
assert_eq!(mem.current_bytes(), 1024 * 4);Implementations§
Source§impl MemoryTracker
impl MemoryTracker
Sourcepub fn current_bytes(&self) -> usize
pub fn current_bytes(&self) -> usize
Current live memory in bytes.
Sourcepub fn peak_bytes(&self) -> usize
pub fn peak_bytes(&self) -> usize
Peak memory usage in bytes.
Sourcepub fn total_allocated(&self) -> usize
pub fn total_allocated(&self) -> usize
Total bytes allocated over the tracker’s lifetime.
Sourcepub fn alloc_count(&self) -> usize
pub fn alloc_count(&self) -> usize
Number of allocations recorded.
Sourcepub fn dealloc_count(&self) -> usize
pub fn dealloc_count(&self) -> usize
Number of deallocations recorded.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of currently live allocations.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MemoryTracker
impl RefUnwindSafe for MemoryTracker
impl Send for MemoryTracker
impl Sync for MemoryTracker
impl Unpin for MemoryTracker
impl UnwindSafe for MemoryTracker
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
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>
Converts
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>
Converts
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