pub struct BandwidthTracker {
pub window_ms: u64,
/* private fields */
}Expand description
Rolling-window bandwidth meter.
Call record_send / record_recv with byte counts and the current
millisecond timestamp. Query bytes_per_sec_up / bytes_per_sec_down
to get the rolling rate.
Fields§
§window_ms: u64Length of the rolling window in milliseconds.
Implementations§
Source§impl BandwidthTracker
impl BandwidthTracker
pub fn new(window_ms: u64) -> Self
Sourcepub fn default_window() -> Self
pub fn default_window() -> Self
Default 1-second rolling window.
Sourcepub fn record_send(&mut self, bytes: usize, now_ms: u64)
pub fn record_send(&mut self, bytes: usize, now_ms: u64)
Record bytes sent at time now_ms.
Sourcepub fn record_recv(&mut self, bytes: usize, now_ms: u64)
pub fn record_recv(&mut self, bytes: usize, now_ms: u64)
Record bytes received at time now_ms.
Sourcepub fn bytes_per_sec_up(&self, now_ms: u64) -> f64
pub fn bytes_per_sec_up(&self, now_ms: u64) -> f64
Bytes per second upload over the rolling window.
Sourcepub fn bytes_per_sec_down(&self, now_ms: u64) -> f64
pub fn bytes_per_sec_down(&self, now_ms: u64) -> f64
Bytes per second download over the rolling window.
pub fn total_bytes_sent(&self) -> u64
pub fn total_bytes_recv(&self) -> u64
Auto Trait Implementations§
impl Freeze for BandwidthTracker
impl RefUnwindSafe for BandwidthTracker
impl Send for BandwidthTracker
impl Sync for BandwidthTracker
impl Unpin for BandwidthTracker
impl UnsafeUnpin for BandwidthTracker
impl UnwindSafe for BandwidthTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.