stats_accounting

This commit is contained in:
John Smith
2022-03-19 18:19:40 -04:00
parent babe176747
commit 3888a832a0
19 changed files with 285 additions and 67 deletions
@@ -19,16 +19,14 @@ pub struct TransferCount {
}
#[derive(Debug, Clone, Default)]
pub struct StatsAccounting {
rolling_latencies: VecDeque<u64>,
pub struct TransferStatsAccounting {
rolling_transfers: VecDeque<TransferCount>,
current_transfer: TransferCount,
}
impl StatsAccounting {
impl TransferStatsAccounting {
pub fn new() -> Self {
Self {
rolling_latencies: VecDeque::new(),
rolling_transfers: VecDeque::new(),
current_transfer: TransferCount::default(),
}
@@ -79,6 +77,19 @@ impl StatsAccounting {
transfer_stats.down.average /= len;
transfer_stats.up.average /= len;
}
}
#[derive(Debug, Clone, Default)]
pub struct LatencyStatsAccounting {
rolling_latencies: VecDeque<u64>,
}
impl LatencyStatsAccounting {
pub fn new() -> Self {
Self {
rolling_latencies: VecDeque::new(),
}
}
pub fn record_latency(&mut self, latency: u64) -> veilid_api::LatencyStats {
while self.rolling_latencies.len() >= ROLLING_LATENCIES_SIZE {