mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
more par
This commit is contained in:
parent
e9b5807127
commit
6d4ec29d43
5 changed files with 40 additions and 23 deletions
31
src/main.rs
31
src/main.rs
|
|
@ -61,43 +61,40 @@ fn main() -> MainResult {
|
|||
|
||||
let lines = once(first).chain(lines);
|
||||
|
||||
let results: Vec<_> = lines
|
||||
let mut results: Vec<_> = lines
|
||||
.enumerate()
|
||||
.par_bridge()
|
||||
.filter(|(_, line)| line.starts_with('{'))
|
||||
.map(|(index, line)| {
|
||||
let mut parsed = serde_json::from_str::<LogLine>(&line)?;
|
||||
.flat_map(|(index, line)| {
|
||||
let mut parsed = serde_json::from_str::<LogLine>(&line).ok()?;
|
||||
parsed.index = index;
|
||||
Some(parsed)
|
||||
})
|
||||
.map(|parsed| {
|
||||
let log_match = matcher.match_log(&parsed);
|
||||
Result::<_, serde_json::Error>::Ok((parsed, log_match))
|
||||
(parsed, log_match)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut error_count = 0;
|
||||
results.sort_by_key(|(line, _)| line.index);
|
||||
|
||||
let mut parsed_lines = Vec::with_capacity(1024);
|
||||
let mut unmatched_lines = Vec::with_capacity(256);
|
||||
let mut parsed_index = 0;
|
||||
|
||||
for result in results {
|
||||
for (parsed_index, result) in results.into_iter().enumerate() {
|
||||
let parsed = match result {
|
||||
Ok((parsed, Some(match_result))) => {
|
||||
(parsed, Some(match_result)) => {
|
||||
counts.entry(match_result).or_default().push(parsed_index);
|
||||
parsed
|
||||
}
|
||||
Ok((parsed, None)) => {
|
||||
(parsed, None) => {
|
||||
unmatched_lines.push(parsed_index);
|
||||
parsed
|
||||
}
|
||||
Err(_) => {
|
||||
error_count += 1;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
parsed_lines.push(parsed);
|
||||
parsed_index += 1;
|
||||
}
|
||||
parsed_lines.sort_by_key(|line| line.index);
|
||||
let error_count = log_file.iter().count();
|
||||
|
||||
let mut matched_lines: Vec<(_, _)> = counts.into_iter().collect();
|
||||
matched_lines.sort_by_key(|(_, lines)| lines.len());
|
||||
|
|
@ -111,7 +108,7 @@ fn main() -> MainResult {
|
|||
let unmatched = LogMatch::new(None, unmatched_lines, &parsed_lines);
|
||||
|
||||
let matches = matched_lines
|
||||
.into_iter()
|
||||
.into_par_iter()
|
||||
.map(|(result, lines)| LogMatch::new(Some(result), lines, &parsed_lines))
|
||||
.collect();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::logline::LogLine;
|
||||
use itertools::Either;
|
||||
use logsmash_data::{LogLevel, LoggingStatement, StatementList};
|
||||
use rayon::prelude::*;
|
||||
use regex::Regex;
|
||||
use std::iter::once;
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ impl Matcher {
|
|||
let matches: Vec<_> = statements
|
||||
.iter()
|
||||
.enumerate()
|
||||
.par_bridge()
|
||||
.map(|(index, statement)| LogMatch::new(index, statement))
|
||||
.collect();
|
||||
|
||||
|
|
@ -89,12 +91,28 @@ impl Matcher {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
#[derive(Debug, Clone, Eq, Hash)]
|
||||
pub enum MatchResult {
|
||||
Single(usize),
|
||||
List(Vec<usize>),
|
||||
}
|
||||
|
||||
impl PartialEq for MatchResult {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(MatchResult::Single(a), MatchResult::Single(b)) => a.eq(b),
|
||||
(MatchResult::List(a), MatchResult::List(b)) => {
|
||||
let mut a = a.clone();
|
||||
let mut b = b.clone();
|
||||
a.sort();
|
||||
b.sort();
|
||||
a.eq(&b)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MatchResult {
|
||||
pub fn len(&self) -> usize {
|
||||
match self {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::ui::match_list::match_list;
|
|||
use crate::ui::raw_logs::raw_logs;
|
||||
use crate::ui::single_log::single_log;
|
||||
use crate::ui::single_match::grouped_lines;
|
||||
use crate::ui::state::{LogState, LogsState, MatchListState, MatchState, UiEvent, UiState};
|
||||
use crate::ui::state::{LogState, LogsState, MatchListState, MatchState, UiEvent, UiPage, UiState};
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyModifiers};
|
||||
use ratatui::crossterm::terminal::{
|
||||
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
||||
|
|
@ -36,7 +36,7 @@ pub fn run_ui(app: App) -> Result<(), UiError> {
|
|||
|
||||
while !matches!(ui_state, UiState::Quit) {
|
||||
terminal.draw(|frame| ui(frame, &app, &mut ui_state))?;
|
||||
if let Some(event) = handle_events()? {
|
||||
if let Some(event) = handle_events(ui_state.page())? {
|
||||
ui_state = ui_state.process(event, &app);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ pub fn run_ui(app: App) -> Result<(), UiError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_events() -> io::Result<Option<UiEvent>> {
|
||||
fn handle_events(page: UiPage) -> io::Result<Option<UiEvent>> {
|
||||
if event::poll(std::time::Duration::from_millis(50))? {
|
||||
if let Event::Key(key) = event::read()? {
|
||||
if key.kind == event::KeyEventKind::Press {
|
||||
|
|
@ -55,7 +55,8 @@ fn handle_events() -> io::Result<Option<UiEvent>> {
|
|||
Some(UiEvent::Quit)
|
||||
}
|
||||
KeyCode::Char('q') => Some(UiEvent::Quit),
|
||||
KeyCode::Esc | KeyCode::Left => Some(UiEvent::Back),
|
||||
KeyCode::Esc => Some(UiEvent::Back),
|
||||
KeyCode::Left if page != UiPage::MatchList => Some(UiEvent::Back),
|
||||
KeyCode::Down => Some(UiEvent::Down(1)),
|
||||
KeyCode::Up => Some(UiEvent::Up(1)),
|
||||
KeyCode::PageDown => Some(UiEvent::Down(10)),
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ pub enum UiEvent {
|
|||
Copy,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum UiPage {
|
||||
MatchList,
|
||||
Match,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue