From 1a544c37de59a5a7d8decfa8db98e053e52efffa Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Fri, 8 Jan 2021 23:33:42 +0000 Subject: [PATCH] Add recovery stats as part of ConnectionStats This is an alternative version of #972, where we add the new stats to ConnectionStats instead of exposing additional accessors. The naming of `recovery` could probably be improved. `path` might be an option. But where would we add something like packet loss? That seems more like an overall stat. --- quinn-proto/src/connection/mod.rs | 6 +++++- quinn-proto/src/connection/stats.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 8a142dc1b..4fae013ce 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -935,7 +935,11 @@ where /// Returns connection statistics pub fn stats(&self) -> ConnectionStats { - self.stats + let mut stats = self.stats; + stats.path.rtt = self.path.rtt.get(); + stats.path.cwnd = self.path.congestion.window(); + + stats } /// Stop accepting data on the given receive stream diff --git a/quinn-proto/src/connection/stats.rs b/quinn-proto/src/connection/stats.rs index a30e6af1d..0cf63626a 100644 --- a/quinn-proto/src/connection/stats.rs +++ b/quinn-proto/src/connection/stats.rs @@ -1,4 +1,7 @@ +//! Connection statistics + use crate::{frame::Frame, Dir}; +use std::time::Duration; /// Statistics about UDP datagrams transmitted or received on a connection #[derive(Default, Debug, Copy, Clone)] @@ -108,6 +111,16 @@ impl std::fmt::Debug for FrameStats { } } +/// Statistics related to a transmission path +#[derive(Debug, Default, Copy, Clone)] +#[non_exhaustive] +pub struct PathStats { + /// Current best estimate of this connection's latency (round-trip-time) + pub rtt: Duration, + /// Current congestion window of the connection + pub cwnd: u64, +} + /// Connection statistics #[derive(Debug, Default, Copy, Clone)] #[non_exhaustive] @@ -120,4 +133,6 @@ pub struct ConnectionStats { pub frame_tx: FrameStats, /// Statistics about frames received on a connection pub frame_rx: FrameStats, + /// Statistics related to the current transmission path + pub path: PathStats, }