Struct ProgressLogger

Source
pub struct ProgressLogger { /* private fields */ }
Expand description

A tool to report the progress of computations. It can be built and configured using the builder function. If given the expected number of updates, reports the expected time to completion, based on the current throughtput.

Progress is reported every 10 seconds by default. See the examples about how to change it.

There are three methods to update the internal counter:

  • update, for events that don’t happen frequently
  • update_light, which tries to report (by checking the configured frequency of updates) only once every million updates. To be used in situations where updates are frequent: it’s an order of magnitude faster than update.

Reports are issued on the console using the info!() macro from the log crate. Therefore, the reports depend on your logging configuration.

Inspired by ProgressLogger in the dsiutil Java library.

§Examples

§Basic usage

use progress_logger::ProgressLogger;

let mut pl = ProgressLogger::builder().start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

§Reporting every 5 seconds

use progress_logger::ProgressLogger;
use std::time::Duration;

let mut pl = ProgressLogger::builder()
    .with_frequency(Duration::from_secs(5))
    .start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

§Changing the names of updates

use progress_logger::ProgressLogger;

let mut pl = ProgressLogger::builder()
    .with_items_name("points")
    .start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

Implementations§

Source§

impl ProgressLogger

Source

pub fn builder() -> ProgressLoggerBuilder

Creates a builder to configure a new progress logger

Source

pub fn time_to_completion(&self) -> Option<Duration>

Get the estimated time to completion, if such prediction is available

Source

pub fn throughput(&self) -> Option<f64>

Source

pub fn update_light<N: Into<u64>>(&mut self, cnt: N)

Try to report progress only once every million updates

Source

pub fn update<N: Into<u64>>(&mut self, cnt: N)

Update the internal counter and report progress if the time since the last report is greater than the configured duration

Source

pub fn stop(self)

Stops and drops the progress logger, logging the completion statement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.