Return the current runtime counters observed by AHP.
(&self)
| 300 | |
| 301 | /// Return the current runtime counters observed by AHP. |
| 302 | pub fn runtime_snapshot(&self) -> AhpRuntimeSnapshot { |
| 303 | let active_tools = self.runtime_state.active_tools(); |
| 304 | let pending_actions = self.runtime_state.pending_actions(); |
| 305 | let queue_depth = self.runtime_state.queue_depth(); |
| 306 | let tokens_used = self.runtime_state.tokens_used(); |
| 307 | let total_events_processed = self.total_events.load(Ordering::Relaxed); |
| 308 | let error_count = self.error_count.load(Ordering::Relaxed) as usize; |
| 309 | let uptime_ms = self.start_time.elapsed().as_millis() as u64; |
| 310 | let current_state = if pending_actions > 0 { |
| 311 | "waiting" |
| 312 | } else if active_tools > 0 { |
| 313 | "running_tools" |
| 314 | } else if self.get_idle_duration_ms() >= self.idle_threshold_ms { |
| 315 | "idle" |
| 316 | } else { |
| 317 | "active" |
| 318 | } |
| 319 | .to_string(); |
| 320 | |
| 321 | AhpRuntimeSnapshot { |
| 322 | active_tools, |
| 323 | pending_actions, |
| 324 | queue_depth, |
| 325 | tokens_used, |
| 326 | total_events_processed, |
| 327 | error_count, |
| 328 | uptime_ms, |
| 329 | current_state, |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /// Get idle duration in milliseconds. |
| 334 | pub fn get_idle_duration_ms(&self) -> u64 { |