pub struct MemoryProfiler { /* private fields */ }Expand description
Main memory profiler
Implementations§
Source§impl MemoryProfiler
impl MemoryProfiler
Sourcepub fn new(config: ProfilerConfig) -> Result<Self>
pub fn new(config: ProfilerConfig) -> Result<Self>
Create a new memory profiler
Sourcepub async fn start_monitoring(&mut self) -> Result<()>
pub async fn start_monitoring(&mut self) -> Result<()>
Start memory monitoring
Sourcepub fn record_allocation(&self, info: AllocationInfo) -> Result<Uuid>
pub fn record_allocation(&self, info: AllocationInfo) -> Result<Uuid>
Register a real allocation with the profiler.
The profiler has no way to observe allocations it was not told about, so
the allocation counters in MemoryMetrics describe exactly the
allocations registered through this method.
Returns the id under which the allocation is tracked.
Sourcepub fn record_deallocation(&self, id: Uuid) -> Result<bool>
pub fn record_deallocation(&self, id: Uuid) -> Result<bool>
Register the release of a previously recorded allocation.
Returns true when the allocation was tracked, false when the id is
unknown (in which case no counter is touched).
Sourcepub fn allocation_stats(&self) -> Result<TrackedAllocationStats>
pub fn allocation_stats(&self) -> Result<TrackedAllocationStats>
Snapshot of the tracked-allocation counters.
Sourcepub async fn stop_monitoring(&self) -> Result<()>
pub async fn stop_monitoring(&self) -> Result<()>
Stop memory monitoring
Sourcepub async fn get_current_metrics(&self) -> Result<Option<MemoryMetrics>>
pub async fn get_current_metrics(&self) -> Result<Option<MemoryMetrics>>
Get current metrics snapshot
Sourcepub async fn get_alerts(&self) -> Result<Vec<MemoryAlert>>
pub async fn get_alerts(&self) -> Result<Vec<MemoryAlert>>
Get all alerts
Sourcepub async fn get_patterns(&self) -> Result<Vec<MemoryPattern>>
pub async fn get_patterns(&self) -> Result<Vec<MemoryPattern>>
Get memory patterns
Sourcepub async fn get_adaptive_thresholds(&self) -> Result<AdaptiveThresholds>
pub async fn get_adaptive_thresholds(&self) -> Result<AdaptiveThresholds>
Get adaptive thresholds
Sourcepub async fn get_monitoring_stats(&self) -> Result<MonitoringStats>
pub async fn get_monitoring_stats(&self) -> Result<MonitoringStats>
Get monitoring statistics
Sourcepub async fn configure_leak_detection(
&self,
config: LeakDetectionConfig,
) -> Result<()>
pub async fn configure_leak_detection( &self, config: LeakDetectionConfig, ) -> Result<()>
Configure leak detection parameters
Sourcepub async fn get_leak_detection_config(&self) -> Result<LeakDetectionConfig>
pub async fn get_leak_detection_config(&self) -> Result<LeakDetectionConfig>
Get current leak detection configuration
Sourcepub async fn predict_memory_usage(
&self,
horizon_secs: u64,
) -> Result<Option<MemoryPrediction>>
pub async fn predict_memory_usage( &self, horizon_secs: u64, ) -> Result<Option<MemoryPrediction>>
Predict memory usage for given horizon
Sourcepub async fn get_analytics_summary(&self) -> Result<AnalyticsSummary>
pub async fn get_analytics_summary(&self) -> Result<AnalyticsSummary>
Get comprehensive analytics summary
Source§impl MemoryProfiler
impl MemoryProfiler
Sourcepub async fn generate_report(&self) -> Result<MemoryDashboardReport>
pub async fn generate_report(&self) -> Result<MemoryDashboardReport>
Generate a comprehensive memory report
Sourcepub async fn save_report(&self, report: &MemoryDashboardReport) -> Result<()>
pub async fn save_report(&self, report: &MemoryDashboardReport) -> Result<()>
Save report to files
Sourcepub fn get_current_summary(&self) -> Option<MemorySummary>
pub fn get_current_summary(&self) -> Option<MemorySummary>
Get current memory usage summary
Source§impl MemoryProfiler
impl MemoryProfiler
Sourcepub async fn collect_memory_metrics(
tracked: TrackedAllocationStats,
) -> Result<MemoryMetrics>
pub async fn collect_memory_metrics( tracked: TrackedAllocationStats, ) -> Result<MemoryMetrics>
Collect current memory metrics from the operating system.
tracked carries the allocation counters the profiler maintains for
allocations that were explicitly registered by the caller.
Sourcepub fn get_system_memory_info() -> Result<SystemMemoryInfo>
pub fn get_system_memory_info() -> Result<SystemMemoryInfo>
Read the machine’s memory statistics.
cached_memory and buffer_memory are None: they are not exposed
portably, and reporting a guess would be worse than reporting nothing.
Sourcepub fn get_process_memory_info() -> Result<ProcessMemoryInfo>
pub fn get_process_memory_info() -> Result<ProcessMemoryInfo>
Read this process’s resident and virtual memory footprint.
Sourcepub async fn get_gpu_memory_info() -> Result<Option<GpuMemoryInfo>>
pub async fn get_gpu_memory_info() -> Result<Option<GpuMemoryInfo>>
Read GPU memory usage.
Returns Ok(None) when no GPU backend is compiled in — this crate has no
way to query a device that is not there, and a fabricated card would make
every downstream report fiction.
Sourcepub fn calculate_fragmentation_ratio(
info: &ProcessMemoryInfo,
tracked: TrackedAllocationStats,
) -> f64
pub fn calculate_fragmentation_ratio( info: &ProcessMemoryInfo, tracked: TrackedAllocationStats, ) -> f64
Share of the resident set that is not covered by tracked allocations.
With no registered allocations there is nothing to compare the resident
set against, so the ratio is 0.0 rather than an invented percentage.
Sourcepub async fn update_adaptive_thresholds(
current_metrics: &MemoryMetrics,
adaptive_thresholds: &Arc<Mutex<AdaptiveThresholds>>,
)
pub async fn update_adaptive_thresholds( current_metrics: &MemoryMetrics, adaptive_thresholds: &Arc<Mutex<AdaptiveThresholds>>, )
Update adaptive thresholds based on current metrics
Sourcepub async fn detect_memory_leaks(
current_metrics: &MemoryMetrics,
previous_metrics: &Option<MemoryMetrics>,
leak_detection: &Arc<Mutex<LeakDetectionHeuristics>>,
alerts: &Arc<Mutex<Vec<MemoryAlert>>>,
cached_recommendations: &AlertRecommendations,
)
pub async fn detect_memory_leaks( current_metrics: &MemoryMetrics, previous_metrics: &Option<MemoryMetrics>, leak_detection: &Arc<Mutex<LeakDetectionHeuristics>>, alerts: &Arc<Mutex<Vec<MemoryAlert>>>, cached_recommendations: &AlertRecommendations, )
Detect memory leaks using heuristics
Sourcepub async fn update_memory_prediction(
_current_metrics: &MemoryMetrics,
memory_predictor: &Arc<Mutex<MemoryPredictor>>,
metrics_history: &Arc<Mutex<VecDeque<MemoryMetrics>>>,
)
pub async fn update_memory_prediction( _current_metrics: &MemoryMetrics, memory_predictor: &Arc<Mutex<MemoryPredictor>>, metrics_history: &Arc<Mutex<VecDeque<MemoryMetrics>>>, )
Update memory prediction
Sourcepub async fn analyze_for_alerts_adaptive(
current: &MemoryMetrics,
_previous: &Option<MemoryMetrics>,
alerts: &Arc<Mutex<Vec<MemoryAlert>>>,
_config: &ProfilerConfig,
cached_recommendations: &AlertRecommendations,
adaptive_thresholds: &Arc<Mutex<AdaptiveThresholds>>,
)
pub async fn analyze_for_alerts_adaptive( current: &MemoryMetrics, _previous: &Option<MemoryMetrics>, alerts: &Arc<Mutex<Vec<MemoryAlert>>>, _config: &ProfilerConfig, cached_recommendations: &AlertRecommendations, adaptive_thresholds: &Arc<Mutex<AdaptiveThresholds>>, )
Analyze for alerts with adaptive thresholds
Sourcepub async fn update_patterns(
current_metrics: &MemoryMetrics,
patterns: &Arc<Mutex<Vec<MemoryPattern>>>,
)
pub async fn update_patterns( current_metrics: &MemoryMetrics, patterns: &Arc<Mutex<Vec<MemoryPattern>>>, )
Update memory patterns
Auto Trait Implementations§
impl Freeze for MemoryProfiler
impl RefUnwindSafe for MemoryProfiler
impl Send for MemoryProfiler
impl Sync for MemoryProfiler
impl Unpin for MemoryProfiler
impl UnsafeUnpin for MemoryProfiler
impl UnwindSafe for MemoryProfiler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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