diff options
| author | tv <tv@krebsco.de> | 2026-11-04 22:15:18 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-04 22:15:18 +0100 |
| commit | a1585a3db53ee59fe941622d698638322b585267 (patch) | |
| tree | 097f53b4cb6efe4e0da54d01f960a707cc0b7922 /src/swarm/stats.rs | |
| parent | e1e6c8b8faead6c348f1b775baa50a30867c0016 (diff) | |
hop delays
Diffstat (limited to 'src/swarm/stats.rs')
| -rw-r--r-- | src/swarm/stats.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index 74076a4..de63962 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -59,7 +59,7 @@ pub(crate) struct Propagation { } impl Propagation { - fn record(&mut self, delay_ms: i64) { + pub(crate) fn record(&mut self, delay_ms: i64) { if delay_ms < 0 { self.ahead += 1; } @@ -73,6 +73,20 @@ impl Propagation { self.sum_ms += delay_ms; } + /// The bound of the bucket by which `quantile` of the delays came: None if beyond + /// the last bound, or none came. + pub(crate) fn within(&self, quantile: f64) -> Option<u64> { + let wanted = (self.count as f64 * quantile).ceil() as u64; + let mut seen = 0; + for (bound, count) in self.buckets() { + seen += count; + if seen >= wanted && seen > 0 { + return bound; + } + } + None + } + /// Each bucket's upper bound (None for the last) and count. pub(crate) fn buckets(&self) -> impl Iterator<Item = (Option<u64>, u64)> + '_ { PROPAGATION_BUCKETS_MS |
