Skip to content

Commit 0c188bb

Browse files
tstackttiimm
authored andcommitted
[progress] fix reporting after change to working in chunks
1 parent 4f1f110 commit 0c188bb

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub use progress::WorkInfo;
3131
use source_query::QueryResult;
3232
pub use source_query::SourceQuery;
3333
pub use source_ref::SourceRef;
34+
use crate::progress::WorkGuard;
3435

3536
#[derive(Error, Debug, Diagnostic, Clone)]
3637
pub enum LogError {
@@ -161,6 +162,7 @@ impl LogMatcher {
161162
pub fn extract_log_statements(&mut self, tracker: &ProgressTracker) {
162163
tracker.begin_step("Extracting log statements".to_string());
163164
self.roots.iter_mut().for_each(|(_path, coll)| {
165+
let guard = tracker.doing_work(coll.tree.stats().files as u64, "files".to_string());
164166
for event_chunk in &coll.tree.scan().chunks(10) {
165167
let sources = event_chunk
166168
.flat_map(|event| match event {
@@ -179,7 +181,7 @@ impl LogMatcher {
179181
}
180182
})
181183
.collect::<Vec<CodeSource>>();
182-
extract_logging(&sources, tracker)
184+
extract_logging_guarded(&sources, &guard)
183185
.into_iter()
184186
.for_each(|sif| {
185187
coll.files_with_statements.insert(sif.id, sif);
@@ -489,8 +491,7 @@ where
489491
.collect()
490492
}
491493

492-
pub fn extract_logging(sources: &[CodeSource], tracker: &ProgressTracker) -> Vec<StatementsInFile> {
493-
let guard = tracker.doing_work(sources.len() as u64, "files".to_string());
494+
pub fn extract_logging_guarded(sources: &[CodeSource], guard: &WorkGuard) -> Vec<StatementsInFile> {
494495
sources
495496
.par_iter()
496497
.flat_map(|code| {
@@ -548,6 +549,11 @@ pub fn extract_logging(sources: &[CodeSource], tracker: &ProgressTracker) -> Vec
548549
.collect()
549550
}
550551

552+
pub fn extract_logging(sources: &[CodeSource], tracker: &ProgressTracker) -> Vec<StatementsInFile> {
553+
let guard = tracker.doing_work(sources.len() as u64, "files".to_string());
554+
extract_logging_guarded(sources, &guard)
555+
}
556+
551557
#[cfg(test)]
552558
mod tests {
553559
use super::*;

src/source_hier.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ pub struct SourceHierTree {
418418
pub root_node: SourceHierNode,
419419
next_id: usize,
420420
deleted_events: Vec<ScanEvent>,
421+
stats: SourceHierStats,
421422
}
422423

423424
impl SourceHierTree {
@@ -427,6 +428,7 @@ impl SourceHierTree {
427428
root_node: SourceHierNode::stub(),
428429
next_id: 0,
429430
deleted_events: Vec::new(),
431+
stats: SourceHierStats::default(),
430432
}
431433
}
432434

@@ -441,6 +443,7 @@ impl SourceHierTree {
441443
&mut self.deleted_events,
442444
);
443445
self.next_id = SourceFileInfo::NEXT_ID.with(|id_opt| *id_opt.borrow());
446+
self.stats = self.compute_stats();
444447
}
445448

446449
/// Scan the tree for changes that have happened since the last scan. Changes to the tree
@@ -482,7 +485,7 @@ impl SourceHierTree {
482485
walk(&self.root_node, &mut f);
483486
}
484487

485-
pub fn stats(&self) -> SourceHierStats {
488+
fn compute_stats(&self) -> SourceHierStats {
486489
let mut retval = SourceHierStats::default();
487490

488491
self.visit(|node| match node.content {
@@ -495,6 +498,10 @@ impl SourceHierTree {
495498

496499
retval
497500
}
501+
502+
pub fn stats(&self) -> &SourceHierStats {
503+
&self.stats
504+
}
498505
}
499506

500507
#[cfg(test)]

0 commit comments

Comments
 (0)