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", "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]] [[package]]
name = "indoc" name = "indoc"
version = "2.0.5" version = "2.0.5"
@ -610,6 +624,15 @@ dependencies = [
"syn 2.0.87", "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]] [[package]]
name = "is-terminal" name = "is-terminal"
version = "0.4.13" version = "0.4.13"
@ -708,6 +731,7 @@ dependencies = [
"dialoguer", "dialoguer",
"flate2", "flate2",
"hdrhistogram", "hdrhistogram",
"indicatif",
"itertools", "itertools",
"log", "log",
"logsmash-data", "logsmash-data",
@ -830,6 +854,12 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.20.2" version = "1.20.2"
@ -887,6 +917,12 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "portable-atomic"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
version = "0.2.0" version = "0.2.0"

View file

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

View file

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