mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +02:00
show stats in dir
This commit is contained in:
parent
eb4a1379af
commit
2dde316476
1 changed files with 24 additions and 2 deletions
|
|
@ -2,16 +2,26 @@ use main_error::MainError;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::stdout;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
use tf_log_parser::parse;
|
use tf_log_parser::parse;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
fn main() -> Result<(), MainError> {
|
fn main() -> Result<(), MainError> {
|
||||||
let path = args().nth(1).expect("No path provided");
|
let path = args().nth(1).expect("No path provided");
|
||||||
|
|
||||||
|
let mut parse_time = Duration::default();
|
||||||
|
let mut count = 0;
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
|
let mut stdout = stdout().lock();
|
||||||
|
|
||||||
for entry in WalkDir::new(path) {
|
for entry in WalkDir::new(path) {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path.extension() == Some(OsStr::new("log")) {
|
if path.extension() == Some(OsStr::new("log")) {
|
||||||
print!("{} - ", path.display());
|
let _ = write!(&mut stdout, "{} - ", path.display());
|
||||||
let input = match fs::read_to_string(path) {
|
let input = match fs::read_to_string(path) {
|
||||||
Ok(input) => input,
|
Ok(input) => input,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -19,10 +29,22 @@ fn main() -> Result<(), MainError> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let parse_start = Instant::now();
|
||||||
let (output, _) = parse(&input)?;
|
let (output, _) = parse(&input)?;
|
||||||
println!("{} messages", output.chat.len());
|
parse_time += parse_start.elapsed();
|
||||||
|
count += 1;
|
||||||
|
let _ = writeln!(&mut stdout, "{} messages", output.chat.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let total = start.elapsed();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Parsed {} in {:01}s with {:01}s of IO overhead",
|
||||||
|
count,
|
||||||
|
parse_time.as_secs_f32(),
|
||||||
|
total.as_secs_f32()
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue