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 frequentlyupdate_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 thanupdate
.
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
impl ProgressLogger
Sourcepub fn builder() -> ProgressLoggerBuilder
pub fn builder() -> ProgressLoggerBuilder
Creates a builder to configure a new progress logger
Sourcepub fn time_to_completion(&self) -> Option<Duration>
pub fn time_to_completion(&self) -> Option<Duration>
Get the estimated time to completion, if such prediction is available
pub fn throughput(&self) -> Option<f64>
Sourcepub fn update_light<N: Into<u64>>(&mut self, cnt: N)
pub fn update_light<N: Into<u64>>(&mut self, cnt: N)
Try to report progress only once every million updates
Auto Trait Implementations§
impl Freeze for ProgressLogger
impl RefUnwindSafe for ProgressLogger
impl Send for ProgressLogger
impl Sync for ProgressLogger
impl Unpin for ProgressLogger
impl UnwindSafe for ProgressLogger
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