pub struct StatisticsTracker { /* private fields */ }Expand description
Subscribes to the event bus and maintains running statistics about all download and metadata fetch operations.
The tracker runs a background task that processes events from the EventBus and
updates its internal counters. Use snapshot to
retrieve a point-in-time view of the collected data.
§Examples
let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg"));
let downloader = Downloader::builder(libraries, "output").build().await?;
// ... perform downloads ...
let snapshot = downloader.statistics().snapshot().await;
println!("Completed: {}", snapshot.downloads.completed);
println!("Total bytes: {}", snapshot.downloads.total_bytes);Implementations§
Source§impl StatisticsTracker
impl StatisticsTracker
Sourcepub fn new(bus: &EventBus) -> Self
pub fn new(bus: &EventBus) -> Self
Creates a tracker with default configuration and subscribes to bus.
§Arguments
bus- The event bus to subscribe to.
§Returns
A new StatisticsTracker that is already running its background event loop.
Sourcepub fn with_config(bus: &EventBus, config: TrackerConfig) -> Self
pub fn with_config(bus: &EventBus, config: TrackerConfig) -> Self
Creates a tracker with custom configuration and subscribes to bus.
§Arguments
bus- The event bus to subscribe to.config- History-size bounds and other settings.
§Returns
A new StatisticsTracker that is already running its background event loop.
Sourcepub async fn snapshot(&self) -> GlobalSnapshot
pub async fn snapshot(&self) -> GlobalSnapshot
Returns a point-in-time snapshot of all collected statistics.
Acquires a read lock on the internal state, computes derived metrics (averages,
rates), and returns a fully-owned GlobalSnapshot. Subsequent mutations to the
tracker are not reflected in an already-obtained snapshot.
§Returns
A GlobalSnapshot containing aggregate statistics for downloads, fetches,
post-processing, and playlists at the time of the call.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Returns the number of downloads currently in progress.
§Returns
The count of downloads that have been started but have not yet reached a terminal state (completed, failed, or canceled).
Sourcepub async fn completed_count(&self) -> u64
pub async fn completed_count(&self) -> u64
Returns the total number of successfully completed downloads.
§Returns
Cumulative count of downloads that ended with a DownloadCompleted event.
Sourcepub async fn total_bytes(&self) -> u64
pub async fn total_bytes(&self) -> u64
Returns the total number of bytes transferred across all completed downloads.
§Returns
Sum of total_bytes from every DownloadCompleted event received.
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Resets all counters and history to their initial state, preserving the configuration.
This is useful for implementing rolling windows or clearing statistics between logical phases of an application. The tracker continues running and will start collecting fresh data immediately after the reset.
Trait Implementations§
Source§impl Debug for StatisticsTracker
impl Debug for StatisticsTracker
Auto Trait Implementations§
impl Freeze for StatisticsTracker
impl !RefUnwindSafe for StatisticsTracker
impl Send for StatisticsTracker
impl Sync for StatisticsTracker
impl Unpin for StatisticsTracker
impl UnsafeUnpin for StatisticsTracker
impl !UnwindSafe for StatisticsTracker
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
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>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn 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>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which 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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.