#[cfg(feature = "compute-validation")]
use std::sync::atomic::{AtomicU64, Ordering};
#[cfg(feature = "compute-validation")]
use std::time::Duration;
#[cfg(feature = "compute-validation")]
use tracing::warn;
#[cfg(feature = "compute-validation")]
pub const SMALL_THRESHOLD_US: u64 = 100;
#[cfg(feature = "compute-validation")]
pub const MEDIUM_THRESHOLD_US: u64 = 1000;
#[cfg(feature = "compute-validation")]
static SMALL_MISCLASSIFIED: AtomicU64 = AtomicU64::new(0);
#[cfg(feature = "compute-validation")]
static MEDIUM_MISCLASSIFIED: AtomicU64 = AtomicU64::new(0);
#[cfg(feature = "compute-validation")]
static LARGE_MISCLASSIFIED: AtomicU64 = AtomicU64::new(0);
#[cfg(feature = "compute-validation")]
pub fn validate_small(elapsed: Duration) {
let micros = elapsed.as_micros() as u64;
if micros > SMALL_THRESHOLD_US {
SMALL_MISCLASSIFIED.fetch_add(1, Ordering::Relaxed);
warn!(
task_duration_us = micros,
threshold_us = SMALL_THRESHOLD_US,
"compute_small! task exceeded threshold. Consider using compute_medium!"
);
}
}
#[cfg(feature = "compute-validation")]
pub fn validate_medium(elapsed: Duration) {
let micros = elapsed.as_micros() as u64;
if micros < SMALL_THRESHOLD_US {
MEDIUM_MISCLASSIFIED.fetch_add(1, Ordering::Relaxed);
warn!(
task_duration_us = micros,
threshold_us = SMALL_THRESHOLD_US,
"compute_medium! task below small threshold. Consider using compute_small!"
);
} else if micros > MEDIUM_THRESHOLD_US {
MEDIUM_MISCLASSIFIED.fetch_add(1, Ordering::Relaxed);
warn!(
task_duration_us = micros,
threshold_us = MEDIUM_THRESHOLD_US,
"compute_medium! task exceeded threshold. Consider using compute_large!"
);
}
}
#[cfg(feature = "compute-validation")]
pub fn validate_large(elapsed: Duration) {
let micros = elapsed.as_micros() as u64;
if micros < MEDIUM_THRESHOLD_US {
LARGE_MISCLASSIFIED.fetch_add(1, Ordering::Relaxed);
warn!(
task_duration_us = micros,
threshold_us = MEDIUM_THRESHOLD_US,
"compute_large! task below medium threshold. Consider using compute_medium! or compute_small!"
);
}
}
#[cfg(feature = "compute-validation")]
pub fn get_misclassification_metrics() -> (u64, u64, u64) {
(
SMALL_MISCLASSIFIED.load(Ordering::Relaxed),
MEDIUM_MISCLASSIFIED.load(Ordering::Relaxed),
LARGE_MISCLASSIFIED.load(Ordering::Relaxed),
)
}
#[cfg(feature = "compute-validation")]
pub fn reset_misclassification_metrics() {
SMALL_MISCLASSIFIED.store(0, Ordering::Relaxed);
MEDIUM_MISCLASSIFIED.store(0, Ordering::Relaxed);
LARGE_MISCLASSIFIED.store(0, Ordering::Relaxed);
}