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

guard_added_fast rendering in compilation metrics #84

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu

let symbolic_shape_specialization_index: RefCell<SymbolicShapeSpecializationIndex> =
RefCell::new(FxHashMap::default());
let guard_added_fast_index: RefCell<GuardAddedFastIndex> = RefCell::new(FxHashMap::default());

// Store results in an output Vec<PathBuf, String>
let mut output: Vec<(PathBuf, String)> = Vec::new();
Expand Down Expand Up @@ -385,6 +386,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
tt: &tt,
stack_index: &stack_index,
symbolic_shape_specialization_index: &symbolic_shape_specialization_index,
guard_added_fast_index: &guard_added_fast_index,
output_files: &copied_directory,
compile_id_dir: &compile_id_dir,
});
Expand Down Expand Up @@ -466,6 +468,13 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
.or_default()
.push(specialization);
}
if let Some(guard_added_fast) = e.guard_added_fast {
guard_added_fast_index
.borrow_mut()
.entry(e.compile_id.clone())
.or_default()
.push(guard_added_fast)
}

if let Some(m) = e.dynamo_start {
if let Some(mut stack) = m.stack {
Expand Down
14 changes: 14 additions & 0 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub struct CompilationMetricsParser<'t> {
pub tt: &'t TinyTemplate<'t>,
pub stack_index: &'t RefCell<StackIndex>,
pub symbolic_shape_specialization_index: &'t RefCell<SymbolicShapeSpecializationIndex>,
pub guard_added_fast_index: &'t RefCell<GuardAddedFastIndex>,
pub output_files: &'t Vec<OutputFile>,
pub compile_id_dir: &'t PathBuf,
}
Expand Down Expand Up @@ -409,6 +410,18 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
stack_html: format_stack(&spec.stack.unwrap_or(Vec::new())),
})
.collect();
let guards_added_fast = self
.guard_added_fast_index
.borrow_mut()
.remove(&cid)
.unwrap_or(Vec::new())
.drain(..)
.map(|guard| GuardAddedFastContext {
expr: guard.expr.unwrap_or("".to_string()),
user_stack_html: format_stack(&guard.user_stack.unwrap_or(Vec::new())),
stack_html: format_stack(&guard.stack.unwrap_or(Vec::new())),
})
.collect();
let remove_prefix = |x: &String| -> String {
// url is X_Y_Z/<rest>. Get the rest of the string for the link
// on compilation metrics page
Expand All @@ -433,6 +446,7 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
stack_html: stack_html,
mini_stack_html: mini_stack_html,
symbolic_shape_specializations: specializations,
guards_added_fast: guards_added_fast,
output_files: &output_files,
compile_id_dir: &self.compile_id_dir,
qps: TEMPLATE_QUERY_PARAM_SCRIPT,
Expand Down
19 changes: 19 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ table td { vertical-align: top; }
.status-empty { background-color: white; color: black; }
.status-ok { background-color: green; color: white; }
.status-break { background-color: lime; color: black; }
summary::-webkit-details-marker { color: #00ACF3; font-size: 125%; margin-right: 2px; }
summary:focus { outline-style: none; }
article > details > summary { font-size: 28px; margin-top: 16px; }
details > p { margin-left: 24px; }
details details { margin-left: 36px; }
details details summary { font-size: 16px; }
"#;

pub static JAVASCRIPT: &str = r#"
Expand Down Expand Up @@ -302,6 +308,19 @@ pub static TEMPLATE_COMPILATION_METRICS: &str = r#"
</tr>
{{ endfor }}
</table>
<h2>Guards added fast</h2>
<table>
<tr>
<th>Expr</th> <th>User stack</th> <th>Framework stack</th>
</tr>
{{ for g in guards_added_fast }}
<tr>
<td>{g.expr}</td>
<td>{g.user_stack_html | format_unescaped}</td>
<td>{g.stack_html | format_unescaped}</td>
</tr>
{{ endfor }}
</table>
{qps | format_unescaped}
</body>
</html>
Expand Down
27 changes: 27 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub type CompilationMetricsIndex = FxIndexMap<Option<CompileId>, Vec<Compilation
pub type StackIndex = FxHashMap<Option<CompileId>, StackSummary>; // NB: attempt is always 0 here
pub type SymbolicShapeSpecializationIndex =
FxHashMap<Option<CompileId>, Vec<SymbolicShapeSpecializationMetadata>>;
pub type GuardAddedFastIndex =
FxHashMap<Option<CompileId>, Vec<GuardAddedFastMetadata>>;

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

Expand Down Expand Up @@ -63,11 +65,14 @@ impl StackTrieNode {
metrics_index: Option<&CompilationMetricsIndex>,
) -> Result<String, fmt::Error> {
let mut f = String::new();
write!(f, "<details>")?;
write!(f, "<summary>Stack</summary>")?;
write!(f, "<div class='stack-trie'>")?;
write!(f, "<ul>")?;
self.fmt_inner(&mut f, metrics_index)?;
write!(f, "</ul>")?;
write!(f, "</div>")?;
write!(f, "</details>")?;
Ok(f)
}

Expand Down Expand Up @@ -390,12 +395,18 @@ pub struct CompilationMetricsContext<'e> {
pub compile_id: String,
pub stack_html: String,
pub symbolic_shape_specializations: Vec<SymbolicShapeSpecializationContext>,
pub guards_added_fast: Vec<GuardAddedFastContext>,
pub output_files: &'e Vec<OutputFile>,
pub compile_id_dir: &'e PathBuf,
pub mini_stack_html: String,
pub qps: &'static str,
}

#[derive(Debug, Serialize)]
pub struct GuardsAddedFastContext {
pub guards: Vec<GuardAddedFastContext>,
}

#[derive(Debug, Serialize)]
pub enum FailureReason {
Failure((String, String, String, u32)), // (failure type, failure reason, user frame filename, user frame lineno)
Expand Down Expand Up @@ -452,13 +463,21 @@ pub enum Metadata<'e> {
BwdCompilationMetrics(&'e BwdCompilationMetricsMetadata),
Artifact(&'e ArtifactMetadata),
DumpFile(&'e DumpFileMetadata),
GuardAddedFast(&'e GuardAddedFastMetadata),
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DumpFileMetadata {
pub name: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GuardAddedFastMetadata {
pub expr: Option<String>,
pub stack: Option<StackSummary>,
pub user_stack: Option<StackSummary>,
}

#[derive(Debug, Deserialize)]
pub struct Envelope {
pub rank: Option<u32>,
Expand Down Expand Up @@ -496,6 +515,7 @@ pub struct Envelope {
pub describe_source: Option<SourceDesc>,
pub dump_file: Option<DumpFileMetadata>,
pub chromium_event: Option<EmptyMetadata>,
pub guard_added_fast: Option<GuardAddedFastMetadata>,
#[serde(flatten)]
pub _other: FxHashMap<String, Value>,
}
Expand Down Expand Up @@ -618,3 +638,10 @@ pub struct SymbolicShapeSpecializationContext {
pub user_stack_html: String,
pub stack_html: String,
}

#[derive(Debug, Serialize)]
pub struct GuardAddedFastContext {
pub expr: String,
pub user_stack_html: String,
pub stack_html: String,
}
Loading