Skip to content

Commit 973e34f

Browse files
committed
Refactor CompileDirectoryEntry, print size
Fixes https://github.com/pytorch/pytorch/issues/134301 Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 29c22b4 ghstack-comment-id: 2324862517 Pull Request resolved: #64
1 parent 6c6e3c3 commit 973e34f

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ regex = "1.9.2"
3232
serde = { version = "1.0.185", features = ["serde_derive"] }
3333
serde_json = "1.0.100"
3434
tinytemplate = "1.1.0"
35+
human_bytes = "0.4.3"

src/lib.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use fxhash::{FxHashMap, FxHashSet};
33
use md5::{Digest, Md5};
44
use std::ffi::{OsStr, OsString};
55

6+
use human_bytes::human_bytes;
67
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
78
use regex::Regex;
89
use std::cell::RefCell;
@@ -82,7 +83,7 @@ fn run_parser<'t>(
8283
payload: &str,
8384
output_count: &mut i32,
8485
output: &mut Vec<(PathBuf, String)>,
85-
compile_directory: &mut Vec<(String, String, i32)>,
86+
compile_directory: &mut Vec<CompileDirectoryEntry>,
8687
multi: &MultiProgress,
8788
stats: &mut Stats,
8889
) {
@@ -106,27 +107,36 @@ fn run_parser<'t>(
106107
} else {
107108
raw_filename
108109
};
110+
let size = human_bytes(out.len() as f64);
109111
output.push((filename.clone(), out));
110112
let filename_str = format!("{}", filename.to_string_lossy());
111-
compile_directory.push((
112-
filename_str.clone(),
113-
filename_str,
114-
*output_count,
115-
));
113+
compile_directory.push(CompileDirectoryEntry {
114+
filename: filename_str.clone(),
115+
display_filename: filename_str,
116+
seq_nr: *output_count,
117+
size: size,
118+
});
116119
*output_count += 1;
117120
}
118121
ParserOutput::GlobalFile(filename, out) => {
122+
let size = human_bytes(out.len() as f64);
119123
output.push((filename.clone(), out));
120124
let filename_str = format!("{}", filename.to_string_lossy());
121-
compile_directory.push((
122-
filename_str.clone(),
123-
filename_str,
124-
*output_count,
125-
));
125+
compile_directory.push(CompileDirectoryEntry {
126+
filename: filename_str.clone(),
127+
display_filename: filename_str,
128+
seq_nr: *output_count,
129+
size: size,
130+
});
126131
*output_count += 1;
127132
}
128133
ParserOutput::Link(name, url) => {
129-
compile_directory.push((url, name, *output_count));
134+
compile_directory.push(CompileDirectoryEntry {
135+
filename: url,
136+
display_filename: name,
137+
seq_nr: *output_count,
138+
size: "".to_string(),
139+
});
130140
*output_count += 1;
131141
}
132142
}
@@ -191,7 +201,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
191201
// Each entry is a compile id => (link, rendered name, output number)
192202
// For files, link and rendered name are the same
193203
// For links, you can specify a custom name for the link
194-
let mut directory: FxIndexMap<Option<CompileId>, Vec<(String, String, i32)>> =
204+
let mut directory: FxIndexMap<Option<CompileId>, Vec<CompileDirectoryEntry>> =
195205
FxIndexMap::default();
196206

197207
let mut metrics_index: CompilationMetricsIndex = FxIndexMap::default();

src/parsers.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub struct CompilationMetricsParser<'t> {
349349
pub tt: &'t TinyTemplate<'t>,
350350
pub stack_index: &'t RefCell<StackIndex>,
351351
pub symbolic_shape_specialization_index: &'t RefCell<SymbolicShapeSpecializationIndex>,
352-
pub output_files: &'t Vec<(String, String, i32)>,
352+
pub output_files: &'t Vec<CompileDirectoryEntry>,
353353
pub compile_id_dir: &'t PathBuf,
354354
}
355355
impl StructuredLogParser for CompilationMetricsParser<'_> {
@@ -416,11 +416,16 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
416416
let new_str: String = parts[1..].join("");
417417
new_str
418418
};
419-
let output_files: Vec<(String, String, i32)> = self
419+
let output_files: Vec<CompileDirectoryEntry> = self
420420
.output_files
421421
.iter()
422-
.map(|(url, name, number)| {
423-
return (remove_prefix(url), remove_prefix(name), number.clone());
422+
.map(|e| {
423+
return CompileDirectoryEntry {
424+
filename: remove_prefix(&e.filename),
425+
display_filename: remove_prefix(&e.display_filename),
426+
seq_nr: e.seq_nr.clone(),
427+
size: e.size.clone(),
428+
};
424429
})
425430
.collect();
426431
let context = CompilationMetricsContext {

src/templates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Build products below:
138138
<li><a id="{compile_directory.0}">{compile_directory.0}</a>
139139
<ul>
140140
{{ for path_idx in compile_directory.1 }}
141-
<li><a href="{path_idx.0}">{path_idx.1}</a> ({path_idx.2})</li>
141+
<li><a href="{path_idx.filename}">{path_idx.display_filename}</a> ({path_idx.seq_nr}) {path_idx.size}</li>
142142
{{ endfor }}
143143
</ul>
144144
</li>

src/types.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub struct CompilationMetricsContext<'e> {
351351
pub compile_id: String,
352352
pub stack_html: String,
353353
pub symbolic_shape_specializations: Vec<SymbolicShapeSpecializationContext>,
354-
pub output_files: &'e Vec<(String, String, i32)>,
354+
pub output_files: &'e Vec<CompileDirectoryEntry>,
355355
pub compile_id_dir: &'e PathBuf,
356356
pub mini_stack_html: String,
357357
}
@@ -556,7 +556,7 @@ pub struct DynamoGuardsContext {
556556
pub struct IndexContext {
557557
pub css: &'static str,
558558
pub javascript: &'static str,
559-
pub directory: Vec<(String, Vec<(String, String, i32)>)>,
559+
pub directory: Vec<(String, Vec<CompileDirectoryEntry>)>,
560560
pub stack_trie_html: String,
561561
pub unknown_stack_trie_html: String,
562562
pub has_unknown_stack_trie: bool,
@@ -573,3 +573,11 @@ pub struct SymbolicShapeSpecializationContext {
573573
pub user_stack_html: String,
574574
pub stack_html: String,
575575
}
576+
577+
#[derive(Debug, Serialize, Clone)]
578+
pub struct CompileDirectoryEntry {
579+
pub filename: String,
580+
pub display_filename: String,
581+
pub seq_nr: i32,
582+
pub size: String,
583+
}

0 commit comments

Comments
 (0)