Record a tool execution
(&mut self, tool_name: &str, success: bool, duration_ms: u64)
| 232 | |
| 233 | /// Record a tool execution |
| 234 | pub fn record(&mut self, tool_name: &str, success: bool, duration_ms: u64) { |
| 235 | self.total_calls += 1; |
| 236 | self.total_duration_ms += duration_ms; |
| 237 | |
| 238 | let entry = self |
| 239 | .stats |
| 240 | .entry(tool_name.to_string()) |
| 241 | .or_insert_with(|| ToolStats { |
| 242 | tool_name: tool_name.to_string(), |
| 243 | total_calls: 0, |
| 244 | success_count: 0, |
| 245 | failure_count: 0, |
| 246 | total_duration_ms: 0, |
| 247 | min_duration_ms: u64::MAX, |
| 248 | max_duration_ms: 0, |
| 249 | avg_duration_ms: 0, |
| 250 | last_called_at: None, |
| 251 | }); |
| 252 | |
| 253 | entry.total_calls += 1; |
| 254 | if success { |
| 255 | entry.success_count += 1; |
| 256 | } else { |
| 257 | entry.failure_count += 1; |
| 258 | } |
| 259 | entry.total_duration_ms += duration_ms; |
| 260 | entry.min_duration_ms = entry.min_duration_ms.min(duration_ms); |
| 261 | entry.max_duration_ms = entry.max_duration_ms.max(duration_ms); |
| 262 | entry.avg_duration_ms = entry.total_duration_ms / entry.total_calls; |
| 263 | entry.last_called_at = Some(chrono::Utc::now()); |
| 264 | } |
| 265 | |
| 266 | /// Get all tool stats |
| 267 | pub fn stats(&self) -> Vec<ToolStats> { |
no test coverage detected