Watch
0
0
Fork
You've already forked hyperhive
0

hive-c0re/swarm-*: drop clippy allows and dedupe unix_now + KV open_or_create

No behaviour change. Casts replaced by try_from / Duration math; schedules.rs
reuses agent_renewal::unix_now; the five swarm-queue-client KV open-or-create
copies share one private kv::open_or_create.
This commit is contained in:
atlas 2026-10-09 09:48:03 +02:00 • committed by mara
commit b874d21cda

View file

@ -222,16 +222,8 @@ pub async fn gather() -> Vec<ContainerResource> {
let t0: Vec<Option<u64>> = candidates.iter().map(|(_, d)| read_usage_usec(d)).collect();
sleep(CPU_SAMPLE).await;
#[allow(
clippy::cast_precision_loss,
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
)]
let nproc = host_nproc() as f64;
#[allow(
clippy::cast_precision_loss,
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
)]
let interval_usec = CPU_SAMPLE.as_micros() as f64;
let nproc = f64::from(u32::try_from(host_nproc()).unwrap_or(u32::MAX));
let interval_secs = CPU_SAMPLE.as_secs_f64();
// Snapshot the slow disk cache once (cheap clone of a small map) so
// the per-agent loop below is a plain map lookup — no `du` on this
@ -246,12 +238,8 @@ pub async fn gather() -> Vec<ContainerResource> {
let usage_now = read_usage_usec(dir);
let cpu_pct = match (t0[i], usage_now) {
(Some(a), Some(b)) => {
#[allow(
clippy::cast_precision_loss,
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
)]
let delta = b.saturating_sub(a) as f64;
(delta / (interval_usec * nproc)) * 100.0
let delta_secs = Duration::from_micros(b.saturating_sub(a)).as_secs_f64();
(delta_secs / (interval_secs * nproc)) * 100.0
}
_ => 0.0,
};