refactor(client): use SignedDuration for effective RTT to support negative values
Simplify RttSample by merging signed and unsigned fields into a single SignedDuration for adjusted and effective RTT. This ensures accurate reporting and statistics when server processing time exceeds raw RTT.
This commit is contained in:
1 parent
37de7c96a1
commit
bec56d4114
14 files changed
+207
-86
No files matched your search
@@ -106,11 +106,15 @@ pub enum WarningKind {
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct RttSample {
|
||||
/// Client-observed RTT from send to receive.
|
||||
pub raw: Duration,
|
||||
pub adjusted: Option<Duration>,
|
||||
pub effective: Duration,
|
||||
pub adjusted_signed: Option<SignedDuration>,
|
||||
pub effective_signed: SignedDuration,
|
||||
/// Signed RTT adjusted for server processing when server processing is available.
|
||||
pub adjusted: Option<SignedDuration>,
|
||||
/// Signed effective RTT used by stats and CLI reporting.
|
||||
///
|
||||
/// This is `adjusted` when server processing is available, otherwise `raw`
|
||||
/// converted to a signed duration.
|
||||
pub effective: SignedDuration,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -118,6 +122,20 @@ pub struct SignedDuration {
|
||||
pub ns: i128,
|
||||
}
|
||||
|
||||
impl SignedDuration {
|
||||
pub fn from_duration(duration: Duration) -> Self {
|
||||
Self {
|
||||
ns: i128::try_from(duration.as_nanos()).unwrap_or(i128::MAX),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Duration> for SignedDuration {
|
||||
fn from(value: Duration) -> Self {
|
||||
Self::from_duration(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ServerTiming {
|
||||
pub receive_wall_ns: Option<i64>,
|
||||
|
||||
Reference in new issue
Block a user