Skip to main content

MemoryProfiler

Struct MemoryProfiler 

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

Main memory profiler

Implementations§

Source§

impl MemoryProfiler

Source

pub fn new(config: ProfilerConfig) -> Result<Self>

Create a new memory profiler

Source

pub async fn start_monitoring(&mut self) -> Result<()>

Start memory monitoring

Source

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.

Source

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).

Source

pub fn allocation_stats(&self) -> Result<TrackedAllocationStats>

Snapshot of the tracked-allocation counters.

Source

pub async fn stop_monitoring(&self) -> Result<()>

Stop memory monitoring

Source

pub async fn get_current_metrics(&self) -> Result<Option<MemoryMetrics>>

Get current metrics snapshot

Source

pub async fn get_alerts(&self) -> Result<Vec<MemoryAlert>>

Get all alerts

Source

pub async fn get_patterns(&self) -> Result<Vec<MemoryPattern>>

Get memory patterns

Source

pub async fn get_adaptive_thresholds(&self) -> Result<AdaptiveThresholds>

Get adaptive thresholds

Source

pub async fn get_monitoring_stats(&self) -> Result<MonitoringStats>

Get monitoring statistics

Source

pub async fn configure_leak_detection( &self, config: LeakDetectionConfig, ) -> Result<()>

Configure leak detection parameters

Source

pub async fn get_leak_detection_config(&self) -> Result<LeakDetectionConfig>

Get current leak detection configuration

Source

pub async fn predict_memory_usage( &self, horizon_secs: u64, ) -> Result<Option<MemoryPrediction>>

Predict memory usage for given horizon

Source

pub async fn get_analytics_summary(&self) -> Result<AnalyticsSummary>

Get comprehensive analytics summary

Source§

impl MemoryProfiler

Source

pub async fn generate_report(&self) -> Result<MemoryDashboardReport>

Generate a comprehensive memory report

Source

pub async fn save_report(&self, report: &MemoryDashboardReport) -> Result<()>

Save report to files

Source

pub fn get_current_summary(&self) -> Option<MemorySummary>

Get current memory usage summary

Source§

impl MemoryProfiler

Source

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.

Source

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.

Source

pub fn get_process_memory_info() -> Result<ProcessMemoryInfo>

Read this process’s resident and virtual memory footprint.

Source

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.

Source

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.

Source

pub async fn update_adaptive_thresholds( current_metrics: &MemoryMetrics, adaptive_thresholds: &Arc<Mutex<AdaptiveThresholds>>, )

Update adaptive thresholds based on current metrics

Source

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

Source

pub async fn update_memory_prediction( _current_metrics: &MemoryMetrics, memory_predictor: &Arc<Mutex<MemoryPredictor>>, metrics_history: &Arc<Mutex<VecDeque<MemoryMetrics>>>, )

Update memory prediction

Source

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

Source

pub async fn update_patterns( current_metrics: &MemoryMetrics, patterns: &Arc<Mutex<Vec<MemoryPattern>>>, )

Update memory patterns

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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