pub struct ResourceMonitor<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Resource monitor for tracking and managing system resources
Implementations§
Source§impl<T> ResourceMonitor<T>
impl<T> ResourceMonitor<T>
Sourcepub fn new(constraints: ResourceConstraints<T>) -> Self
pub fn new(constraints: ResourceConstraints<T>) -> Self
Create a new resource monitor
Sourcepub fn start_monitoring(&mut self) -> Result<()>
pub fn start_monitoring(&mut self) -> Result<()>
Start resource monitoring
Sourcepub fn stop_monitoring(&mut self) -> Result<()>
pub fn stop_monitoring(&mut self) -> Result<()>
Stop resource monitoring
Sourcepub fn update_usage(&self) -> Result<()>
pub fn update_usage(&self) -> Result<()>
Sample every tracker and record a snapshot (F12).
This is called once per generation from
NeuralArchitectureSearch::check_resource_constraints; before that wiring it
was never called at all, so current_usage stayed at
ResourceUsage::default() forever and check_resource_violations could
never fire.
The snapshot’s derived fields are all measured or absent: active_processes,
memory_pressure, cpu_load_average and gpu_utilization used to be
hard-coded to 1 / Low / 0.6 / 0.8.
The clock is read once and reused for the timestamp and the retention cutoff,
so a snapshot cannot be pruned by an Instant::now() taken microseconds later.
Sourcepub fn check_violations(&self) -> Result<Vec<ResourceViolation<T>>>
pub fn check_violations(&self) -> Result<Vec<ResourceViolation<T>>>
Check for resource violations
Sourcepub fn optimize_resources(&self) -> Result<Vec<OptimizationAction<T>>>
pub fn optimize_resources(&self) -> Result<Vec<OptimizationAction<T>>>
Optimize resource usage
Sourcepub fn get_current_usage(&self) -> ResourceUsage<T>
pub fn get_current_usage(&self) -> ResourceUsage<T>
Get current resource usage.
Recovers from a poisoned mutex instead of panicking (F22): the guarded data is a plain snapshot with no invariants that a panicking writer could have broken, so one panic elsewhere must not make this getter panic forever.
Sourcepub fn get_usage_history(&self) -> Vec<ResourceSnapshot<T>>
pub fn get_usage_history(&self) -> Vec<ResourceSnapshot<T>>
Get usage history. Poison-recovering, for the same reason as
ResourceMonitor::get_current_usage.
Sourcepub fn get_monitoring_state(&self) -> MonitoringState
pub fn get_monitoring_state(&self) -> MonitoringState
Get monitoring state
Sourcepub fn set_trackers(&mut self, monitors: Vec<Box<dyn ResourceTracker<T>>>)
pub fn set_trackers(&mut self, monitors: Vec<Box<dyn ResourceTracker<T>>>)
Replace the resource trackers. This is the injection point for real
telemetry: hand in a SystemResourceTracker::with_telemetry built over a
source that can measure what the default cannot (F12).
Sourcepub fn set_alert_handlers(&mut self, handlers: Vec<Box<dyn AlertHandler<T>>>)
pub fn set_alert_handlers(&mut self, handlers: Vec<Box<dyn AlertHandler<T>>>)
Replace the alert handlers.
Sourcepub fn set_optimization_strategies(
&mut self,
strategies: Vec<Box<dyn ResourceOptimizer<T>>>,
)
pub fn set_optimization_strategies( &mut self, strategies: Vec<Box<dyn ResourceOptimizer<T>>>, )
Replace the optimization strategies.
Sourcepub fn telemetry_source_names(&self) -> Vec<&str>
pub fn telemetry_source_names(&self) -> Vec<&str>
Names of the telemetry sources currently backing this monitor.
Sourcepub fn update_constraints(&mut self, constraints: ResourceConstraints<T>)
pub fn update_constraints(&mut self, constraints: ResourceConstraints<T>)
Update constraints
Sourcepub fn generate_report(&self) -> ResourceReport<T>
pub fn generate_report(&self) -> ResourceReport<T>
Generate resource report
Sourcepub fn check_resource_violations(&self) -> Result<Vec<ResourceViolation<T>>>
pub fn check_resource_violations(&self) -> Result<Vec<ResourceViolation<T>>>
Check for resource constraint violations
Sourcepub fn get_usage_summary(&self) -> ResourceUsageSummary<T>
pub fn get_usage_summary(&self) -> ResourceUsageSummary<T>
Get a summary of resource usage
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for ResourceMonitor<T>
impl<T> !UnwindSafe for ResourceMonitor<T>
impl<T> Freeze for ResourceMonitor<T>where
ResourceConstraints<T>: Freeze,
Arc<Mutex<ResourceUsage<T>>>: Freeze,
Arc<Mutex<Vec<ResourceSnapshot<T>>>>: Freeze,
Vec<Box<dyn ResourceTracker<T>>>: Freeze,
Vec<Box<dyn AlertHandler<T>>>: Freeze,
Vec<Box<dyn ResourceOptimizer<T>>>: Freeze,
impl<T> Send for ResourceMonitor<T>where
ResourceConstraints<T>: Send,
Arc<Mutex<ResourceUsage<T>>>: Send,
Arc<Mutex<Vec<ResourceSnapshot<T>>>>: Send,
Vec<Box<dyn ResourceTracker<T>>>: Send,
Vec<Box<dyn AlertHandler<T>>>: Send,
Vec<Box<dyn ResourceOptimizer<T>>>: Send,
impl<T> Sync for ResourceMonitor<T>where
ResourceConstraints<T>: Sync,
Arc<Mutex<ResourceUsage<T>>>: Sync,
Arc<Mutex<Vec<ResourceSnapshot<T>>>>: Sync,
Vec<Box<dyn ResourceTracker<T>>>: Sync,
Vec<Box<dyn AlertHandler<T>>>: Sync,
Vec<Box<dyn ResourceOptimizer<T>>>: Sync,
impl<T> Unpin for ResourceMonitor<T>where
ResourceConstraints<T>: Unpin,
Arc<Mutex<ResourceUsage<T>>>: Unpin,
Arc<Mutex<Vec<ResourceSnapshot<T>>>>: Unpin,
Vec<Box<dyn ResourceTracker<T>>>: Unpin,
Vec<Box<dyn AlertHandler<T>>>: Unpin,
Vec<Box<dyn ResourceOptimizer<T>>>: Unpin,
impl<T> UnsafeUnpin for ResourceMonitor<T>where
ResourceConstraints<T>: UnsafeUnpin,
Arc<Mutex<ResourceUsage<T>>>: UnsafeUnpin,
Arc<Mutex<Vec<ResourceSnapshot<T>>>>: UnsafeUnpin,
Vec<Box<dyn ResourceTracker<T>>>: UnsafeUnpin,
Vec<Box<dyn AlertHandler<T>>>: UnsafeUnpin,
Vec<Box<dyn ResourceOptimizer<T>>>: UnsafeUnpin,
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> 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