progress bar issues fixed with multiprogress

This commit is contained in:
sreedevk
2025-07-13 13:21:20 +00:00
parent 3a03208f47
commit fcf69ae1cc
4 changed files with 35 additions and 9 deletions

View File

@@ -133,3 +133,5 @@ These benchmarks were run using [hyperfine](https://github.com/sharkdp/hyperfine
- [ ] restore json output
- [ ] update documentation
- [x] remove color output
- [ ] progress bar improvements
- [ ] use progress bar groups

View File

@@ -1,6 +1,8 @@
use anyhow::Result;
use dashmap::DashMap;
use indicatif::{ParallelProgressIterator, ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{
MultiProgress, ParallelProgressIterator, ProgressBar, ProgressFinish, ProgressStyle,
};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use std::borrow::Cow;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
@@ -17,9 +19,10 @@ impl Processor {
app_args: Arc<Params>,
sw_store: Arc<DashMap<u64, Vec<FileInfo>>>,
hw_store: Arc<DashMap<String, Vec<FileInfo>>>,
progress_bar_box: Arc<MultiProgress>,
) -> Result<()> {
let progress_bar = match app_args.progress {
true => ProgressBar::new_spinner(),
true => progress_bar_box.add(ProgressBar::new_spinner()),
false => ProgressBar::hidden(),
};
@@ -69,9 +72,10 @@ impl Processor {
store: Arc<DashMap<u64, Vec<FileInfo>>>,
files: Arc<Mutex<Vec<FileInfo>>>,
max_file_size: Arc<AtomicU64>,
progress_bar_box: Arc<MultiProgress>,
) -> Result<()> {
let progress_bar = match app_args.progress {
true => ProgressBar::new_spinner(),
true => progress_bar_box.add(ProgressBar::new_spinner()),
false => ProgressBar::hidden(),
};
@@ -118,6 +122,7 @@ impl Processor {
mod tests {
use anyhow::Result;
use dashmap::DashMap;
use indicatif::MultiProgress;
use rand::Rng;
use std::fs::File;
use std::io::Write;
@@ -162,6 +167,7 @@ mod tests {
dupstore.clone(),
file_queue,
Arc::new(AtomicU64::new(0)),
Arc::new(MultiProgress::new()),
)?;
assert_eq!(dupstore.len(), 2);

View File

@@ -1,7 +1,7 @@
#![allow(unused)]
use crate::{fileinfo::FileInfo, params::Params};
use anyhow::Result;
use indicatif::{ProgressBar, ProgressStyle};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use std::sync::{Arc, Mutex};
use std::{fs, path::PathBuf, time::Duration};
@@ -102,11 +102,16 @@ impl Scanner {
Ok(walker.build()?)
}
pub fn scan(&self, files: Arc<Mutex<Vec<FileInfo>>>) -> Result<()> {
pub fn scan(
&self,
files: Arc<Mutex<Vec<FileInfo>>>,
progress_bar_box: Arc<MultiProgress>,
) -> Result<()> {
let progress_bar = match self.progress {
true => ProgressBar::new_spinner(),
true => progress_bar_box.add(ProgressBar::new_spinner()),
false => ProgressBar::hidden(),
};
let progress_style = ProgressStyle::with_template("[{elapsed_precise}] {pos:>7} {msg}")?;
progress_bar.set_style(progress_style);
progress_bar.enable_steady_tick(Duration::from_millis(50));

View File

@@ -5,6 +5,7 @@ use crate::processor::Processor;
use crate::scanner::Scanner;
use anyhow::Result;
use dashmap::DashMap;
use indicatif::MultiProgress;
use threadpool::ThreadPool;
use crate::fileinfo::FileInfo;
@@ -32,6 +33,8 @@ impl Server {
}
pub fn start(&self) -> Result<()> {
let progbarbox = Arc::new(MultiProgress::new());
let app_args_clone_for_sc = self.app_args.clone();
let app_args_clone_for_pr = self.app_args.clone();
let file_queue_clone_sc = self.filequeue.clone();
@@ -46,15 +49,19 @@ impl Server {
let store_dupl_hw = self.hw_duplicate_set.clone();
let max_file_path_len_clone = self.max_file_path_len.clone();
let progbarbox_sc_clone = progbarbox.clone();
self.threadpool.execute(move || {
Scanner::build(app_args_clone_for_sc)
.unwrap()
.scan(file_queue_clone_sc)
.scan(file_queue_clone_sc, progbarbox_sc_clone)
.unwrap();
sfin_sc_tr_cl.store(true, std::sync::atomic::Ordering::Relaxed);
});
let progbarbox_pr_clone = progbarbox.clone();
self.threadpool.execute(move || {
Processor::sizewise(
app_args_clone_for_pr.clone(),
@@ -62,11 +69,17 @@ impl Server {
store_dupl_sw_for_sw,
file_queue_clone_pr,
max_file_path_len_clone,
progbarbox_pr_clone.clone(),
)
.unwrap();
Processor::hashwise(app_args_clone_for_pr, store_dupl_sw_for_hw, store_dupl_hw)
.unwrap();
Processor::hashwise(
app_args_clone_for_pr,
store_dupl_sw_for_hw,
store_dupl_hw,
progbarbox_pr_clone,
)
.unwrap();
});
self.threadpool.join();