Skip to main content

agent_hub_runtime/core/
timing.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2
3/// Decide whether a per-command timing line should be logged.
4///
5/// Strategy: always log the very first call after process start (to
6/// capture a cold baseline), then for subsequent calls only log when the
7/// elapsed time crosses `slow_threshold_ms`. This keeps diagnostic
8/// visibility for slow paths while preventing the log file from being
9/// flooded with one INFO line per refresh during normal interactive use.
10pub fn should_log_first_or_slow(
11    first_call: &AtomicBool,
12    elapsed_ms: u128,
13    slow_threshold_ms: u128,
14) -> bool {
15    if first_call.swap(false, Ordering::Relaxed) {
16        return true;
17    }
18    elapsed_ms >= slow_threshold_ms
19}
20
21#[cfg(test)]
22mod tests;