add loading progress bar

This commit is contained in:
Robin Appelman 2024-11-05 19:53:22 +01:00
commit 1e33ad60db
3 changed files with 45 additions and 2 deletions

36
Cargo.lock generated
View file

@ -585,6 +585,20 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "indicatif"
version = "0.17.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3"
dependencies = [
"console",
"instant",
"number_prefix",
"portable-atomic",
"rayon",
"unicode-width 0.1.14",
]
[[package]]
name = "indoc"
version = "2.0.5"
@ -610,6 +624,15 @@ dependencies = [
"syn 2.0.87",
]
[[package]]
name = "instant"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
]
[[package]]
name = "is-terminal"
version = "0.4.13"
@ -708,6 +731,7 @@ dependencies = [
"dialoguer",
"flate2",
"hdrhistogram",
"indicatif",
"itertools",
"log",
"logsmash-data",
@ -830,6 +854,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "once_cell"
version = "1.20.2"
@ -887,6 +917,12 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "portable-atomic"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]]
name = "powerfmt"
version = "0.2.0"

View file

@ -30,6 +30,7 @@ xz2 = "0.1.7"
bzip2-rs = "0.1.2"
ruzstd = "0.7.2"
dialoguer = "0.11.0"
indicatif = { version = "0.17.8", features = ["rayon"] }
[target.'cfg(not(target_os = "windows"))'.dependencies]
tikv-jemallocator = "0.6.0"

View file

@ -6,6 +6,7 @@ use crate::matcher::{MatchResult, Matcher};
use crate::ui::run_ui;
use base64::prelude::*;
use clap::Parser;
use indicatif::{ParallelProgressIterator};
use logsmash_data::{default_apps, get_statements, SourceDefinition};
use main_error::MainResult;
use rayon::prelude::*;
@ -70,6 +71,8 @@ fn main() -> MainResult {
);
let matcher = Matcher::new(&statements);
let line_count = lines.len();
let mut results: Vec<_> = lines
.into_par_iter()
.map(|(index, line)| {
@ -80,11 +83,14 @@ fn main() -> MainResult {
parsed.map_err(|err| (index, line, err))
})
.map(|parsed| {
parsed.map(|parsed| {
let res = parsed.map(|parsed| {
let log_match = matcher.match_log(&parsed);
(parsed, log_match)
})
});
// bar.inc(1);
res
})
.progress_count(line_count as u64)
.collect();
results.sort_by_key(|res| match res {