From 50a9ada333c5ce859375a5cc2d9de5a986bb8cbf Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 22 Aug 2023 07:28:32 +0000 Subject: [PATCH 1/7] list out all spans that haven't been closed --- crates/turbopack-convert-trace/src/main.rs | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 213fdc21801dc..41c567dbd0a27 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -253,6 +253,20 @@ fn main() { start.elapsed().as_secs_f64() ); + if !active_ids.is_empty() { + let active_spans = active_ids + .into_values() + .map(|id| &spans[id]) + .filter(|span| span.end == span.start) + .collect::>(); + if !active_spans.is_empty() { + eprintln!("{} spans still active:", active_spans.len()); + for span in active_spans { + eprintln!("- {}", span.name); + } + } + } + let mut name_counts: Vec<(Cow<'_, str>, usize)> = name_counts.into_iter().collect(); name_counts.sort_by_key(|(_, count)| Reverse(*count)); @@ -391,6 +405,7 @@ fn main() { if single || merged { eprint!("Emitting span tree..."); let start = Instant::now(); + let mut span_counter = 0; const CONCURRENCY_FIXED_POINT_FACTOR: u64 = 100; const CONCURRENCY_FIXED_POINT_FACTOR_F: f32 = 100.0; @@ -438,6 +453,7 @@ fn main() { .rev() .filter_map(|(id, span)| { if span.parent == 0 { + span_counter += 1; Some(Task::Enter { id, root: true }) } else { None @@ -603,6 +619,14 @@ fn main() { } } SpanItem::Child(id) => { + span_counter += 1; + if span_counter % 12543 == 0 { + eprint!( + "\rEmitting span tree... {} / {}", + span_counter, + spans.len() + ); + } stack.push(Task::Enter { id: *id, root: false, @@ -690,7 +714,12 @@ fn main() { } } } - eprintln!(" done ({:.3}s)", start.elapsed().as_secs_f64()); + eprintln!( + "\rEmitting span tree... {} / {} done ({:.3}s)", + spans.len(), + spans.len(), + start.elapsed().as_secs_f64() + ); } println!(); println!("]"); From 059b21c59a7a4d62e67109bff5555566d36a8b2d Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 22 Aug 2023 08:28:25 +0000 Subject: [PATCH 2/7] improve span names for trait default implementation --- crates/turbo-tasks-macros/src/value_trait_macro.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/turbo-tasks-macros/src/value_trait_macro.rs b/crates/turbo-tasks-macros/src/value_trait_macro.rs index a7971ff31df6c..6f2f4c1a0621d 100644 --- a/crates/turbo-tasks-macros/src/value_trait_macro.rs +++ b/crates/turbo-tasks-macros/src/value_trait_macro.rs @@ -108,7 +108,8 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream { let mut inline_signature = sig.clone(); inline_signature.ident = inline_function_ident; - let native_function = NativeFn::new(&ident.to_string(), &inline_function_path); + let native_function = + NativeFn::new(&format!("{trait_ident}::{ident}"), &inline_function_path); let native_function_ident = get_trait_default_impl_function_ident(trait_ident, ident); let native_function_ty = native_function.ty(); From cf313010436f25c7d1e4e19cc102d99bf64b3a1f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 22 Aug 2023 08:59:34 +0000 Subject: [PATCH 3/7] avoid collapsing root spans --- crates/turbopack-convert-trace/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 41c567dbd0a27..2087e4488b967 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -16,6 +16,10 @@ //! - `--merged`: Shows all cpu time scaled by the concurrency. //! - `--threads`: Shows cpu time distributed on infinite virtual cpus/threads. //! - `--idle`: Adds extra info spans when cpus are idle. +//! - `--graph`: Collapse spans with the same name into a single span per +//! parent. +//! - `--collapse-names`: Collapse spans with the same type into a single span +//! per parent. //! //! Default is `--merged`. @@ -163,7 +167,7 @@ fn main() { values, } => { let values = values.into_iter().collect(); - let name = get_name(name, &values, collapse_names); + let name = get_name(name, &values, collapse_names && parent.is_some()); let internal_id = ensure_span(&mut active_ids, &mut spans, id); spans[internal_id].name = name.clone(); spans[internal_id].target = target.into(); From 94444d9798c07c63ee8a7066278e9f9b916b96bc Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 23 Aug 2023 09:42:50 +0000 Subject: [PATCH 4/7] print full path and omit waiting parents --- crates/turbopack-convert-trace/src/main.rs | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 2087e4488b967..7d2574068a204 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -23,6 +23,8 @@ //! //! Default is `--merged`. +#![feature(iter_intersperse)] + use std::{ borrow::Cow, cmp::{max, min, Reverse}, @@ -262,11 +264,35 @@ fn main() { .into_values() .map(|id| &spans[id]) .filter(|span| span.end == span.start) + .filter(|span| { + !span.items.iter().any(|item| { + if let &SpanItem::Child(c) = item { + spans[c].end == spans[c].start + } else { + false + } + }) + }) .collect::>(); if !active_spans.is_empty() { eprintln!("{} spans still active:", active_spans.len()); for span in active_spans { - eprintln!("- {}", span.name); + let mut parents = Vec::new(); + let mut current = span; + loop { + parents.push(current); + if current.parent == 0 { + break; + } + current = &spans[current.parent]; + } + let message = parents + .iter() + .rev() + .map(|span| &*span.name) + .intersperse(" > ") + .collect::(); + eprintln!("- {}", message); } } } @@ -275,7 +301,7 @@ fn main() { name_counts.sort_by_key(|(_, count)| Reverse(*count)); eprintln!("Top 10 span names:"); - for (name, count) in name_counts.into_iter().take(10) { + for (name, count) in name_counts.into_iter().take(50) { eprintln!("{}x {}", count, name); } From 9eeab844ff99015755c93c8503a20d4b03e10880 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 23 Aug 2023 10:25:14 +0000 Subject: [PATCH 5/7] fix number of shown spans --- crates/turbopack-convert-trace/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 7d2574068a204..63c3d12eae3ec 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -301,7 +301,7 @@ fn main() { name_counts.sort_by_key(|(_, count)| Reverse(*count)); eprintln!("Top 10 span names:"); - for (name, count) in name_counts.into_iter().take(50) { + for (name, count) in name_counts.into_iter().take(10) { eprintln!("{}x {}", count, name); } From 7d5e3c6fead788d0ed66083195b1793d82cc608a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 23 Aug 2023 12:05:45 +0000 Subject: [PATCH 6/7] avoid too long chains --- crates/turbopack-convert-trace/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 63c3d12eae3ec..79ed4ed60f3ad 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -286,12 +286,16 @@ fn main() { } current = &spans[current.parent]; } - let message = parents + let mut parents = parents .iter() .rev() .map(|span| &*span.name) - .intersperse(" > ") - .collect::(); + .collect::>(); + if parents.len() > 10 { + parents.drain(10..parents.len() - 10); + parents.insert(10, "...") + } + let message = parents.into_iter().intersperse(" > ").collect::(); eprintln!("- {}", message); } } From 4059c10c9e850354cdc18dc84d66a73f71eb54e7 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 23 Aug 2023 12:09:13 +0000 Subject: [PATCH 7/7] improve formatting --- crates/turbopack-convert-trace/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/turbopack-convert-trace/src/main.rs b/crates/turbopack-convert-trace/src/main.rs index 79ed4ed60f3ad..4bcd32cd1a39c 100644 --- a/crates/turbopack-convert-trace/src/main.rs +++ b/crates/turbopack-convert-trace/src/main.rs @@ -295,7 +295,10 @@ fn main() { parents.drain(10..parents.len() - 10); parents.insert(10, "...") } - let message = parents.into_iter().intersperse(" > ").collect::(); + let message = parents + .into_iter() + .intersperse("\n > ") + .collect::(); eprintln!("- {}", message); } }