Skip to main content

ResourceGuard

Struct ResourceGuard 

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

Unified resource guard for monitoring all system resources.

Implementations§

Source§

impl ResourceGuard

Source

pub fn new(config: ResourceGuardConfig) -> Self

Create a new resource guard with the given configuration.

Source

pub fn default_guard() -> Self

Create a resource guard with default configuration.

Source

pub fn with_memory_limit(limit_mb: usize) -> Self

Create a resource guard with specified memory limit.

Source

pub fn disabled() -> Self

Create a disabled resource guard.

Source

pub fn shared(config: ResourceGuardConfig) -> Arc<Self>

Create an Arc-wrapped resource guard for sharing across threads.

Source

pub fn check(&self) -> SynthResult<DegradationLevel>

Check all resources (memory, disk, CPU). Returns Ok with current degradation level or Err if hard limits exceeded.

Source

pub fn check_now(&self) -> SynthResult<DegradationLevel>

Force an immediate check of all resources (bypasses interval).

Source

pub fn get_actions(&self) -> DegradationActions

Get actions to take based on current degradation level.

Source

pub fn is_degraded(&self) -> bool

Check if currently degraded (not Normal).

Source

pub fn degradation_level(&self) -> DegradationLevel

Get current degradation level.

Source

pub fn stats(&self) -> ResourceStats

Get combined resource statistics.

Source

pub fn pre_check(&self) -> PreCheckResult

Pre-check before a potentially expensive operation. Returns recommended action based on current resource state.

Source

pub fn check_before_write(&self, estimated_bytes: u64) -> SynthResult<()>

Pre-check before writing data.

Source

pub fn record_write(&self, bytes: u64)

Record bytes written (for tracking).

Source

pub fn memory(&self) -> &MemoryGuard

Get reference to memory guard.

Source

pub fn disk(&self) -> &DiskSpaceGuard

Get reference to disk guard.

Source

pub fn cpu(&self) -> &CpuMonitor

Get reference to CPU monitor.

Source

pub fn degradation(&self) -> &DegradationController

Get reference to degradation controller.

Source

pub fn maybe_throttle(&self)

Apply throttle delay if CPU is overloaded.

Source

pub fn reset_stats(&self)

Reset all statistics (for testing).

Source

pub fn is_available() -> bool

Check if resource monitoring is available on this platform.

Source

pub fn current_memory_mb(&self) -> usize

Get current memory usage in MB.

Source

pub fn available_disk_mb(&self) -> usize

Get current available disk space in MB.

Source

pub fn current_cpu_load(&self) -> f64

Get current CPU load.

Trait Implementations§

Source§

impl Debug for ResourceGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceGuard

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

Source§

fn vzip(self) -> V