Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo fmt #16

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use clap::Parser;
use std::fs;
use std::path::PathBuf;

use tlparse::{ParseConfig, parse_path};

use tlparse::{parse_path, ParseConfig};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -26,7 +25,6 @@ pub struct Cli {
no_browser: bool,
}


fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let path = cli.path;
Expand Down
93 changes: 53 additions & 40 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ use anyhow::anyhow;
use fxhash::FxHashMap;
use md5::{Digest, Md5};

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use regex::Regex;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::PathBuf;
use tinytemplate::TinyTemplate;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use std::time::Instant;
use tinytemplate::TinyTemplate;


use crate::types::*;
use crate::templates::*;
use crate::parsers::default_parsers;
use crate::templates::*;
use crate::types::*;
mod parsers;
mod templates;
mod types;


pub struct ParseConfig {
pub strict: bool,
pub custom_parsers: Vec<Box<dyn crate::parsers::StructuredLogParser>>,
Expand Down Expand Up @@ -65,16 +63,19 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
let mut directory: FxHashMap<Option<CompileId>, Vec<PathBuf>> = FxHashMap::default();

// Store results in an output Vec<PathBuf, String>
let mut output : Vec<(PathBuf, String)> = Vec::new();
let mut output: Vec<(PathBuf, String)> = Vec::new();

let mut tt : TinyTemplate = TinyTemplate::new();
let mut tt: TinyTemplate = TinyTemplate::new();
tt.add_formatter("format_unescaped", tinytemplate::format_unescaped);
tt.add_template("index.html", TEMPLATE_INDEX)?;
tt.add_template("failures_and_restarts.html", TEMPLATE_FAILURES_AND_RESTARTS)?;
tt.add_template("dynamo_guards.html", TEMPLATE_DYNAMO_GUARDS)?;
tt.add_template("compilation_metrics.html", TEMPLATE_COMPILATION_METRICS)?;

let mut breaks = RestartsAndFailuresContext { css:TEMPLATE_FAILURES_CSS, failures: Vec::new() };
let mut breaks = RestartsAndFailuresContext {
css: TEMPLATE_FAILURES_CSS,
failures: Vec::new(),
};

// NB: Sometimes, the log output we get from Logarithm stutters with a blank line.
// Filter them out, they're never valid (a blank line in payload will still be \t)
Expand Down Expand Up @@ -188,56 +189,63 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
compile_directory.push(filename);
}
}
Err(err) => {
match parser.name() {
"dynamo_guards" => {
eprintln!("Failed to parse guards json: {}", err);
stats.fail_dynamo_guards_json += 1;
}
name => {
eprintln!("Parser {name} failed: {err}");
stats.fail_parser += 1;
}
Err(err) => match parser.name() {
"dynamo_guards" => {
eprintln!("Failed to parse guards json: {}", err);
stats.fail_dynamo_guards_json += 1;
}
}
name => {
eprintln!("Parser {name} failed: {err}");
stats.fail_parser += 1;
}
},
}

}
}

if let Some(m) = e.compilation_metrics {
let compile_id_dir: PathBuf = e.compile_id
.as_ref()
.map_or(
format!("unknown_{lineno}"),
|CompileId {
frame_id,
frame_compile_id,
attempt,
}| { format!("{frame_id}_{frame_compile_id}_{attempt}") },
)
.into();
let compile_id_dir: PathBuf = e
.compile_id
.as_ref()
.map_or(
format!("unknown_{lineno}"),
|CompileId {
frame_id,
frame_compile_id,
attempt,
}| { format!("{frame_id}_{frame_compile_id}_{attempt}") },
)
.into();

let id = e.compile_id.clone().map_or("(unknown) ".to_string(), |c| {
format!("<a href='{}/compilation_metrics.html'>{cid}</a> ", compile_id_dir.display(), cid = c)
format!(
"<a href='{}/compilation_metrics.html'>{cid}</a> ",
compile_id_dir.display(),
cid = c
)
});
if let Some(rr) = m.restart_reasons {
for restart in rr {
breaks.failures.push((id.clone(), format!("{}", FailureReason::Restart(restart))));
breaks
.failures
.push((id.clone(), format!("{}", FailureReason::Restart(restart))));
}
}
if let Some(f) = m.fail_type {
let reason = m.fail_reason.ok_or_else(|| anyhow::anyhow!("Fail reason not found"))?;
let reason = m
.fail_reason
.ok_or_else(|| anyhow::anyhow!("Fail reason not found"))?;
let user_frame_filename = m.fail_user_frame_filename.unwrap_or(String::from("N/A"));
let user_frame_lineno = m.fail_user_frame_lineno.unwrap_or(0);
let failure_reason = FailureReason::Failure((
f.clone(),
reason.clone(),
user_frame_filename.clone(),
user_frame_lineno.clone(),

));
breaks.failures.push((id.clone(), format!("{failure_reason}")));
breaks
.failures
.push((id.clone(), format!("{failure_reason}")));
}
}

Expand All @@ -251,9 +259,11 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
);
};
};

}
output.push((PathBuf::from("failures_and_restarts.html"), tt.render("failures_and_restarts.html", &breaks)?));
output.push((
PathBuf::from("failures_and_restarts.html"),
tt.render("failures_and_restarts.html", &breaks)?,
));
pb.finish_with_message("done");
spinner.finish();

Expand All @@ -268,7 +278,10 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
stack_trie_html: stack_trie.to_string(),
num_breaks: breaks.failures.len(),
};
output.push((PathBuf::from("index.html"), tt.render("index.html", &index_context)?));
output.push((
PathBuf::from("index.html"),
tt.render("index.html", &index_context)?,
));

// other_rank is included here because you should only have logs from one rank when
// configured properly
Expand Down
Loading
Loading