Skip to main content

MemScope

Struct MemScope 

Source
pub struct MemScope {
    pub event_store: Arc<EventStore>,
    pub capture: Arc<CaptureEngine>,
    pub metadata: Arc<MetadataEngine>,
    pub snapshot: Arc<SnapshotEngine>,
    pub query: Arc<QueryEngine>,
    pub analysis: Arc<Mutex<AnalysisEngine>>,
    pub timeline: Arc<TimelineEngine>,
    pub render: Arc<RenderEngine>,
}
Expand description

MemScope - Unified facade for all engines

MemScope provides a simple, unified interface for memory tracking, analysis, and visualization. It integrates all 9 engines into a single, easy-to-use API.

Key properties:

  • Simple: One-stop interface for all functionality
  • Powerful: Access to all engines when needed
  • Type-safe: Strong typing throughout
  • Thread-safe: All operations are thread-safe

Fields§

§event_store: Arc<EventStore>

Event Store - Centralized event storage

§capture: Arc<CaptureEngine>

Capture Engine - Event capture backend

§metadata: Arc<MetadataEngine>

Metadata Engine - Centralized metadata management

§snapshot: Arc<SnapshotEngine>

Snapshot Engine - Snapshot construction and aggregation

§query: Arc<QueryEngine>

Query Engine - Unified query interface

§analysis: Arc<Mutex<AnalysisEngine>>

Analysis Engine - Memory analysis logic (wrapped in Mutex for interior mutability)

§timeline: Arc<TimelineEngine>

Timeline Engine - Time-based memory analysis

§render: Arc<RenderEngine>

Render Engine - Output rendering

Implementations§

Source§

impl MemScope

Source

pub fn new() -> Self

Create a new MemScope instance

This creates all engines with default settings and connects them together in the correct configuration.

Source

pub fn with_backend(backend_type: CaptureBackendType) -> Self

Create a new MemScope instance with a specific capture backend

§Arguments
  • backend_type - The type of capture backend to use
Source

pub fn register_analyzer(&self, analyzer: Box<dyn Analyzer>)

Register an analyzer with the analysis engine

§Arguments
  • analyzer - The analyzer to register
Source

pub fn summary(&self) -> QueryResult

Get a summary of current memory usage

Source

pub fn top_allocations(&self, limit: usize) -> QueryResult

Get top allocations by size

§Arguments
  • limit - Maximum number of allocations to return
Source

pub fn render_json(&self, verbose: bool) -> Result<RenderResult, String>

Render current snapshot to JSON

§Arguments
  • verbose - Whether to include verbose output
Source

pub fn clear(&self)

Clear all events and reset state

Source

pub fn event_count(&self) -> usize

Get the total number of events

Source

pub fn register_detector<D>(&self, detector: D)
where D: Detector + Send + Sync + 'static,

Register a detector with the analysis engine

This method automatically wraps the detector in an adapter and registers it as an analyzer.

§Arguments
  • detector - The detector to register
Source

pub fn run_detectors(&self) -> Vec<AnalysisResult>

Run all registered detectors and return the results

§Returns

A vector of analysis results from all detectors

Source

pub fn run_leak_detector(&self) -> DetectionResult

Run the leak detector on the current snapshot

§Returns

Detection results from the leak detector

Source

pub fn run_uaf_detector(&self) -> DetectionResult

Run the UAF (Use-After-Free) detector on the current snapshot

§Returns

Detection results from the UAF detector

Source

pub fn run_overflow_detector(&self) -> DetectionResult

Run the overflow detector on the current snapshot

§Returns

Detection results from the overflow detector

Source

pub fn run_safety_detector(&self) -> DetectionResult

Run the safety detector on the current snapshot

§Returns

Detection results from the safety detector

Source

pub fn run_lifecycle_detector(&self) -> DetectionResult

Run the lifecycle detector on the current snapshot

§Returns

Detection results from the lifecycle detector

Source

pub fn export_html_with_template<P: AsRef<Path>>( &self, path: P, template: DashboardTemplate, ) -> Result<(), String>

Export the current memory snapshot as an HTML dashboard with a specific template

§Arguments
  • path - Directory path where the HTML file will be saved
  • template - The dashboard template to use
§Returns

Result indicating success or failure

Source

pub fn export_html<P: AsRef<Path>>(&self, path: P) -> Result<(), String>

Export the current memory snapshot as an HTML dashboard

This method automatically detects program characteristics and selects the most appropriate template:

  • Multithread: If the program uses multiple threads
  • Binary: Default template for single-threaded programs
§Arguments
  • path - Directory path where the HTML file will be saved
§Returns

Result indicating success or failure

Source

pub fn export_json<P: AsRef<Path>>(&self, path: P) -> Result<(), String>

Export all JSON files

This method exports 9 JSON files containing comprehensive memory analysis:

  • memory_analysis.json: Complete memory allocation analysis
  • lifetime.json: Ownership and lifetime tracking
  • ownership_graph.json: Ownership graph analysis with cycle detection
  • system_resources.json: System resource monitoring
  • thread_analysis.json: Thread-specific memory stats
  • unsafe_ffi.json: Unsafe FFI boundary tracking
  • memory_passports.json: Memory lifecycle passports
  • leak_detection.json: Potential memory leaks
  • async_analysis.json: Async task analysis
§Arguments
  • path - Directory path where JSON files will be saved
§Returns

Result indicating success or failure

Trait Implementations§

Source§

impl Default for MemScope

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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