From db872a860aac92a5427209832d186e93c136acff Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 2 Sep 2024 10:18:21 -0400 Subject: [PATCH 1/2] Update [ghstack-poisoned] --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/lib.rs | 36 +++++++++++++++++++++++------------- src/parsers.rs | 13 +++++++++---- src/templates.rs | 2 +- src/types.rs | 12 ++++++++++-- 6 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52370ec..3cbd17c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,12 @@ dependencies = [ "utf8-width", ] +[[package]] +name = "human_bytes" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f255a4535024abf7640cb288260811fc14794f62b063652ed349f9a6c2348e" + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -787,6 +793,7 @@ dependencies = [ "clap", "fxhash", "html-escape", + "human_bytes", "indexmap", "indicatif", "md-5", diff --git a/Cargo.toml b/Cargo.toml index cacdae0..b10c4bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,4 @@ regex = "1.9.2" serde = { version = "1.0.185", features = ["serde_derive"] } serde_json = "1.0.100" tinytemplate = "1.1.0" +human_bytes = "0.4.3" diff --git a/src/lib.rs b/src/lib.rs index 95236e4..fbf4e68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use fxhash::{FxHashMap, FxHashSet}; use md5::{Digest, Md5}; use std::ffi::{OsStr, OsString}; +use human_bytes::human_bytes; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use regex::Regex; use std::cell::RefCell; @@ -82,7 +83,7 @@ fn run_parser<'t>( payload: &str, output_count: &mut i32, output: &mut Vec<(PathBuf, String)>, - compile_directory: &mut Vec<(String, String, i32)>, + compile_directory: &mut Vec, multi: &MultiProgress, stats: &mut Stats, ) { @@ -106,27 +107,36 @@ fn run_parser<'t>( } else { raw_filename }; + let size = human_bytes(out.len() as f64); output.push((filename.clone(), out)); let filename_str = format!("{}", filename.to_string_lossy()); - compile_directory.push(( - filename_str.clone(), - filename_str, - *output_count, - )); + compile_directory.push(CompileDirectoryEntry { + filename: filename_str.clone(), + display_filename: filename_str, + seq_nr: *output_count, + size: size, + }); *output_count += 1; } ParserOutput::GlobalFile(filename, out) => { + let size = human_bytes(out.len() as f64); output.push((filename.clone(), out)); let filename_str = format!("{}", filename.to_string_lossy()); - compile_directory.push(( - filename_str.clone(), - filename_str, - *output_count, - )); + compile_directory.push(CompileDirectoryEntry { + filename: filename_str.clone(), + display_filename: filename_str, + seq_nr: *output_count, + size: size, + }); *output_count += 1; } ParserOutput::Link(name, url) => { - compile_directory.push((url, name, *output_count)); + compile_directory.push(CompileDirectoryEntry { + filename: url, + display_filename: name, + seq_nr: *output_count, + size: "".to_string(), + }); *output_count += 1; } } @@ -191,7 +201,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result (link, rendered name, output number) // For files, link and rendered name are the same // For links, you can specify a custom name for the link - let mut directory: FxIndexMap, Vec<(String, String, i32)>> = + let mut directory: FxIndexMap, Vec> = FxIndexMap::default(); let mut metrics_index: CompilationMetricsIndex = FxIndexMap::default(); diff --git a/src/parsers.rs b/src/parsers.rs index eab4d32..05dc647 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -349,7 +349,7 @@ pub struct CompilationMetricsParser<'t> { pub tt: &'t TinyTemplate<'t>, pub stack_index: &'t RefCell, pub symbolic_shape_specialization_index: &'t RefCell, - pub output_files: &'t Vec<(String, String, i32)>, + pub output_files: &'t Vec, pub compile_id_dir: &'t PathBuf, } impl StructuredLogParser for CompilationMetricsParser<'_> { @@ -416,11 +416,16 @@ impl StructuredLogParser for CompilationMetricsParser<'_> { let new_str: String = parts[1..].join(""); new_str }; - let output_files: Vec<(String, String, i32)> = self + let output_files: Vec = self .output_files .iter() - .map(|(url, name, number)| { - return (remove_prefix(url), remove_prefix(name), number.clone()); + .map(|e| { + return CompileDirectoryEntry { + filename: remove_prefix(&e.filename), + display_filename: remove_prefix(&e.display_filename), + seq_nr: e.seq_nr.clone(), + size: e.size.clone(), + }; }) .collect(); let context = CompilationMetricsContext { diff --git a/src/templates.rs b/src/templates.rs index 73b2df1..88b9190 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -138,7 +138,7 @@ Build products below:
  • {compile_directory.0}
  • diff --git a/src/types.rs b/src/types.rs index 8f54b45..9f76c2a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -351,7 +351,7 @@ pub struct CompilationMetricsContext<'e> { pub compile_id: String, pub stack_html: String, pub symbolic_shape_specializations: Vec, - pub output_files: &'e Vec<(String, String, i32)>, + pub output_files: &'e Vec, pub compile_id_dir: &'e PathBuf, pub mini_stack_html: String, } @@ -556,7 +556,7 @@ pub struct DynamoGuardsContext { pub struct IndexContext { pub css: &'static str, pub javascript: &'static str, - pub directory: Vec<(String, Vec<(String, String, i32)>)>, + pub directory: Vec<(String, Vec)>, pub stack_trie_html: String, pub unknown_stack_trie_html: String, pub has_unknown_stack_trie: bool, @@ -573,3 +573,11 @@ pub struct SymbolicShapeSpecializationContext { pub user_stack_html: String, pub stack_html: String, } + +#[derive(Debug, Serialize, Clone)] +pub struct CompileDirectoryEntry { + pub filename: String, + pub display_filename: String, + pub seq_nr: i32, + pub size: String, +} From be38ac34a3f5fb2e2dbada1f029971ba2884a412 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 3 Sep 2024 10:18:40 -0400 Subject: [PATCH 2/2] Update [ghstack-poisoned] --- src/templates.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates.rs b/src/templates.rs index 88b9190..78f4653 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -221,7 +221,7 @@ pub static TEMPLATE_COMPILATION_METRICS: &str = r#"

    Output files:

    Stack