Skip to content

Commit 4738578

Browse files
committed
delete/gc stats include elapsed time
1 parent f9a1782 commit 4738578

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/archive.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Conserve backup system.
2-
// Copyright 2015, 2016, 2017, 2018, 2019, 2020 Martin Pool.
2+
// Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021 Martin Pool.
33

44
// This program is free software; you can redistribute it and/or modify
55
// it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@ use std::collections::{HashMap, HashSet};
1717
use std::io::ErrorKind;
1818
use std::path::Path;
1919
use std::sync::Mutex;
20+
use std::time::Instant;
2021

2122
use rayon::prelude::*;
2223
use serde::{Deserialize, Serialize};
@@ -245,6 +246,7 @@ impl Archive {
245246
pub fn delete_unreferenced(&self, options: &DeleteOptions) -> Result<DeleteStats> {
246247
let block_dir = self.block_dir();
247248
let mut stats = DeleteStats::default();
249+
let start = Instant::now();
248250
let delete_guard = if options.break_lock {
249251
gc_lock::GarbageCollectionLock::break_lock(self)?
250252
} else {
@@ -288,16 +290,18 @@ impl Archive {
288290
stats.deleted_block_count += blocks.len() - error_count;
289291
}
290292

293+
stats.elapsed = start.elapsed();
291294
Ok(stats)
292295
}
293296

294-
/// Delete bands, and the blocks that they referenec.
297+
/// Delete bands, and the blocks that they reference.
295298
pub fn delete_bands(
296299
&self,
297300
band_ids: &[BandId],
298301
options: &DeleteOptions,
299302
) -> Result<DeleteStats> {
300303
let mut stats = DeleteStats::default();
304+
let start = Instant::now();
301305
for band_id in band_ids {
302306
if !options.dry_run {
303307
Band::delete(self, band_id).map(|()| stats.deleted_band_count += 1)?
@@ -306,6 +310,7 @@ impl Archive {
306310
if !options.no_gc {
307311
stats += self.delete_unreferenced(options)?;
308312
}
313+
stats.elapsed = start.elapsed();
309314
Ok(stats)
310315
}
311316

src/stats.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use std::fmt;
1515
use std::io;
16+
use std::time::Duration;
1617

1718
use derive_more::{Add, AddAssign};
1819
use thousands::Separable;
1920

21+
use crate::ui::duration_to_hms;
2022
use crate::*;
2123

2224
pub fn mb_string(s: u64) -> String {
@@ -55,6 +57,10 @@ fn write_count<I: Into<usize>>(w: &mut fmt::Formatter<'_>, label: &str, value: I
5557
.unwrap();
5658
}
5759

60+
fn write_duration(w: &mut fmt::Formatter<'_>, label: &str, duration: Duration) -> fmt::Result {
61+
writeln!(w, "{:>12} {}", duration_to_hms(duration), label)
62+
}
63+
5864
/// Describes sizes of data read or written, with both the
5965
/// compressed and uncompressed size.
6066
#[derive(Add, AddAssign, Clone, Copy, Debug, Default, Eq, PartialEq)]
@@ -278,6 +284,7 @@ pub struct DeleteStats {
278284
pub unreferenced_block_bytes: u64,
279285
pub deletion_errors: usize,
280286
pub deleted_block_count: usize,
287+
pub elapsed: Duration,
281288
}
282289

283290
impl fmt::Display for DeleteStats {
@@ -293,6 +300,9 @@ impl fmt::Display for DeleteStats {
293300
writeln!(w)?;
294301

295302
write_count(w, "deletion errors", self.deletion_errors);
303+
writeln!(w)?;
304+
305+
write_duration(w, "elapsed", self.elapsed)?;
296306

297307
Ok(())
298308
}

tests/gc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015, 2016, 2017, 2019, 2020 Martin Pool.
1+
// Copyright 2015, 2016, 2017, 2019, 2020, 2021 Martin Pool.
22

33
// This program is free software; you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -50,6 +50,7 @@ fn unreferenced_blocks() {
5050
deletion_errors: 0,
5151
deleted_block_count: 0,
5252
deleted_band_count: 0,
53+
elapsed: delete_stats.elapsed,
5354
}
5455
);
5556

@@ -68,6 +69,7 @@ fn unreferenced_blocks() {
6869
deletion_errors: 0,
6970
deleted_block_count: 1,
7071
deleted_band_count: 0,
72+
elapsed: delete_stats.elapsed,
7173
}
7274
);
7375

@@ -81,6 +83,7 @@ fn unreferenced_blocks() {
8183
deletion_errors: 0,
8284
deleted_block_count: 0,
8385
deleted_band_count: 0,
86+
elapsed: delete_stats.elapsed,
8487
}
8588
);
8689
}

0 commit comments

Comments
 (0)