aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/stats.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/stats.rs')
-rw-r--r--src/swarm/stats.rs16
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