From 40fbe9ba35116ccff04251f6c52d1607f3480c6f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 2 Apr 2022 15:48:23 +0300 Subject: feat: add data structures for accumulating time measurements Sponsored-by: author --- src/performance.rs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/performance.rs (limited to 'src/performance.rs') diff --git a/src/performance.rs b/src/performance.rs new file mode 100644 index 0000000..79fa9ab --- /dev/null +++ b/src/performance.rs @@ -0,0 +1,118 @@ +//! Performance measurements from an Obnam run. + +use crate::accumulated_time::AccumulatedTime; +use log::info; + +/// The kinds of clocks we have. +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +pub enum Clock { + /// The complete runtime of the program. + RunTime, + + /// Time spent downloading previous backup generations. + GenerationDownload, + + /// Time spent uploading backup generations. + GenerationUpload, + + /// Time spent checking if a chunk exists already on server. + HasChunk, + + /// Time spent computing splitting files into chunks. + Chunking, + + /// Time spent scanning live data. + Scanning, +} + +/// Collected measurements from this Obnam run. +#[derive(Debug)] +pub struct Performance { + args: Vec, + time: AccumulatedTime, + live_files: u64, + files_backed_up: u64, + chunks_uploaded: u64, + chunks_reused: u64, +} + +impl Default for Performance { + fn default() -> Self { + Self { + args: std::env::args().collect(), + time: AccumulatedTime::::new(), + live_files: 0, + files_backed_up: 0, + chunks_reused: 0, + chunks_uploaded: 0, + } + } +} + +impl Performance { + /// Log all performance measurements to the log file. + pub fn log(&self) { + info!("Performance measurements for this Obnam run"); + for (i, arg) in self.args.iter().enumerate() { + info!("argv[{}]={:?}", i, arg); + } + info!("Live files found: {}", self.live_files); + info!("Files backed up: {}", self.files_backed_up); + info!("Chunks uploaded: {}", self.chunks_uploaded); + info!("Chunks reused: {}", self.chunks_reused); + info!( + "Scanning live data (seconds): {}", + self.time.secs(Clock::Scanning) + ); + info!( + "Chunking live data (seconds): {}", + self.time.secs(Clock::Chunking) + ); + info!( + "Checking for duplicate chunks (seconds): {}", + self.time.secs(Clock::HasChunk) + ); + info!( + "Downloading previous generation (seconds): {}", + self.time.secs(Clock::GenerationDownload) + ); + info!( + "Uploading new generation (seconds): {}", + self.time.secs(Clock::GenerationUpload) + ); + info!( + "Complete run time (seconds): {}", + self.time.secs(Clock::RunTime) + ); + } + + /// Start a specific clock. + pub fn start(&mut self, clock: Clock) { + self.time.start(clock) + } + + /// Stop a specific clock. + pub fn stop(&mut self, clock: Clock) { + self.time.stop(clock) + } + + /// Increment number of live files. + pub fn found_live_files(&mut self, n: u64) { + self.live_files += n; + } + + /// Increment number of files backed up this run. + pub fn back_up_file(&mut self) { + self.files_backed_up += 1; + } + + /// Increment number of reused chunks. + pub fn reuse_chunk(&mut self) { + self.chunks_reused += 1; + } + + /// Increment number of uploaded chunks. + pub fn upload_chunk(&mut self) { + self.chunks_uploaded += 1; + } +} -- cgit v1.2.1 From dd13fde5ea8bd61b6b5c7f024df6733301864456 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 2 Apr 2022 15:54:02 +0300 Subject: feat: collect and log some time metrics Log the complete run-time of the program, and the time spent downloading the previous generation, and uploading the new generation. Sponsored-by: author --- src/performance.rs | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/performance.rs') diff --git a/src/performance.rs b/src/performance.rs index 79fa9ab..29c2328 100644 --- a/src/performance.rs +++ b/src/performance.rs @@ -14,15 +14,6 @@ pub enum Clock { /// Time spent uploading backup generations. GenerationUpload, - - /// Time spent checking if a chunk exists already on server. - HasChunk, - - /// Time spent computing splitting files into chunks. - Chunking, - - /// Time spent scanning live data. - Scanning, } /// Collected measurements from this Obnam run. @@ -60,18 +51,6 @@ impl Performance { info!("Files backed up: {}", self.files_backed_up); info!("Chunks uploaded: {}", self.chunks_uploaded); info!("Chunks reused: {}", self.chunks_reused); - info!( - "Scanning live data (seconds): {}", - self.time.secs(Clock::Scanning) - ); - info!( - "Chunking live data (seconds): {}", - self.time.secs(Clock::Chunking) - ); - info!( - "Checking for duplicate chunks (seconds): {}", - self.time.secs(Clock::HasChunk) - ); info!( "Downloading previous generation (seconds): {}", self.time.secs(Clock::GenerationDownload) -- cgit v1.2.1