Skip to content

Commit

Permalink
Docs for counters, and remove unused values
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Sep 30, 2023
1 parent 10753bb commit b8a5692
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn backup(
task.set_name(format!("Backup {}", entry.apath()));
if let Some(bytes) = entry.size() {
if bytes > 0 {
monitor.count(Counter::ScannedFileBytes, bytes as usize);
monitor.count(Counter::FileBytes, bytes as usize);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/blockdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use tracing::{instrument, trace};
use crate::backup::BackupStats;
use crate::blockhash::BlockHash;
use crate::compress::snappy::{Compressor, Decompressor};
use crate::counters::Counter;
use crate::monitor::Monitor;
use crate::transport::{ListDir, Transport};
use crate::*;
Expand Down Expand Up @@ -325,7 +324,6 @@ impl BlockDir {
.flat_map(|hash| match self.get_block_content(&hash) {
Ok(bytes) => {
task.increment(1);
monitor.count(Counter::BlockBytesDone, bytes.len());
Some((hash, bytes.len()))
}
Err(err) => {
Expand Down
28 changes: 18 additions & 10 deletions src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//!
//! Library code sets counters through the [Monitor] interface.
#![warn(missing_docs)]

use std::fmt::{self, Debug};
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
Expand All @@ -12,41 +14,47 @@ use itertools::Itertools;
use strum::{EnumCount, IntoEnumIterator};
use strum_macros::{EnumCount, EnumIter};

/// Counters of events or bytes.
#[derive(Debug, Clone, Copy, Eq, PartialEq, EnumCount, EnumIter)]
pub enum Counter {
/// Number of files processed.
/// Number of files processed (restored, backed up, etc).
///
/// Includes files that are unchanged, but not files that are excluded.
Files,
/// Total bytes in files processed.
FileBytes,
/// Number of directories processed.
Dirs,
/// Number of symlinks processed.
Symlinks,
Bands,
IndexBytesDone,
BlockBytesDone,
BlockRead,
BlockWrite,
BlockMatchExisting,
BlockCacheHit,
ScannedFileBytes,
/// Number of entries (files etc) that are unchanged from the basis backup.
EntriesUnchanged,
/// Number of entries changed since the basis backup.
EntriesChanged,
/// Number of entries added since the basis backup.
EntriesAdded,
/// Number of entries deleted relative to the basis backup.
EntriesDeleted,
// ...
}

/// Counter values, identified by a [Counter].
#[derive(Default)]
pub struct Counters {
counters: [AtomicUsize; Counter::COUNT],
}

impl Counters {
/// Increase the value for a given counter by an amount.
pub fn count(&self, counter: Counter, increment: usize) {
self.counters[counter as usize].fetch_add(increment, Relaxed);
}

/// Set the absolute value of a counter.
pub fn set(&self, counter: Counter, value: usize) {
self.counters[counter as usize].store(value, Relaxed);
}

/// Get the current value of a counter.
pub fn get(&self, counter: Counter) -> usize {
self.counters[counter as usize].load(Relaxed)
}
Expand Down

0 comments on commit b8a5692

Please sign in to comment.