Skip to content

Commit 2754ec1

Browse files
authored
Add create symbols logs to compilation metrics artifact. (#168)
We already have structured logs for symbol creations we just do NOT add them to the tl-parse report ! doing that here. Note: I do not know rust programming this was added with help of AI please review tested after: <img width="1231" height="423" alt="Screenshot 2026-02-02 at 5 19 25 PM" src="https://github.com/user-attachments/assets/7f9f04ba-6b0d-46c0-8964-856319544c4c" />
1 parent e27b5ac commit 2754ec1

4 files changed

Lines changed: 149 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
491491
RefCell::new(FxHashMap::default());
492492
let guard_added_fast_index: RefCell<GuardAddedFastIndex> = RefCell::new(FxHashMap::default());
493493
let sym_expr_info_index: RefCell<SymExprInfoIndex> = RefCell::new(FxHashMap::default());
494+
let create_symbol_index: RefCell<CreateSymbolIndex> = RefCell::new(FxHashMap::default());
495+
let unbacked_symbol_index: RefCell<UnbackedSymbolIndex> = RefCell::new(FxHashMap::default());
494496

495497
// Store results in an output ParseOutput
496498
let mut output: ParseOutput = Vec::new();
@@ -819,6 +821,8 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
819821
stack_index: &stack_index,
820822
symbolic_shape_specialization_index: &symbolic_shape_specialization_index,
821823
guard_added_fast_index: &guard_added_fast_index,
824+
create_symbol_index: &create_symbol_index,
825+
unbacked_symbol_index: &unbacked_symbol_index,
822826
output_files: &copied_directory,
823827
compile_id_dir: &compile_id_dir,
824828
});
@@ -996,7 +1000,7 @@ pub fn parse_path(path: &PathBuf, config: &ParseConfig) -> anyhow::Result<ParseO
9961000
.insert(sym_expr_info.result_id.unwrap(), sym_expr_info);
9971001
}
9981002

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

1017+
// Handle symbol creation events OUTSIDE of export block - they should always be collected
1018+
if let Some(unbacked_symbol) = e.create_unbacked_symbol.clone() {
1019+
// Apply same data migration as in CompilationMetricsParser for consistent HashMap keys
1020+
let mut cid = e.compile_id.clone();
1021+
if let Some(c) = cid.as_mut() {
1022+
if c.frame_compile_id.is_some() {
1023+
c.attempt = Some(c.attempt.unwrap_or(0));
1024+
}
1025+
}
1026+
unbacked_symbol_index
1027+
.borrow_mut()
1028+
.entry(cid)
1029+
.or_default()
1030+
.push(unbacked_symbol);
1031+
}
1032+
1033+
// Handle create_symbol events (backed symbols with concrete values)
1034+
if let Some(symbol) = e.create_symbol.clone() {
1035+
// Apply same data migration as in CompilationMetricsParser for consistent HashMap keys
1036+
let mut cid = e.compile_id.clone();
1037+
if let Some(c) = cid.as_mut() {
1038+
if c.frame_compile_id.is_some() {
1039+
c.attempt = Some(c.attempt.unwrap_or(0));
1040+
}
1041+
}
1042+
create_symbol_index
1043+
.borrow_mut()
1044+
.entry(cid)
1045+
.or_default()
1046+
.push(symbol);
1047+
}
1048+
10131049
if let Some(stack) = e.stack {
10141050
unknown_stack_trie.insert(stack.clone(), None);
10151051
}

src/parsers.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ pub struct CompilationMetricsParser<'t> {
390390
pub stack_index: &'t RefCell<StackIndex>,
391391
pub symbolic_shape_specialization_index: &'t RefCell<SymbolicShapeSpecializationIndex>,
392392
pub guard_added_fast_index: &'t RefCell<GuardAddedFastIndex>,
393+
pub create_symbol_index: &'t RefCell<CreateSymbolIndex>,
394+
pub unbacked_symbol_index: &'t RefCell<UnbackedSymbolIndex>,
393395
pub output_files: &'t Vec<OutputFile>,
394396
pub compile_id_dir: &'t PathBuf,
395397
}
@@ -486,6 +488,50 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
486488
),
487489
})
488490
.collect();
491+
let create_symbols = self
492+
.create_symbol_index
493+
.borrow_mut()
494+
.remove(&cid)
495+
.unwrap_or(Vec::new())
496+
.drain(..)
497+
.map(|sym| CreateSymbolContext {
498+
symbol: sym.symbol.unwrap_or("".to_string()),
499+
val: sym.val.unwrap_or("".to_string()),
500+
vr: sym.vr.unwrap_or("".to_string()),
501+
source: sym.source.unwrap_or("".to_string()),
502+
user_stack_html: format_stack(
503+
&sym.user_stack.unwrap_or(Vec::new()),
504+
"User Stack",
505+
false,
506+
),
507+
stack_html: format_stack(
508+
&sym.stack.unwrap_or(Vec::new()),
509+
"Framework Stack",
510+
false,
511+
),
512+
})
513+
.collect();
514+
let unbacked_symbols = self
515+
.unbacked_symbol_index
516+
.borrow_mut()
517+
.remove(&cid)
518+
.unwrap_or(Vec::new())
519+
.drain(..)
520+
.map(|sym| UnbackedSymbolContext {
521+
symbol: sym.symbol.unwrap_or("".to_string()),
522+
vr: sym.vr.unwrap_or("".to_string()),
523+
user_stack_html: format_stack(
524+
&sym.user_stack.unwrap_or(Vec::new()),
525+
"User Stack",
526+
false,
527+
),
528+
stack_html: format_stack(
529+
&sym.stack.unwrap_or(Vec::new()),
530+
"Framework Stack",
531+
false,
532+
),
533+
})
534+
.collect();
489535
let remove_prefix = |x: &String| -> String {
490536
// url is X_Y_Z/<rest>. Get the rest of the string for the link
491537
// on compilation metrics page
@@ -512,6 +558,8 @@ impl StructuredLogParser for CompilationMetricsParser<'_> {
512558
mini_stack_html: mini_stack_html,
513559
symbolic_shape_specializations: specializations,
514560
guards_added_fast: guards_added_fast,
561+
create_symbols: create_symbols,
562+
unbacked_symbols: unbacked_symbols,
515563
output_files: &output_files,
516564
compile_id_dir: &self.compile_id_dir,
517565
qps: TEMPLATE_QUERY_PARAM_SCRIPT,

src/templates.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,36 @@ pub static TEMPLATE_COMPILATION_METRICS: &str = r#"
376376
</tr>
377377
{{ endfor }}
378378
</table>
379+
<h2>Created Symbols</h2>
380+
<table>
381+
<tr>
382+
<th>Symbol</th> <th>Value</th> <th>Range</th> <th>Source</th> <th>User stack</th> <th>Framework stack</th>
383+
</tr>
384+
{{ for sym in create_symbols }}
385+
<tr>
386+
<td>{sym.symbol}</td>
387+
<td>{sym.val}</td>
388+
<td>{sym.vr}</td>
389+
<td>{sym.source}</td>
390+
<td>{sym.user_stack_html | format_unescaped}</td>
391+
<td>{sym.stack_html | format_unescaped}</td>
392+
</tr>
393+
{{ endfor }}
394+
</table>
395+
<h2>Unbacked Symbols</h2>
396+
<table>
397+
<tr>
398+
<th>Symbol</th> <th>Range</th> <th>User stack</th> <th>Framework stack</th>
399+
</tr>
400+
{{ for sym in unbacked_symbols }}
401+
<tr>
402+
<td>{sym.symbol}</td>
403+
<td>{sym.vr}</td>
404+
<td>{sym.user_stack_html | format_unescaped}</td>
405+
<td>{sym.stack_html | format_unescaped}</td>
406+
</tr>
407+
{{ endfor }}
408+
</table>
379409
{qps | format_unescaped}
380410
</body>
381411
</html>

src/types.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub type SymbolicShapeSpecializationIndex =
2020
FxHashMap<Option<CompileId>, Vec<SymbolicShapeSpecializationMetadata>>;
2121
pub type GuardAddedFastIndex = FxHashMap<Option<CompileId>, Vec<GuardAddedFastMetadata>>;
2222
pub type SymExprInfoIndex = FxHashMap<u64, SymExprInfoMetadata>;
23+
pub type CreateSymbolIndex = FxHashMap<Option<CompileId>, Vec<CreateSymbolMetadata>>;
24+
pub type UnbackedSymbolIndex = FxHashMap<Option<CompileId>, Vec<UnbackedSymbolMetadata>>;
2325

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

@@ -550,7 +552,7 @@ pub struct SymbolicShapePropagateRealTensorMetadata {
550552
pub prefix: Option<String>,
551553
}
552554

553-
#[derive(Debug, Deserialize, Serialize)]
555+
#[derive(Debug, Deserialize, Serialize, Clone)]
554556
pub struct UnbackedSymbolMetadata {
555557
pub symbol: Option<String>,
556558
pub node_id: Option<u64>,
@@ -559,6 +561,16 @@ pub struct UnbackedSymbolMetadata {
559561
pub vr: Option<String>,
560562
}
561563

564+
#[derive(Debug, Deserialize, Serialize, Clone)]
565+
pub struct CreateSymbolMetadata {
566+
pub symbol: Option<String>,
567+
pub val: Option<String>,
568+
pub vr: Option<String>,
569+
pub source: Option<String>,
570+
pub user_stack: Option<StackSummary>,
571+
pub stack: Option<StackSummary>,
572+
}
573+
562574
#[derive(Default, Debug, Deserialize, Serialize)]
563575
pub struct SymExprInfoMetadata {
564576
pub method: Option<String>,
@@ -610,6 +622,8 @@ pub struct CompilationMetricsContext<'e> {
610622
pub stack_html: String,
611623
pub symbolic_shape_specializations: Vec<SymbolicShapeSpecializationContext>,
612624
pub guards_added_fast: Vec<GuardAddedFastContext>,
625+
pub create_symbols: Vec<CreateSymbolContext>,
626+
pub unbacked_symbols: Vec<UnbackedSymbolContext>,
613627
pub output_files: &'e Vec<OutputFile>,
614628
pub compile_id_dir: &'e PathBuf,
615629
pub mini_stack_html: String,
@@ -757,6 +771,7 @@ pub struct Envelope {
757771
pub propagate_real_tensors_provenance: Option<SymbolicShapePropagateRealTensorMetadata>,
758772
pub guard_added: Option<SymbolicShapePropagateRealTensorMetadata>,
759773
pub create_unbacked_symbol: Option<UnbackedSymbolMetadata>,
774+
pub create_symbol: Option<CreateSymbolMetadata>,
760775
pub expression_created: Option<SymExprInfoMetadata>,
761776
pub missing_fake_kernel: Option<FakeKernelMetadata>,
762777
pub mismatched_fake_kernel: Option<FakeKernelMetadata>,
@@ -914,6 +929,24 @@ pub struct GuardAddedFastContext {
914929
pub stack_html: String,
915930
}
916931

932+
#[derive(Debug, Serialize)]
933+
pub struct CreateSymbolContext {
934+
pub symbol: String,
935+
pub val: String,
936+
pub vr: String,
937+
pub source: String,
938+
pub user_stack_html: String,
939+
pub stack_html: String,
940+
}
941+
942+
#[derive(Debug, Serialize)]
943+
pub struct UnbackedSymbolContext {
944+
pub symbol: String,
945+
pub vr: String,
946+
pub user_stack_html: String,
947+
pub stack_html: String,
948+
}
949+
917950
#[derive(Serialize)]
918951
pub struct ProvenanceContext<'a> {
919952
pub css: &'a str,

0 commit comments

Comments
 (0)