src/backup/chunk_stat.rs: log write speed

This commit is contained in:
Dietmar Maurer 2019-02-25 13:21:00 +01:00
parent 7e3365554e
commit 8eb1203bda
1 changed files with 13 additions and 2 deletions

View File

@ -5,6 +5,8 @@ pub struct ChunkStat {
pub chunk_count: usize,
pub duplicate_chunks: usize,
start_time: std::time::SystemTime,
}
impl ChunkStat {
@ -17,6 +19,8 @@ impl ChunkStat {
chunk_count: 0,
duplicate_chunks: 0,
start_time: std::time::SystemTime::now(),
}
}
}
@ -26,7 +30,14 @@ impl std::fmt::Debug for ChunkStat {
let avg = ((self.size as f64)/(self.chunk_count as f64)) as usize;
let compression = (self.compressed_size*100)/(self.size as u64);
let rate = (self.disk_size*100)/(self.size as u64);
write!(f, "Size: {}, average chunk size: {}, compression rate: {}%, disk_size: {} ({}%)",
self.size, avg, compression, self.disk_size, rate)
let elapsed = self.start_time.elapsed().unwrap();
let elapsed = (elapsed.as_secs() as f64) +
(elapsed.subsec_millis() as f64)/1000.0;
let write_speed = ((self.size as f64)/(1024.0*1024.0))/elapsed;
write!(f, "Size: {}, average chunk size: {}, compression rate: {}%, disk_size: {} ({}%), speed: {:.2} MB/s",
self.size, avg, compression, self.disk_size, rate, write_speed)
}
}