Skip to content
Open
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
38 changes: 37 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
RefCell::new(FxHashMap::default());
let guard_added_fast_index: RefCell<GuardAddedFastIndex> = RefCell::new(FxHashMap::default());
let sym_expr_info_index: RefCell<SymExprInfoIndex> = RefCell::new(FxHashMap::default());
let create_symbol_index: RefCell<CreateSymbolIndex> = RefCell::new(FxHashMap::default());
let unbacked_symbol_index: RefCell<UnbackedSymbolIndex> = RefCell::new(FxHashMap::default());

// Store results in an output ParseOutput
let mut output: ParseOutput = Vec::new();
Expand Down Expand Up @@ -819,6 +821,8 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
stack_index: &stack_index,
symbolic_shape_specialization_index: &symbolic_shape_specialization_index,
guard_added_fast_index: &guard_added_fast_index,
create_symbol_index: &create_symbol_index,
unbacked_symbol_index: &unbacked_symbol_index,
output_files: &copied_directory,
compile_id_dir: &compile_id_dir,
});
Expand Down Expand Up @@ -996,7 +1000,7 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
.insert(sym_expr_info.result_id.unwrap(), sym_expr_info);
}

if let Some(unbacked_symbol) = e.create_unbacked_symbol {
if let Some(ref unbacked_symbol) = e.create_unbacked_symbol {
sym_expr_info_index.borrow_mut().insert(
unbacked_symbol.node_id.unwrap(),
SymExprInfoMetadata {
Expand All @@ -1010,6 +1014,38 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
}
}

// Handle symbol creation events OUTSIDE of export block - they should always be collected
if let Some(unbacked_symbol) = e.create_unbacked_symbol.clone() {
// Apply same data migration as in CompilationMetricsParser for consistent HashMap keys
let mut cid = e.compile_id.clone();
if let Some(c) = cid.as_mut() {
if c.frame_compile_id.is_some() {
c.attempt = Some(c.attempt.unwrap_or(0));
}
}
unbacked_symbol_index
.borrow_mut()
.entry(cid)
.or_default()
.push(unbacked_symbol);
}

// Handle create_symbol events (backed symbols with concrete values)
if let Some(symbol) = e.create_symbol.clone() {
// Apply same data migration as in CompilationMetricsParser for consistent HashMap keys
let mut cid = e.compile_id.clone();
if let Some(c) = cid.as_mut() {
if c.frame_compile_id.is_some() {
c.attempt = Some(c.attempt.unwrap_or(0));
}
}
create_symbol_index
.borrow_mut()
.entry(cid)
.or_default()
.push(symbol);
}

if let Some(stack) = e.stack {
unknown_stack_trie.insert(stack.clone(), None);
}
Expand Down
48 changes: 48 additions & 0 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ pub struct CompilationMetricsParser<'t> {
pub stack_index: &'t RefCell<StackIndex>,
pub symbolic_shape_specialization_index: &'t RefCell<SymbolicShapeSpecializationIndex>,
pub guard_added_fast_index: &'t RefCell<GuardAddedFastIndex>,
pub create_symbol_index: &'t RefCell<CreateSymbolIndex>,
pub unbacked_symbol_index: &'t RefCell<UnbackedSymbolIndex>,
pub output_files: &'t Vec<OutputFile>,
pub compile_id_dir: &'t PathBuf,
}
Expand Down Expand Up @@ -486,6 +488,50 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
),
})
.collect();
let create_symbols = self
.create_symbol_index
.borrow_mut()
.remove(&cid)
.unwrap_or(Vec::new())
.drain(..)
.map(|sym| CreateSymbolContext {
symbol: sym.symbol.unwrap_or("".to_string()),
val: sym.val.unwrap_or("".to_string()),
vr: sym.vr.unwrap_or("".to_string()),
source: sym.source.unwrap_or("".to_string()),
user_stack_html: format_stack(
&sym.user_stack.unwrap_or(Vec::new()),
"User Stack",
false,
),
stack_html: format_stack(
&sym.stack.unwrap_or(Vec::new()),
"Framework Stack",
false,
),
})
.collect();
let unbacked_symbols = self
.unbacked_symbol_index
.borrow_mut()
.remove(&cid)
.unwrap_or(Vec::new())
.drain(..)
.map(|sym| UnbackedSymbolContext {
symbol: sym.symbol.unwrap_or("".to_string()),
vr: sym.vr.unwrap_or("".to_string()),
user_stack_html: format_stack(
&sym.user_stack.unwrap_or(Vec::new()),
"User Stack",
false,
),
stack_html: format_stack(
&sym.stack.unwrap_or(Vec::new()),
"Framework Stack",
false,
),
})
.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 @@ -512,6 +558,8 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
mini_stack_html: mini_stack_html,
symbolic_shape_specializations: specializations,
guards_added_fast: guards_added_fast,
create_symbols: create_symbols,
unbacked_symbols: unbacked_symbols,
output_files: &output_files,
compile_id_dir: &self.compile_id_dir,
qps: TEMPLATE_QUERY_PARAM_SCRIPT,
Expand Down
30 changes: 30 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,36 @@ pub static TEMPLATE_COMPILATION_METRICS: &str = r#"
</tr>
{{ endfor }}
</table>
<h2>Created Symbols</h2>
<table>
<tr>
<th>Symbol</th> <th>Value</th> <th>Range</th> <th>Source</th> <th>User stack</th> <th>Framework stack</th>
</tr>
{{ for sym in create_symbols }}
<tr>
<td>{sym.symbol}</td>
<td>{sym.val}</td>
<td>{sym.vr}</td>
<td>{sym.source}</td>
<td>{sym.user_stack_html | format_unescaped}</td>
<td>{sym.stack_html | format_unescaped}</td>
</tr>
{{ endfor }}
</table>
<h2>Unbacked Symbols</h2>
<table>
<tr>
<th>Symbol</th> <th>Range</th> <th>User stack</th> <th>Framework stack</th>
</tr>
{{ for sym in unbacked_symbols }}
<tr>
<td>{sym.symbol}</td>
<td>{sym.vr}</td>
<td>{sym.user_stack_html | format_unescaped}</td>
<td>{sym.stack_html | format_unescaped}</td>
</tr>
{{ endfor }}
</table>
{qps | format_unescaped}
</body>
</html>
Expand Down
35 changes: 34 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub type SymbolicShapeSpecializationIndex =
FxHashMap<Option<CompileId>, Vec<SymbolicShapeSpecializationMetadata>>;
pub type GuardAddedFastIndex = FxHashMap<Option<CompileId>, Vec<GuardAddedFastMetadata>>;
pub type SymExprInfoIndex = FxHashMap<u64, SymExprInfoMetadata>;
pub type CreateSymbolIndex = FxHashMap<Option<CompileId>, Vec<CreateSymbolMetadata>>;
pub type UnbackedSymbolIndex = FxHashMap<Option<CompileId>, Vec<UnbackedSymbolMetadata>>;

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

Expand Down Expand Up @@ -550,7 +552,7 @@ pub struct SymbolicShapePropagateRealTensorMetadata {
pub prefix: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct UnbackedSymbolMetadata {
pub symbol: Option<String>,
pub node_id: Option<u64>,
Expand All @@ -559,6 +561,16 @@ pub struct UnbackedSymbolMetadata {
pub vr: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CreateSymbolMetadata {
pub symbol: Option<String>,
pub val: Option<String>,
pub vr: Option<String>,
pub source: Option<String>,
pub user_stack: Option<StackSummary>,
pub stack: Option<StackSummary>,
}

#[derive(Default, Debug, Deserialize, Serialize)]
pub struct SymExprInfoMetadata {
pub method: Option<String>,
Expand Down Expand Up @@ -610,6 +622,8 @@ pub struct CompilationMetricsContext<'e> {
pub stack_html: String,
pub symbolic_shape_specializations: Vec<SymbolicShapeSpecializationContext>,
pub guards_added_fast: Vec<GuardAddedFastContext>,
pub create_symbols: Vec<CreateSymbolContext>,
pub unbacked_symbols: Vec<UnbackedSymbolContext>,
pub output_files: &'e Vec<OutputFile>,
pub compile_id_dir: &'e PathBuf,
pub mini_stack_html: String,
Expand Down Expand Up @@ -757,6 +771,7 @@ pub struct Envelope {
pub propagate_real_tensors_provenance: Option<SymbolicShapePropagateRealTensorMetadata>,
pub guard_added: Option<SymbolicShapePropagateRealTensorMetadata>,
pub create_unbacked_symbol: Option<UnbackedSymbolMetadata>,
pub create_symbol: Option<CreateSymbolMetadata>,
pub expression_created: Option<SymExprInfoMetadata>,
pub missing_fake_kernel: Option<FakeKernelMetadata>,
pub mismatched_fake_kernel: Option<FakeKernelMetadata>,
Expand Down Expand Up @@ -914,6 +929,24 @@ pub struct GuardAddedFastContext {
pub stack_html: String,
}

#[derive(Debug, Serialize)]
pub struct CreateSymbolContext {
pub symbol: String,
pub val: String,
pub vr: String,
pub source: String,
pub user_stack_html: String,
pub stack_html: String,
}

#[derive(Debug, Serialize)]
pub struct UnbackedSymbolContext {
pub symbol: String,
pub vr: String,
pub user_stack_html: String,
pub stack_html: String,
}

#[derive(Serialize)]
pub struct ProvenanceContext<'a> {
pub css: &'a str,
Expand Down
Loading