]>
git.proxmox.com Git - proxmox-backup.git/blob - src/backup/store_progress.rs
1 #[derive(Debug, Default)]
2 /// Tracker for progress of operations iterating over `Datastore` contents.
3 pub struct StoreProgress
{
8 /// Completed snapshots within current group
9 pub done_snapshots
: u64,
10 /// Total snapshots in current group
11 pub group_snapshots
: u64,
15 pub fn new(total_groups
: u64) -> Self {
22 /// Calculates an interpolated relative progress based on current counters.
23 pub fn percentage(&self) -> f64 {
24 let per_groups
= (self.done_groups
as f64) / (self.total_groups
as f64);
25 if self.group_snapshots
== 0 {
28 let per_snapshots
= (self.done_snapshots
as f64) / (self.group_snapshots
as f64);
29 per_groups
+ (1.0 / self.total_groups
as f64) * per_snapshots
34 impl std
::fmt
::Display
for StoreProgress
{
35 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
36 let current_group
= if self.done_groups
< self.total_groups
{
42 if self.group_snapshots
== 0 {
45 "{:.2}% ({} of {} groups)",
46 self.percentage() * 100.0,
50 } else if self.total_groups
== 1 {
53 "{:.2}% ({} of {} snapshots)",
54 self.percentage() * 100.0,
58 } else if self.done_snapshots
== self.group_snapshots
{
61 "{:.2}% ({} of {} groups)",
62 self.percentage() * 100.0,
69 "{:.2}% ({} of {} groups, {} of {} group snapshots)",
70 self.percentage() * 100.0,