babylon.metrics
Metrics collection and analysis for Babylon/Babylon.
Metrics are the nervous system of the simulation. They provide feedback on the health of all subsystems.
- class babylon.metrics.MetricsCollector[source]
Bases:
objectCentralized metrics collection and aggregation.
This class creates independent instances for dependency injection. Each ServiceContainer should have its own MetricsCollector instance.
Note: MetricsCollector is NOT thread-safe for concurrent access. Each ServiceContainer instance MUST have its own MetricsCollector. Concurrent access from multiple threads to the same collector is not supported (simulation runs single-threaded).
Metrics Categories: - performance: Timing, throughput, latency - simulation: Game state metrics (P(S|A), P(S|R), Rent flow) - cache: Hit rates, evictions, memory usage - embedding: Generation times, batch sizes, errors
- clear()[source]
Clear all collected metrics.
Used primarily for testing or resetting between game sessions.
- Return type:
- record_metric(name, value, context='', object_id=None, context_level=None)[source]
Record a named metric with context.
- class babylon.metrics.MetricsCollectorProtocol(*args, **kwargs)[source]
Bases:
ProtocolProtocol defining the contract for metrics collectors.
This protocol ensures both the real MetricsCollector and any test doubles (spies, mocks) implement the same interface.
The protocol follows the “Dumb Spy” pattern for test doubles: implementations should record what was called, not calculate statistics. Statistical analysis belongs in the production MetricsCollector only.
Example
def process_data(collector: MetricsCollectorProtocol) -> None: collector.increment("items_processed") with collector.time("processing_duration"): # ... do work ... pass
- __init__(*args, **kwargs)
- clear()[source]
Clear all recorded metrics.
Used primarily for testing or resetting between game sessions.
- Return type:
- gauge(name, value)[source]
Set a gauge value.
Gauges represent point-in-time values that can go up or down.
- record_metric(name, value, context='', object_id=None, context_level=None)[source]
Record a named metric with context.
Modules
Metrics collection system for Babylon/Babylon. |
|
Metrics collector interfaces and protocols. |