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
impl MemScope
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MemScope instance
This creates all engines with default settings and connects them together in the correct configuration.
Sourcepub fn with_backend(backend_type: CaptureBackendType) -> Self
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
Sourcepub fn register_analyzer(&self, analyzer: Box<dyn Analyzer>)
pub fn register_analyzer(&self, analyzer: Box<dyn Analyzer>)
Sourcepub fn summary(&self) -> QueryResult
pub fn summary(&self) -> QueryResult
Get a summary of current memory usage
Sourcepub fn top_allocations(&self, limit: usize) -> QueryResult
pub fn top_allocations(&self, limit: usize) -> QueryResult
Sourcepub fn render_json(&self, verbose: bool) -> Result<RenderResult, String>
pub fn render_json(&self, verbose: bool) -> Result<RenderResult, String>
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Get the total number of events
Sourcepub fn register_detector<D>(&self, detector: D)
pub fn register_detector<D>(&self, detector: D)
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
Sourcepub fn run_detectors(&self) -> Vec<AnalysisResult>
pub fn run_detectors(&self) -> Vec<AnalysisResult>
Run all registered detectors and return the results
§Returns
A vector of analysis results from all detectors
Sourcepub fn run_leak_detector(&self) -> DetectionResult
pub fn run_leak_detector(&self) -> DetectionResult
Sourcepub fn run_uaf_detector(&self) -> DetectionResult
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
Sourcepub fn run_overflow_detector(&self) -> DetectionResult
pub fn run_overflow_detector(&self) -> DetectionResult
Run the overflow detector on the current snapshot
§Returns
Detection results from the overflow detector
Sourcepub fn run_safety_detector(&self) -> DetectionResult
pub fn run_safety_detector(&self) -> DetectionResult
Sourcepub fn run_lifecycle_detector(&self) -> DetectionResult
pub fn run_lifecycle_detector(&self) -> DetectionResult
Run the lifecycle detector on the current snapshot
§Returns
Detection results from the lifecycle detector
Sourcepub fn export_html_with_template<P: AsRef<Path>>(
&self,
path: P,
template: DashboardTemplate,
) -> Result<(), String>
pub fn export_html_with_template<P: AsRef<Path>>( &self, path: P, template: DashboardTemplate, ) -> Result<(), String>
Sourcepub fn export_html<P: AsRef<Path>>(&self, path: P) -> Result<(), String>
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
Sourcepub fn export_json<P: AsRef<Path>>(&self, path: P) -> Result<(), String>
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§
Auto Trait Implementations§
impl Freeze for MemScope
impl !RefUnwindSafe for MemScope
impl Send for MemScope
impl Sync for MemScope
impl Unpin for MemScope
impl UnsafeUnpin for MemScope
impl !UnwindSafe for MemScope
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
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