Skip to content

Commit

Permalink
Add support for parsing chromium_events (#62)
Browse files Browse the repository at this point in the history
Internally we can probably `s/https://ui.perfetto.dev/<internal link>` 

For now we will have one trace for the entire tlparse: there are certain
dynamo_timed events that occur outside of compile contexts i.e.
cudagraphify and autotuning, which occur at "runtime", and having them
in separate compile contexts actually makes the data incomplete. If this
turns out to make traces too large we can reconsider some other format
  • Loading branch information
jamesjwu authored Aug 6, 2024
1 parent 5208bc3 commit 188a14f
Show file tree
Hide file tree
Showing 6 changed files with 54,369 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu

let mut all_parsers = default_parsers(&tt, &config);
all_parsers.extend(config.custom_parsers);
let mut chromium_events: Vec<serde_json::Value> = Vec::new();

while let Some((lineno, line)) = iter.next() {
bytes_read += line.len() as u64;
Expand Down Expand Up @@ -438,6 +439,10 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
unknown_stack_trie.insert(stack.clone(), None);
}

if let Some(_) = e.chromium_event {
chromium_events.push(serde_json::from_str(&payload)?);
}

if let Some(specialization) = e.symbolic_shape_specialization {
symbolic_shape_specialization_index
.borrow_mut()
Expand All @@ -463,6 +468,11 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
pb.finish_with_message("done");
spinner.finish();

output.push((
PathBuf::from("chromium_events.json"),
serde_json::to_string_pretty(&chromium_events).unwrap(),
));

eprintln!("{:?}", stats);
if unknown_fields.len() > 0 {
eprintln!(
Expand All @@ -485,6 +495,7 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
unknown_stack_trie_html: unknown_stack_trie.fmt(Some(&metrics_index)).unwrap(),
has_unknown_stack_trie: !unknown_stack_trie.is_empty(),
num_breaks: breaks.failures.len(),
has_chromium_events: !chromium_events.is_empty(),
};
output.push((
PathBuf::from("index.html"),
Expand Down
4 changes: 2 additions & 2 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ impl StructuredLogParser for DumpFileParser {
}
fn parse<'e>(
&self,
lineno: usize,
_lineno: usize,
metadata: Metadata<'e>,
_rank: Option<u32>,
compile_id: &Option<CompileId>,
_compile_id: &Option<CompileId>,
payload: &str,
) -> anyhow::Result<ParserResults> {
if let Metadata::DumpFile(metadata) = metadata {
Expand Down
7 changes: 7 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ phase generates:
<li>Inductor will apply some post grad FX passes, producing <code>inductor_post_grad_graph</code></li>
<li>Inductor will perform code generation, producing the final <code>inductor_output_code</code> which will be executed at runtime. This output is a valid Python program and can be directly run.</li>
</ol>
{{ if has_chromium_events }}
<h2> Chromium Events </h2>
PT2 generates <a href='chromium_events.json'>Chromium Trace Events</a> in JSON on specific events during compilation.
You can download and view them in a tool like <a href='https://ui.perfetto.dev/'>Perfetto</a>.
{{ endif }}
<p>
Build products below:
</p>
Expand All @@ -139,6 +145,7 @@ Build products below:
{{ endfor }}
</ul>
</div>
{{ if has_unknown_stack_trie }}
<div>
<h2>Unknown stacks</h2>
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ pub struct Envelope {
pub describe_tensor: Option<TensorDesc>,
pub describe_source: Option<SourceDesc>,
pub dump_file: Option<DumpFileMetadata>,
pub chromium_event: Option<EmptyMetadata>,
#[serde(flatten)]
pub _other: FxHashMap<String, Value>,
}
Expand Down Expand Up @@ -561,6 +562,7 @@ pub struct IndexContext {
pub has_unknown_stack_trie: bool,
pub num_breaks: usize,
pub custom_header_html: String,
pub has_chromium_events: bool,
}

#[derive(Debug, Serialize)]
Expand Down
Loading

0 comments on commit 188a14f

Please sign in to comment.