Struct MemoryTracker

Source
pub struct MemoryTracker { /* private fields */ }
Expand description

Core memory tracking functionality.

The MemoryTracker maintains records of all memory allocations and deallocations, provides statistics, and supports exporting data in various formats.

Implementations§

Source§

impl MemoryTracker

Source

pub fn new() -> Self

Create a new memory tracker.

Source

pub fn track_allocation(&self, ptr: usize, size: usize) -> TrackingResult<()>

Track a new memory allocation.

Source

pub fn track_deallocation(&self, ptr: usize) -> TrackingResult<()>

Track a memory deallocation.

Source

pub fn associate_var( &self, ptr: usize, var_name: String, type_name: String, ) -> TrackingResult<()>

Associate a variable name and type with an allocation.

Source

pub fn get_stats(&self) -> TrackingResult<MemoryStats>

Get current memory usage statistics.

Source

pub fn get_active_allocations(&self) -> TrackingResult<Vec<AllocationInfo>>

Get all currently active allocations.

Source

pub fn get_allocation_history(&self) -> TrackingResult<Vec<AllocationInfo>>

Get the complete allocation history.

Source

pub fn get_memory_by_type(&self) -> TrackingResult<Vec<TypeMemoryUsage>>

Get memory usage grouped by type.

Source

pub fn export_to_json<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>

Export memory data to JSON format with hierarchical structure.

Source

pub fn export_memory_analysis<P: AsRef<Path>>( &self, path: P, ) -> TrackingResult<()>

Export memory analysis visualization showing variable names, types, and usage patterns. This creates a comprehensive memory analysis with call stack analysis, timeline, and categorization.

§Arguments
  • path - Output path for the memory analysis SVG file (recommended: “program_name_memory_analysis.svg”)
Source

pub fn export_lifecycle_timeline<P: AsRef<Path>>( &self, path: P, ) -> TrackingResult<()>

Export interactive lifecycle timeline showing variable lifecycles and relationships. This creates an advanced timeline with variable birth, life, death, and cross-section interactivity.

§Arguments
  • path - Output path for the lifecycle timeline SVG file (recommended: “program_name_lifecycle.svg”)
Source

pub fn export_to_svg<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>

👎Deprecated since 0.1.0: Use export_memory_analysis instead

Legacy export method for backward compatibility. Redirects to the new memory analysis export.

§Arguments
  • path - Output path for the SVG file

Trait Implementations§

Source§

impl Default for MemoryTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more