From 13281d5f8aaaed5a9037784f5fa38068f9b7bf65 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 7 Sep 2018 00:16:44 +0200 Subject: parallelize log searching --- Cargo.toml | 1 + src/main.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6558165..5e0c600 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ walkdir = "2" quick-error = "1" colored = "1" chrono = "0.4" +rayon = "1" \ No newline at end of file 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::>(); + 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, RuntimeError> { -- cgit v1.2.3