//! System resource monitoring during load tests

use std::time::Duration;
use sysinfo::{RefreshKind, System};

use super::LoadTestMetrics;

pub async fn monitor_memory(duration_secs: u64, metrics: &LoadTestMetrics) {
    let mut sys = System::new_with_specifics(RefreshKind::everything());

    let pid = sysinfo::get_current_pid().unwrap();

    for _ in 0..duration_secs {
        tokio::time::sleep(Duration::from_secs(1)).await;
        sys.refresh_all();

        if let Some(process) = sys.process(pid) {
            metrics.record_memory(process.memory());
        }
    }
}
