Skip to content

Commit

Permalink
Move counters to conserve::counters
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Sep 30, 2023
1 parent 661d156 commit 10753bb
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use tracing::{error, warn};

use crate::blockdir::Address;
use crate::change::Change;
use crate::counters::Counter;
use crate::entry::EntryValue;
use crate::io::read_with_retries;
use crate::monitor::counters::Counter;
use crate::monitor::Monitor;
use crate::stats::{
write_compressed_size, write_count, write_duration, write_size, IndexWriterStats,
Expand Down
2 changes: 1 addition & 1 deletion src/blockdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use tracing::{instrument, trace};
use crate::backup::BackupStats;
use crate::blockhash::BlockHash;
use crate::compress::snappy::{Compressor, Decompressor};
use crate::monitor::counters::Counter;
use crate::counters::Counter;
use crate::monitor::Monitor;
use crate::transport::{ListDir, Transport};
use crate::*;
Expand Down
9 changes: 6 additions & 3 deletions src/monitor/counters.rs → src/counters.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Track counters.
// Copyright 2023 Martin Pool

//! Track counters of the number of files, bytes, blocks, etc, processed.
//!
//! Library code sets counters through the [Monitor] interface.
use std::fmt::{self, Debug};
use std::iter::Map;
use std::slice;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;

Expand All @@ -12,6 +14,7 @@ use strum_macros::{EnumCount, EnumIter};

#[derive(Debug, Clone, Copy, Eq, PartialEq, EnumCount, EnumIter)]
pub enum Counter {
/// Number of files processed.
Files,
FileBytes,
Dirs,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod blockdir;
pub mod blockhash;
pub mod change;
pub mod compress;
pub mod counters;
mod diff;
pub mod entry;
pub mod errors;
Expand Down
5 changes: 2 additions & 3 deletions src/monitor/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::{Arc, Mutex, Weak};

use crate::{Apath, GarbageCollectionLock};

use super::counters::{Counter, Counters};
use super::task::{Task, TaskList, TaskState};
use super::{Monitor, Problem};
use crate::counters::{Counter, Counters};
use crate::{Apath, GarbageCollectionLock};

/// A monitor that collects information for later inspection.
///
Expand Down
10 changes: 1 addition & 9 deletions src/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@

//! Communication from the library to a monitor: a test, a UI, etc.
#![allow(unused_imports)]

pub mod collect;
pub mod counters;
pub mod task;

use std::fmt::Debug;

use strum_macros::{EnumCount, EnumIter};

use self::counters::Counter;
use self::task::Task;
use crate::Apath;

pub use counters::Counters;
use crate::counters::Counter;

pub trait Monitor: Send + Sync + 'static {
/// Notify that a counter increased by a given amount.
Expand Down
2 changes: 1 addition & 1 deletion src/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use time::OffsetDateTime;
use tracing::{error, instrument, trace, warn};

use crate::band::BandSelectionPolicy;
use crate::counters::Counter;
use crate::io::{directory_is_empty, ensure_dir_exists};
use crate::monitor::counters::Counter;
use crate::monitor::Monitor;
use crate::stats::RestoreStats;
use crate::unix_mode::UnixMode;
Expand Down
3 changes: 2 additions & 1 deletion src/termui/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::time::Duration;

use nutmeg::{Destination, View};

use crate::counters::{Counter, Counters};
use crate::monitor::task::{Task, TaskList};
use crate::monitor::{counters::Counter, Counters, Monitor, Problem};
use crate::monitor::{Monitor, Problem};

pub struct TermUiMonitor {
// operation: Operation,
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::sync::Arc;

use crate::monitor::counters::Counter;
use crate::counters::Counter;
use crate::monitor::Monitor;
use crate::*;

Expand Down

0 comments on commit 10753bb

Please sign in to comment.