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
impl MemoryTracker
Sourcepub fn is_fast_mode(&self) -> bool
pub fn is_fast_mode(&self) -> bool
Check if tracker is in fast mode (for testing)
Sourcepub fn enable_fast_mode(&self)
pub fn enable_fast_mode(&self)
Enable fast mode for testing
Sourcepub fn fast_track_allocation(
&self,
ptr: usize,
size: usize,
var_name: String,
) -> TrackingResult<()>
pub fn fast_track_allocation( &self, ptr: usize, size: usize, var_name: String, ) -> TrackingResult<()>
Fast track allocation for testing (minimal overhead)
Sourcepub fn analyze_memory_layout(
&self,
type_name: &str,
size: usize,
) -> Option<MemoryLayoutInfo>
pub fn analyze_memory_layout( &self, type_name: &str, size: usize, ) -> Option<MemoryLayoutInfo>
Analyze memory layout information
Sourcepub fn analyze_generic_type(
&self,
type_name: &str,
size: usize,
) -> Option<GenericTypeInfo>
pub fn analyze_generic_type( &self, type_name: &str, size: usize, ) -> Option<GenericTypeInfo>
Analyze generic type information
Sourcepub fn analyze_dynamic_type(
&self,
type_name: &str,
size: usize,
) -> Option<DynamicTypeInfo>
pub fn analyze_dynamic_type( &self, type_name: &str, size: usize, ) -> Option<DynamicTypeInfo>
Analyze dynamic type information (trait objects)
Sourcepub fn collect_runtime_state(&self) -> RuntimeStateInfo
pub fn collect_runtime_state(&self) -> RuntimeStateInfo
Collect runtime state information
Sourcepub fn analyze_stack_allocation(
&self,
type_name: &str,
ptr: usize,
) -> Option<StackAllocationInfo>
pub fn analyze_stack_allocation( &self, type_name: &str, ptr: usize, ) -> Option<StackAllocationInfo>
Analyze stack allocation information
Sourcepub fn analyze_temporary_object(
&self,
type_name: &str,
ptr: usize,
) -> Option<TemporaryObjectInfo>
pub fn analyze_temporary_object( &self, type_name: &str, ptr: usize, ) -> Option<TemporaryObjectInfo>
Analyze temporary object information
Sourcepub fn analyze_memory_fragmentation(&self) -> EnhancedFragmentationAnalysis
pub fn analyze_memory_fragmentation(&self) -> EnhancedFragmentationAnalysis
Analyze memory fragmentation
Sourcepub fn analyze_generic_instantiation(
&self,
type_name: &str,
size: usize,
) -> Option<GenericInstantiationInfo>
pub fn analyze_generic_instantiation( &self, type_name: &str, size: usize, ) -> Option<GenericInstantiationInfo>
Analyze enhanced generic instantiation
Sourcepub fn analyze_type_relationships(
&self,
type_name: &str,
) -> Option<TypeRelationshipInfo>
pub fn analyze_type_relationships( &self, type_name: &str, ) -> Option<TypeRelationshipInfo>
Analyze type relationships
Sourcepub fn track_type_usage(&self, type_name: &str) -> Option<TypeUsageInfo>
pub fn track_type_usage(&self, type_name: &str) -> Option<TypeUsageInfo>
Track type usage
Sourcepub fn track_function_calls(
&self,
scope_name: Option<&str>,
) -> Option<FunctionCallTrackingInfo>
pub fn track_function_calls( &self, scope_name: Option<&str>, ) -> Option<FunctionCallTrackingInfo>
Track function calls
Sourcepub fn track_object_lifecycle(
&self,
ptr: usize,
type_name: &str,
) -> Option<ObjectLifecycleInfo>
pub fn track_object_lifecycle( &self, ptr: usize, type_name: &str, ) -> Option<ObjectLifecycleInfo>
Track object lifecycle
Sourcepub fn track_memory_access_patterns(
&self,
ptr: usize,
size: usize,
) -> Option<MemoryAccessTrackingInfo>
pub fn track_memory_access_patterns( &self, ptr: usize, size: usize, ) -> Option<MemoryAccessTrackingInfo>
Track memory access patterns
Sourcepub fn track_allocation(&self, ptr: usize, size: usize) -> TrackingResult<()>
pub fn track_allocation(&self, ptr: usize, size: usize) -> TrackingResult<()>
Track a new memory allocation.
Sourcepub fn track_deallocation(&self, ptr: usize) -> TrackingResult<()>
pub fn track_deallocation(&self, ptr: usize) -> TrackingResult<()>
Track a memory deallocation.
Sourcepub fn track_deallocation_with_lifetime(
&self,
ptr: usize,
lifetime_ms: u64,
) -> TrackingResult<()>
pub fn track_deallocation_with_lifetime( &self, ptr: usize, lifetime_ms: u64, ) -> TrackingResult<()>
Track a memory deallocation with precise lifetime information. This method is specifically designed for TrackedVariable to ensure accurate lifetime_ms calculation.
Sourcepub fn update_allocation_info(
&self,
ptr: usize,
var_name: String,
type_name: String,
) -> TrackingResult<()>
pub fn update_allocation_info( &self, ptr: usize, var_name: String, type_name: String, ) -> TrackingResult<()>
Update allocation info for an existing allocation without creating duplicates.
Sourcepub fn create_synthetic_allocation(
&self,
ptr: usize,
size: usize,
var_name: String,
type_name: String,
creation_time: u64,
) -> TrackingResult<()>
pub fn create_synthetic_allocation( &self, ptr: usize, size: usize, var_name: String, type_name: String, creation_time: u64, ) -> TrackingResult<()>
Create a synthetic allocation for smart pointers (Rc/Arc) that don’t go through the allocator.
Sourcepub fn create_smart_pointer_allocation(
&self,
ptr: usize,
size: usize,
var_name: String,
type_name: String,
creation_time: u64,
ref_count: usize,
data_ptr: usize,
) -> TrackingResult<()>
pub fn create_smart_pointer_allocation( &self, ptr: usize, size: usize, var_name: String, type_name: String, creation_time: u64, ref_count: usize, data_ptr: usize, ) -> TrackingResult<()>
Create a specialized synthetic allocation for Rc/Arc with reference counting support.
Sourcepub fn track_smart_pointer_clone(
&self,
clone_ptr: usize,
source_ptr: usize,
data_ptr: usize,
new_ref_count: usize,
weak_count: usize,
) -> TrackingResult<()>
pub fn track_smart_pointer_clone( &self, clone_ptr: usize, source_ptr: usize, data_ptr: usize, new_ref_count: usize, weak_count: usize, ) -> TrackingResult<()>
Track smart pointer clone relationship
Sourcepub fn update_smart_pointer_ref_count(
&self,
ptr: usize,
strong_count: usize,
weak_count: usize,
) -> TrackingResult<()>
pub fn update_smart_pointer_ref_count( &self, ptr: usize, strong_count: usize, weak_count: usize, ) -> TrackingResult<()>
Update reference count for a smart pointer
Sourcepub fn mark_smart_pointer_data_deallocated(
&self,
data_ptr: usize,
) -> TrackingResult<()>
pub fn mark_smart_pointer_data_deallocated( &self, data_ptr: usize, ) -> TrackingResult<()>
Mark smart pointer data as implicitly deallocated
Sourcepub fn track_smart_pointer_deallocation(
&self,
ptr: usize,
lifetime_ms: u64,
final_ref_count: usize,
) -> TrackingResult<()>
pub fn track_smart_pointer_deallocation( &self, ptr: usize, lifetime_ms: u64, final_ref_count: usize, ) -> TrackingResult<()>
Track the deallocation of a smart pointer with enhanced metadata.
Sourcepub fn enhance_allocation_info(&self, allocation: &mut AllocationInfo)
pub fn enhance_allocation_info(&self, allocation: &mut AllocationInfo)
Enhance allocation information with detailed analysis
Sourcepub fn associate_var(
&self,
ptr: usize,
var_name: String,
type_name: String,
) -> TrackingResult<()>
pub fn associate_var( &self, ptr: usize, var_name: String, type_name: String, ) -> TrackingResult<()>
Associate a variable name and type with an allocation.
Sourcepub fn get_stats(&self) -> TrackingResult<MemoryStats>
pub fn get_stats(&self) -> TrackingResult<MemoryStats>
Get current memory usage statistics with advanced analysis.
Sourcepub fn get_active_allocations(&self) -> TrackingResult<Vec<AllocationInfo>>
pub fn get_active_allocations(&self) -> TrackingResult<Vec<AllocationInfo>>
Get all currently active allocations.
Sourcepub fn get_allocation_history(&self) -> TrackingResult<Vec<AllocationInfo>>
pub fn get_allocation_history(&self) -> TrackingResult<Vec<AllocationInfo>>
Get the complete allocation history.
Sourcepub fn get_memory_by_type(&self) -> TrackingResult<Vec<TypeMemoryUsage>>
pub fn get_memory_by_type(&self) -> TrackingResult<Vec<TypeMemoryUsage>>
Get memory usage grouped by type with smart inference.
Sourcepub fn export_interactive_dashboard<P: AsRef<Path>>(
&self,
path: P,
) -> TrackingResult<()>
pub fn export_interactive_dashboard<P: AsRef<Path>>( &self, path: P, ) -> TrackingResult<()>
Export interactive HTML dashboard with embedded SVG charts
Sourcepub fn export_memory_analysis<P: AsRef<Path>>(
&self,
path: P,
) -> TrackingResult<()>
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. All output files are automatically placed in the MemoryAnalysis/ directory.
§Arguments
path
- Output filename for the memory analysis SVG file (recommended: “program_name_memory_analysis.svg”)
Sourcepub fn export_lifecycle_timeline<P: AsRef<Path>>(
&self,
path: P,
) -> TrackingResult<()>
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. All output files are automatically placed in the MemoryAnalysis/ directory.
§Arguments
path
- Output filename for the lifecycle timeline SVG file (recommended: “program_name_lifecycle.svg”)
Sourcepub fn export_to_json<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>
pub fn export_to_json<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>
Export memory tracking data to 4 separate JSON files.
This method exports data to 4 specialized files:
- {name}_memory_analysis.json: Memory allocation patterns and statistics
- {name}_lifetime.json: Variable lifetime and scope analysis
- {name}_unsafe_ffi.json: Unsafe operations and FFI tracking
- {name}_variable_relationships.json: Variable dependency graph and relationships
§Export Modes
§Default Mode (Fast - Recommended)
tracker.export_to_json("output")?;
// OR explicitly
tracker.export_to_json_with_options("output", ExportOptions::default())?;
- Performance: ~2-5 seconds for typical datasets
- Data: Only user-tracked variables get full enrichment
- Use case: Normal development, HTML rendering, production monitoring
§Complete Mode (Slow - Debug Only)
let options = ExportOptions::new().include_system_allocations(true);
tracker.export_to_json_with_options("output", options)?;
- Performance: ~10-40 seconds (5-10x slower!)
- Data: ALL allocations including system internals get full enrichment
- Use case: Deep debugging, memory leak investigation, system analysis
- ⚠️ Warning: Very slow, generates large files, may impact application performance
Sourcepub fn export_to_json_with_options<P: AsRef<Path>>(
&self,
path: P,
options: ExportOptions,
) -> TrackingResult<()>
pub fn export_to_json_with_options<P: AsRef<Path>>( &self, path: P, options: ExportOptions, ) -> TrackingResult<()>
Export memory tracking data with custom options.
§Examples
§Fast mode (default - recommended for most users)
tracker.export_to_json_with_options("output", ExportOptions::default())?;
§Complete mode (slow - for debugging)
let options = ExportOptions::new()
.include_system_allocations(true)
.verbose_logging(true);
tracker.export_to_json_with_options("debug_output", options)?;
Source§impl MemoryTracker
impl MemoryTracker
Sourcepub fn generate_timeline_data(
&self,
allocation_history: &[AllocationInfo],
_active_allocations: &[AllocationInfo],
) -> TimelineData
pub fn generate_timeline_data( &self, allocation_history: &[AllocationInfo], _active_allocations: &[AllocationInfo], ) -> TimelineData
Generate timeline data with stack traces and hotspots
Source§impl MemoryTracker
Main export interface - unified entry point for all JSON export operations
impl MemoryTracker
Main export interface - unified entry point for all JSON export operations
Sourcepub fn export_to_json_fast<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>
pub fn export_to_json_fast<P: AsRef<Path>>(&self, path: P) -> TrackingResult<()>
[CONVENIENCE] Quick export with performance optimization
This method provides a convenient way to export with performance-focused settings. Ideal for production environments where speed is more important than comprehensive analysis. Automatically enables fast export mode for large datasets (>5000 allocations).
§Arguments
path
- Output base path for multiple optimized files
§Example
// Fast export for production monitoring
tracker.export_to_json_fast("prod_snapshot")?;
§Performance
- Uses parallel shard processing for large datasets
- Automatically switches to fast export coordinator when beneficial
- Reduces export time by 60-80% for complex programs
Sourcepub fn export_to_json_comprehensive<P: AsRef<Path>>(
&self,
path: P,
) -> TrackingResult<()>
pub fn export_to_json_comprehensive<P: AsRef<Path>>( &self, path: P, ) -> TrackingResult<()>
[CONVENIENCE] Comprehensive export with all features enabled
This method provides maximum analysis depth with all security and FFI features enabled. Ideal for debugging, security audits, and comprehensive analysis.
§Arguments
path
- Output base path for comprehensive analysis files
§Example
// Comprehensive export for security audit
tracker.export_to_json_comprehensive("security_audit")?;
Sourcepub fn show_export_upgrade_path(&self)
pub fn show_export_upgrade_path(&self)
[UTILITY] Display upgrade path information
This method shows users how to migrate from the old API to the new optimized API. Useful for understanding the available options and migration path.
Sourcepub fn get_export_capabilities(&self) -> TrackingResult<Value>
pub fn get_export_capabilities(&self) -> TrackingResult<Value>
[UTILITY] Get current export capabilities and status
Returns information about available export features and current system status.
Sourcepub fn export_to_json_with_optimized_options<P: AsRef<Path>>(
&self,
base_path: P,
options: OptimizedExportOptions,
) -> TrackingResult<()>
pub fn export_to_json_with_optimized_options<P: AsRef<Path>>( &self, base_path: P, options: OptimizedExportOptions, ) -> TrackingResult<()>
Unified export to JSON with custom options
This method provides full control over the export process with custom options. It integrates all the new data processing components including BatchProcessor, StreamingJsonWriter, SchemaValidator, and enhanced FFI analysis.
§Arguments
base_path
- Base path for output- Custom export options
§Returns
TrackingResult<()>
- Success or error result
§Example
let options = OptimizedExportOptions::with_optimization_level(OptimizationLevel::Maximum)
.parallel_processing(true)
.streaming_writer(true)
.schema_validation(true);
tracker.export_to_json_with_options("output/analysis", options)?;
Sourcepub fn test_export_backward_compatibility(&self) -> TrackingResult<Value>
pub fn test_export_backward_compatibility(&self) -> TrackingResult<Value>
Test backward compatibility with legacy export methods
This method verifies that the new optimized export system maintains full backward compatibility with existing export methods.
Sourcepub fn get_adaptive_performance_report(&self) -> TrackingResult<Value>
pub fn get_adaptive_performance_report(&self) -> TrackingResult<Value>
Get adaptive performance report
Returns detailed performance metrics and optimization recommendations from the adaptive performance optimizer.
Sourcepub fn reset_adaptive_optimizer(&self) -> TrackingResult<()>
pub fn reset_adaptive_optimizer(&self) -> TrackingResult<()>
Reset adaptive performance optimizer
Clears all cached data and performance metrics. Useful for testing or when starting fresh performance measurements.
Sourcepub fn configure_adaptive_optimization(
&self,
enabled: bool,
cache_size: Option<usize>,
initial_batch_size: Option<usize>,
) -> TrackingResult<()>
pub fn configure_adaptive_optimization( &self, enabled: bool, cache_size: Option<usize>, initial_batch_size: Option<usize>, ) -> TrackingResult<()>
Configure adaptive optimization settings
Allows runtime configuration of the adaptive performance optimizer.
Sourcepub fn get_security_violation_report(&self) -> TrackingResult<Value>
pub fn get_security_violation_report(&self) -> TrackingResult<Value>
Get comprehensive security violation report
Returns detailed security analysis including violation reports, impact assessments, and remediation suggestions.
Sourcepub fn get_security_violations_by_severity(
&self,
min_severity: ViolationSeverity,
) -> TrackingResult<Vec<Value>>
pub fn get_security_violations_by_severity( &self, min_severity: ViolationSeverity, ) -> TrackingResult<Vec<Value>>
Get security violations by severity level
Filters security violations by minimum severity level.
Sourcepub fn verify_security_report_integrity(&self) -> TrackingResult<Value>
pub fn verify_security_report_integrity(&self) -> TrackingResult<Value>
Verify integrity of security violation reports
Checks data integrity hashes for all security violation reports.
Sourcepub fn clear_security_violations(&self) -> TrackingResult<()>
pub fn clear_security_violations(&self) -> TrackingResult<()>
Clear all security violation reports
Clears all stored security violation data. Useful for testing or when starting fresh security analysis.
Sourcepub fn configure_security_analysis(
&self,
enable_correlation: bool,
include_low_severity: bool,
generate_hashes: bool,
max_related_allocations: Option<usize>,
) -> TrackingResult<()>
pub fn configure_security_analysis( &self, enable_correlation: bool, include_low_severity: bool, generate_hashes: bool, max_related_allocations: Option<usize>, ) -> TrackingResult<()>
Configure security analysis settings
Allows runtime configuration of security violation analysis.
Source§impl MemoryTracker
Ultra-fast export implementation (legacy methods for backward compatibility)
impl MemoryTracker
Ultra-fast export implementation (legacy methods for backward compatibility)
Sourcepub fn export_optimized_json_files<P: AsRef<Path>>(
&self,
base_path: P,
) -> TrackingResult<()>
pub fn export_optimized_json_files<P: AsRef<Path>>( &self, base_path: P, ) -> TrackingResult<()>
Optimized export to standard 4 JSON files (replaces export_separated_json_simple)
Sourcepub fn export_optimized_json_files_with_complex_types<P: AsRef<Path>>(
&self,
base_path: P,
) -> TrackingResult<()>
pub fn export_optimized_json_files_with_complex_types<P: AsRef<Path>>( &self, base_path: P, ) -> TrackingResult<()>
Export to 5 JSON files including complex types analysis
Sourcepub fn export_optimized_json_files_with_options<P: AsRef<Path>>(
&self,
base_path: P,
options: OptimizedExportOptions,
) -> TrackingResult<()>
pub fn export_optimized_json_files_with_options<P: AsRef<Path>>( &self, base_path: P, options: OptimizedExportOptions, ) -> TrackingResult<()>
Optimized export to standard 4 JSON files with custom options
Sourcepub fn export_extensible_json_files<P: AsRef<Path>>(
&self,
base_path: P,
file_types: &[JsonFileType],
) -> TrackingResult<()>
pub fn export_extensible_json_files<P: AsRef<Path>>( &self, base_path: P, file_types: &[JsonFileType], ) -> TrackingResult<()>
A generic export method reserved for future expansion. can easily add a 5th and 6th JSON file
Sourcepub fn export_extensible_json_files_with_options<P: AsRef<Path>>(
&self,
base_path: P,
file_types: &[JsonFileType],
options: OptimizedExportOptions,
) -> TrackingResult<()>
pub fn export_extensible_json_files_with_options<P: AsRef<Path>>( &self, base_path: P, file_types: &[JsonFileType], options: OptimizedExportOptions, ) -> TrackingResult<()>
A generic export method reserved for future expansion. can easily add a 5th and 6th JSON file
Source§impl MemoryTracker
impl MemoryTracker
Sourcepub fn export_to_json_optimized<P: AsRef<Path>>(
&self,
path: P,
) -> TrackingResult<ComplexTypeExportResult>
pub fn export_to_json_optimized<P: AsRef<Path>>( &self, path: P, ) -> TrackingResult<ComplexTypeExportResult>
Export tracking data with complex type optimization (separate files for better performance)
Trait Implementations§
Source§impl Default for MemoryTracker
impl Default for MemoryTracker
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
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