Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4c0f13

Browse files
committedJan 8, 2025·
guard_added_fast rendering in compilation metrics
1 parent 62ab847 commit b4c0f13

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
 

‎src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
218218

219219
let symbolic_shape_specialization_index: RefCell<SymbolicShapeSpecializationIndex> =
220220
RefCell::new(FxHashMap::default());
221+
let guard_added_fast_index: RefCell<GuardAddedFastIndex> = RefCell::new(FxHashMap::default());
221222

222223
// Store results in an output Vec<PathBuf, String>
223224
let mut output: Vec<(PathBuf, String)> = Vec::new();
@@ -385,6 +386,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
385386
tt: &tt,
386387
stack_index: &stack_index,
387388
symbolic_shape_specialization_index: &symbolic_shape_specialization_index,
389+
guard_added_fast_index: &guard_added_fast_index,
388390
output_files: &copied_directory,
389391
compile_id_dir: &compile_id_dir,
390392
});
@@ -466,6 +468,13 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
466468
.or_default()
467469
.push(specialization);
468470
}
471+
if let Some(guard_added_fast) = e.guard_added_fast {
472+
guard_added_fast_index
473+
.borrow_mut()
474+
.entry(e.compile_id.clone())
475+
.or_default()
476+
.push(guard_added_fast)
477+
}
469478

470479
if let Some(m) = e.dynamo_start {
471480
if let Some(mut stack) = m.stack {

‎src/parsers.rs

+14
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ pub struct CompilationMetricsParser<'t> {
346346
pub tt: &'t TinyTemplate<'t>,
347347
pub stack_index: &'t RefCell<StackIndex>,
348348
pub symbolic_shape_specialization_index: &'t RefCell<SymbolicShapeSpecializationIndex>,
349+
pub guard_added_fast_index: &'t RefCell<GuardAddedFastIndex>,
349350
pub output_files: &'t Vec<OutputFile>,
350351
pub compile_id_dir: &'t PathBuf,
351352
}
@@ -409,6 +410,18 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
409410
stack_html: format_stack(&spec.stack.unwrap_or(Vec::new())),
410411
})
411412
.collect();
413+
let guards_added_fast = self
414+
.guard_added_fast_index
415+
.borrow_mut()
416+
.remove(&cid)
417+
.unwrap_or(Vec::new())
418+
.drain(..)
419+
.map(|guard| GuardAddedFastContext {
420+
expr: guard.expr.unwrap_or("".to_string()),
421+
user_stack_html: format_stack(&guard.user_stack.unwrap_or(Vec::new())),
422+
stack_html: format_stack(&guard.stack.unwrap_or(Vec::new())),
423+
})
424+
.collect();
412425
let remove_prefix = |x: &String| -> String {
413426
// url is X_Y_Z/<rest>. Get the rest of the string for the link
414427
// on compilation metrics page
@@ -433,6 +446,7 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
433446
stack_html: stack_html,
434447
mini_stack_html: mini_stack_html,
435448
symbolic_shape_specializations: specializations,
449+
guards_added_fast: guards_added_fast,
436450
output_files: &output_files,
437451
compile_id_dir: &self.compile_id_dir,
438452
qps: TEMPLATE_QUERY_PARAM_SCRIPT,

‎src/templates.rs

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ table td { vertical-align: top; }
2020
.status-empty { background-color: white; color: black; }
2121
.status-ok { background-color: green; color: white; }
2222
.status-break { background-color: lime; color: black; }
23+
summary::-webkit-details-marker { color: #00ACF3; font-size: 125%; margin-right: 2px; }
24+
summary:focus { outline-style: none; }
25+
article > details > summary { font-size: 28px; margin-top: 16px; }
26+
details > p { margin-left: 24px; }
27+
details details { margin-left: 36px; }
28+
details details summary { font-size: 16px; }
2329
"#;
2430

2531
pub static JAVASCRIPT: &str = r#"
@@ -302,6 +308,19 @@ pub static TEMPLATE_COMPILATION_METRICS: &str = r#"
302308
</tr>
303309
{{ endfor }}
304310
</table>
311+
<h2>Guards added fast</h2>
312+
<table>
313+
<tr>
314+
<th>Expr</th> <th>User stack</th> <th>Framework stack</th>
315+
</tr>
316+
{{ for g in guards_added_fast }}
317+
<tr>
318+
<td>{g.expr}</td>
319+
<td>{g.user_stack_html | format_unescaped}</td>
320+
<td>{g.stack_html | format_unescaped}</td>
321+
</tr>
322+
{{ endfor }}
323+
</table>
305324
{qps | format_unescaped}
306325
</body>
307326
</html>

‎src/types.rs

+27
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub type CompilationMetricsIndex = FxIndexMap<Option<CompileId>, Vec<Compilation
1818
pub type StackIndex = FxHashMap<Option<CompileId>, StackSummary>; // NB: attempt is always 0 here
1919
pub type SymbolicShapeSpecializationIndex =
2020
FxHashMap<Option<CompileId>, Vec<SymbolicShapeSpecializationMetadata>>;
21+
pub type GuardAddedFastIndex =
22+
FxHashMap<Option<CompileId>, Vec<GuardAddedFastMetadata>>;
2123

2224
pub type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
2325

@@ -63,11 +65,14 @@ impl StackTrieNode {
6365
metrics_index: Option<&CompilationMetricsIndex>,
6466
) -> Result<String, fmt::Error> {
6567
let mut f = String::new();
68+
write!(f, "<details>")?;
69+
write!(f, "<summary>Stack</summary>")?;
6670
write!(f, "<div class='stack-trie'>")?;
6771
write!(f, "<ul>")?;
6872
self.fmt_inner(&mut f, metrics_index)?;
6973
write!(f, "</ul>")?;
7074
write!(f, "</div>")?;
75+
write!(f, "</details>")?;
7176
Ok(f)
7277
}
7378

@@ -390,12 +395,18 @@ pub struct CompilationMetricsContext<'e> {
390395
pub compile_id: String,
391396
pub stack_html: String,
392397
pub symbolic_shape_specializations: Vec<SymbolicShapeSpecializationContext>,
398+
pub guards_added_fast: Vec<GuardAddedFastContext>,
393399
pub output_files: &'e Vec<OutputFile>,
394400
pub compile_id_dir: &'e PathBuf,
395401
pub mini_stack_html: String,
396402
pub qps: &'static str,
397403
}
398404

405+
#[derive(Debug, Serialize)]
406+
pub struct GuardsAddedFastContext {
407+
pub guards: Vec<GuardAddedFastContext>,
408+
}
409+
399410
#[derive(Debug, Serialize)]
400411
pub enum FailureReason {
401412
Failure((String, String, String, u32)), // (failure type, failure reason, user frame filename, user frame lineno)
@@ -452,13 +463,21 @@ pub enum Metadata<'e> {
452463
BwdCompilationMetrics(&'e BwdCompilationMetricsMetadata),
453464
Artifact(&'e ArtifactMetadata),
454465
DumpFile(&'e DumpFileMetadata),
466+
GuardAddedFast(&'e GuardAddedFastMetadata),
455467
}
456468

457469
#[derive(Debug, Deserialize, Serialize)]
458470
pub struct DumpFileMetadata {
459471
pub name: String,
460472
}
461473

474+
#[derive(Debug, Deserialize, Serialize)]
475+
pub struct GuardAddedFastMetadata {
476+
pub expr: Option<String>,
477+
pub stack: Option<StackSummary>,
478+
pub user_stack: Option<StackSummary>,
479+
}
480+
462481
#[derive(Debug, Deserialize)]
463482
pub struct Envelope {
464483
pub rank: Option<u32>,
@@ -496,6 +515,7 @@ pub struct Envelope {
496515
pub describe_source: Option<SourceDesc>,
497516
pub dump_file: Option<DumpFileMetadata>,
498517
pub chromium_event: Option<EmptyMetadata>,
518+
pub guard_added_fast: Option<GuardAddedFastMetadata>,
499519
#[serde(flatten)]
500520
pub _other: FxHashMap<String, Value>,
501521
}
@@ -618,3 +638,10 @@ pub struct SymbolicShapeSpecializationContext {
618638
pub user_stack_html: String,
619639
pub stack_html: String,
620640
}
641+
642+
#[derive(Debug, Serialize)]
643+
pub struct GuardAddedFastContext {
644+
pub expr: String,
645+
pub user_stack_html: String,
646+
pub stack_html: String,
647+
}

0 commit comments

Comments
 (0)
Please sign in to comment.