diff options
author | Daniel <kingdread@gmx.de> | 2018-09-07 00:16:44 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2018-09-07 01:15:35 +0200 |
commit | 13281d5f8aaaed5a9037784f5fa38068f9b7bf65 (patch) | |
tree | 2b8df9d3afc40290191383e1d5169b2cc72131b6 /src/main.rs | |
parent | b94272563e98ca268bcee800533ce851cce9c604 (diff) | |
download | raidgrep-13281d5f8aaaed5a9037784f5fa38068f9b7bf65.tar.gz raidgrep-13281d5f8aaaed5a9037784f5fa38068f9b7bf65.tar.bz2 raidgrep-13281d5f8aaaed5a9037784f5fa38068f9b7bf65.zip |
parallelize log searching
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index c776336..29f482f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ extern crate colored; extern crate evtclib; extern crate regex; extern crate walkdir; +extern crate rayon; use std::fs::File; use std::io::{self, BufReader}; @@ -17,6 +18,8 @@ use regex::Regex; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; +use rayon::prelude::*; + use evtclib::{AgentKind, AgentName, EventKind, Log}; mod errors; @@ -103,16 +106,16 @@ fn is_log_file(entry: &DirEntry) -> bool { fn grep(opt: &Opt) -> Result<(), RuntimeError> { let walker = WalkDir::new(&opt.path); - for entry in walker { - let entry = entry?; + let entries = walker.into_iter().collect::<Vec<_>>(); + entries.into_par_iter().try_for_each(|e| { + let entry = e?; if is_log_file(&entry) { if let Some(result) = search_log(&entry, opt)? { output::colored(io::stdout(), &result)?; } } - } - - Ok(()) + Ok(()) + }) } fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeError> { |