Skip to main content

Analyzer

Trait Analyzer 

Source
pub trait Analyzer: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn config(&self) -> &AnalyzerConfig;
    fn state(&self) -> AnalyzerState;
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn process_event<'life0, 'async_trait>(
        &'life0 mut self,
        event: AnalyzerEvent,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn generate_report<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<AnalysisReport>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_stats(&self) -> AnalyzerStats;
    fn reset<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Core trait that all analyzers must implement

This trait defines the interface for real-time analysis of LLM optimization metrics. Analyzers receive events, maintain state, perform analysis, and generate reports with insights and recommendations.

Required Methods§

Source

fn name(&self) -> &str

Get the analyzer’s unique name

Source

fn config(&self) -> &AnalyzerConfig

Get the analyzer’s configuration

Source

fn state(&self) -> AnalyzerState

Get the current state of the analyzer

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the analyzer

This initializes internal state and prepares the analyzer to receive events.

§Errors

Returns an error if the analyzer is already running or if initialization fails.

Source

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the analyzer gracefully

This drains any remaining events and performs cleanup.

§Errors

Returns an error if the analyzer is already stopped or if cleanup fails.

Source

fn process_event<'life0, 'async_trait>( &'life0 mut self, event: AnalyzerEvent, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Process a single event

This is the core analysis method that processes incoming events. The analyzer updates its internal state and may generate insights immediately or batch them for the next report.

§Arguments
  • event - The event to process
§Returns

Returns Ok(()) if the event was processed successfully.

§Errors

Returns an error if:

  • The analyzer is not in the Running state
  • The event is invalid
  • Internal processing fails
Source

fn generate_report<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<AnalysisReport>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate a report of current analysis results

This method returns the current state of analysis, including any insights, recommendations, and alerts generated since the last report.

§Returns

Returns a report containing:

  • Summary statistics
  • Insights discovered
  • Recommendations generated
  • Alerts triggered
§Errors

Returns an error if report generation fails.

Source

fn get_stats(&self) -> AnalyzerStats

Get current statistics about the analyzer’s operation

This includes metrics like:

  • Events processed
  • Analysis duration
  • Memory usage
  • Error counts
Source

fn reset<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reset the analyzer’s state

This clears all accumulated state and resets counters. The analyzer remains in its current lifecycle state.

§Errors

Returns an error if reset fails.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check for the analyzer

Returns Ok(()) if the analyzer is healthy and able to process events.

§Errors

Returns an error if:

  • Memory usage exceeds limits
  • Error rate is too high
  • Internal state is corrupted

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§