Crate dsi_progress_logger
source ·Expand description
A tunable progress logger to log progress information about long-running activities.
It is a port of the Java class it.unimi.dsi.util.ProgressLogger
from the DSI Utilities.
Logging is based on the standard log
crate at the info
level.
To log the progress of an activity, you call start
. Then, each time you want to mark progress,
you call update
, which increases the item counter, and will log progress information
if enough time has passed since the last log. The time check happens only on multiples of
LIGHT_UPDATE_MASK
+ 1 in the case of light_update
,
which should be used when the activity has an extremely low cost that is comparable to that
of the time check (a call to Instant::now()
) itself.
Some fields can be set at any time to customize the logger: please see the documentation of the fields.
It is also possible to log used and free memory at each log interval by calling
display_memory
. Memory is read from system data by the sysinfo
crate, and
will be updated at each log interval (note that this will slightly slow down the logging process). Moreover,
since it is impossible to update the memory information from the Display::fmt
implementation,
you should call refresh
before displaying the logger
on your own.
At any time, displaying the progress logger will give you time information up to the present.
When the activity is over, you call stop
, which fixes the final time, and
possibly display again the logger. done
will stop the logger, print Completed.
,
and display the final stats. There are also a few other utility methods that make it possible to
customize the logging process.
After you finished a run of the progress logger, can call start
again to measure another activity.
A typical call sequence to a progress logger is as follows:
use dsi_progress_logger::ProgressLogger;
stderrlog::new().init().unwrap();
let mut pl = ProgressLogger::default();
pl.item_name = "pumpkin";
pl.start("Smashing pumpkins...");
for _ in 0..100 {
// do something on each pumlkin
pl.update();
}
pl.done();
A progress logger can also be used as a handy timer:
use dsi_progress_logger::ProgressLogger;
stderrlog::new().init().unwrap();
let mut pl = ProgressLogger::default();
pl.item_name = "pumpkin";
pl.start("Smashing pumpkins...");
for _ in 0..100 {
// do something on each pumlkin
}
pl.done_with_count(100);
This progress logger will display information about memory usage:
use dsi_progress_logger::ProgressLogger;
stderrlog::new().init().unwrap();
let mut pl = ProgressLogger::default().display_memory();