MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / add_maintenance_cpu_secs

Method add_maintenance_cpu_secs

nodedb/src/control/metrics/database.rs:138–150  ·  view source on GitHub ↗

Add `secs` fractional CPU-seconds to the maintenance counter for `db_name`. Converts to integer microseconds (rounded) to avoid `AtomicF64` complexity. Negative or non-finite inputs are clamped to zero so accidental underflow in upstream timing arithmetic cannot subtract from the cumulative counter.

(&self, db_name: &str, secs: f64)

Source from the content-addressed store, hash-verified

136 /// Negative or non-finite inputs are clamped to zero so accidental underflow
137 /// in upstream timing arithmetic cannot subtract from the cumulative counter.
138 pub fn add_maintenance_cpu_secs(&self, db_name: &str, secs: f64) {
139 let us = if secs.is_finite() && secs > 0.0 {
140 (secs * 1_000_000.0).round() as u64
141 } else {
142 0
143 };
144 if us == 0 {
145 return;
146 }
147 self.get_or_create(db_name)
148 .maintenance_cpu_seconds_total
149 .fetch_add(us, Ordering::Relaxed);
150 }
151
152 /// Render all registered databases as Prometheus text format 0.0.4.
153 ///

Callers

nothing calls this directly

Calls 2

roundMethod · 0.80
get_or_createMethod · 0.45

Tested by

no test coverage detected