pub struct ToolStats {
pub call_count: AtomicU64,
pub success_count: AtomicU64,
pub p50_latency_ns: AtomicU64,
pub peak_latency_ns: AtomicU64,
pub cpu_time_ns: AtomicU64,
pub lmdb_pages_touched: AtomicU64,
pub last_used_unix: AtomicU64,
pub effectiveness: AtomicU32,
}Expand description
Atomic statistics tracked per-tool.
All fields are atomic, enabling lock-free updates from any thread. Update overhead is ~10ns per field (relaxed atomic store).
Fields§
§call_count: AtomicU64Total number of calls
success_count: AtomicU64Number of successful calls
p50_latency_ns: AtomicU64Central latency estimate in nanoseconds (exponential moving average of recent call latencies — not an exact median).
peak_latency_ns: AtomicU64Highest latency seen in nanoseconds. The high-latency anomaly path compares new calls against this peak.
cpu_time_ns: AtomicU64Total CPU time consumed in nanoseconds
lmdb_pages_touched: AtomicU64Total LMDB pages touched
last_used_unix: AtomicU64Unix timestamp of last use
effectiveness: AtomicU32Karma-weighted effectiveness score (0.0 = useless, 1.0 = perfect)
Implementations§
Source§impl ToolStats
impl ToolStats
Sourcepub fn record_success(&self, latency: Duration, cpu_time: Duration)
pub fn record_success(&self, latency: Duration, cpu_time: Duration)
Record a successful call.
Sourcepub fn record_failure(&self, latency: Duration)
pub fn record_failure(&self, latency: Duration)
Record a failed call.
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Get the success rate (0.0 to 1.0).
Sourcepub fn effectiveness_f32(&self) -> f32
pub fn effectiveness_f32(&self) -> f32
Get the effectiveness score as a float (0.0 to 1.0).
Sourcepub fn set_effectiveness(&self, score: f32)
pub fn set_effectiveness(&self, score: f32)
Set the effectiveness score.
Sourcepub fn should_retire(&self, min_calls: u64, threshold: f32) -> bool
pub fn should_retire(&self, min_calls: u64, threshold: f32) -> bool
Whether this tool should be retired (low effectiveness after enough calls).
Sourcepub fn restore(&self, snap: &ToolStatsSnapshot)
pub fn restore(&self, snap: &ToolStatsSnapshot)
Restore stats from a persisted snapshot.
Used on startup to rehydrate cross-restart usage data so tools
like tools.usage_report can rank on cumulative history instead
of only the current process lifetime. Counters are overwritten,
not merged — call this before any dispatches are recorded.
Sourcepub fn snapshot(&self) -> ToolStatsSnapshot
pub fn snapshot(&self) -> ToolStatsSnapshot
Get a snapshot of all stats as a serializable struct.