mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
don't store match group lines twice
This commit is contained in:
parent
c1200c5676
commit
2f3e2325df
5 changed files with 10 additions and 13 deletions
15
src/app.rs
15
src/app.rs
|
|
@ -19,11 +19,7 @@ pub struct App<'a> {
|
||||||
|
|
||||||
impl<'a> App<'a> {
|
impl<'a> App<'a> {
|
||||||
pub fn match_lines(&self) -> usize {
|
pub fn match_lines(&self) -> usize {
|
||||||
let unmatched_line_count = if self.unmatched.lines.is_empty() {
|
let unmatched_line_count = if self.unmatched.count == 0 { 0 } else { 1 };
|
||||||
0
|
|
||||||
} else {
|
|
||||||
1
|
|
||||||
};
|
|
||||||
self.matches.len() + 1 + unmatched_line_count
|
self.matches.len() + 1 + unmatched_line_count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +41,7 @@ impl<'a> App<'a> {
|
||||||
|
|
||||||
pub struct LogMatch {
|
pub struct LogMatch {
|
||||||
pub result: Option<MatchResult>,
|
pub result: Option<MatchResult>,
|
||||||
pub lines: Vec<usize>,
|
pub count: usize,
|
||||||
pub histogram: TimeGraph,
|
pub histogram: TimeGraph,
|
||||||
pub sparkline: String,
|
pub sparkline: String,
|
||||||
pub all: GroupedLines,
|
pub all: GroupedLines,
|
||||||
|
|
@ -60,17 +56,18 @@ impl LogMatch {
|
||||||
for line in lines.iter().map(|line| &all_lines[*line]) {
|
for line in lines.iter().map(|line| &all_lines[*line]) {
|
||||||
histogram.add(line.time);
|
histogram.add(line.time);
|
||||||
}
|
}
|
||||||
|
let count = lines.len();
|
||||||
let grouped = group_lines(all_lines, lines.iter().copied());
|
let grouped = group_lines(all_lines, lines.iter().copied());
|
||||||
let sparkline = histogram.sparkline::<10>();
|
let sparkline = histogram.sparkline::<10>();
|
||||||
let all = GroupedLines {
|
let all = GroupedLines {
|
||||||
sparkline: sparkline.clone(),
|
sparkline: sparkline.clone(),
|
||||||
histogram: histogram.clone(),
|
histogram: histogram.clone(),
|
||||||
lines: lines.clone(),
|
lines,
|
||||||
};
|
};
|
||||||
|
|
||||||
LogMatch {
|
LogMatch {
|
||||||
result,
|
result,
|
||||||
lines,
|
count,
|
||||||
histogram,
|
histogram,
|
||||||
sparkline,
|
sparkline,
|
||||||
grouped,
|
grouped,
|
||||||
|
|
@ -116,7 +113,7 @@ impl LogMatch {
|
||||||
|
|
||||||
impl LogMatch {
|
impl LogMatch {
|
||||||
pub fn count(&self) -> usize {
|
pub fn count(&self) -> usize {
|
||||||
self.lines.len()
|
self.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ fn main() -> MainResult {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut error_lines = Vec::with_capacity(32);
|
let mut error_lines = Vec::with_capacity(32);
|
||||||
let mut parsed_lines = Vec::with_capacity(1024);
|
let mut parsed_lines = Vec::with_capacity(results.len());
|
||||||
let mut unmatched_lines = Vec::with_capacity(256);
|
let mut unmatched_lines = Vec::with_capacity(256);
|
||||||
|
|
||||||
let mut parsed_index = 0;
|
let mut parsed_index = 0;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub fn footer<'a>(app: &App<'a>, params: FooterParams<'a>) -> Table<'a> {
|
||||||
Table::new(
|
Table::new(
|
||||||
[Row::new([
|
[Row::new([
|
||||||
Text::from(help(page)),
|
Text::from(help(page)),
|
||||||
Text::from(format!("{} unmatched items", app.unmatched.lines.len())),
|
Text::from(format!("{} unmatched items", app.unmatched.count())),
|
||||||
Text::from(format!("{} parse errors", app.error_count)),
|
Text::from(format!("{} parse errors", app.error_count)),
|
||||||
])],
|
])],
|
||||||
widths,
|
widths,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn match_list<'a>(app: &'a App<'a>, filter: &Filter) -> ScrollbarTable<'a> {
|
||||||
];
|
];
|
||||||
|
|
||||||
let all = log_row(&app.all, app, "All lines");
|
let all = log_row(&app.all, app, "All lines");
|
||||||
let unmatched = if app.unmatched.lines.is_empty() {
|
let unmatched = if app.unmatched.count() == 0 {
|
||||||
Either::Right(empty())
|
Either::Right(empty())
|
||||||
} else {
|
} else {
|
||||||
Either::Left(once(log_row(&app.unmatched, app, "Unmatched lines")))
|
Either::Left(once(log_row(&app.unmatched, app, "Unmatched lines")))
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ pub fn grouped_lines<'a>(
|
||||||
Text::from(""),
|
Text::from(""),
|
||||||
Text::from(""),
|
Text::from(""),
|
||||||
Text::from(log_match.sparkline.as_str()),
|
Text::from(log_match.sparkline.as_str()),
|
||||||
Text::from(log_match.lines.len().to_string()),
|
Text::from(log_match.count().to_string()),
|
||||||
]))
|
]))
|
||||||
.chain(
|
.chain(
|
||||||
grouped
|
grouped
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue