Unverified Commit 3e8fe3c7 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

add user-level tracing (#59284)

### What?

add a few user-focused info-level spans to allow high-level tracing on a
normal build.

`NEXT_TURBOPACK_TRACING=1` can be used to generate a `.next/trace.log`
file

### Why?

Gain insight into build performance and module cost 



Closes PACK-2083
parent faa44210
...@@ -81,6 +81,7 @@ fn test(input: &Path, minify: bool) { ...@@ -81,6 +81,7 @@ fn test(input: &Path, minify: bool) {
auto_modularize_imports: None, auto_modularize_imports: None,
optimize_barrel_exports: None, optimize_barrel_exports: None,
optimize_server_react: None, optimize_server_react: None,
prefer_esm: false,
}; };
let unresolved_mark = Mark::new(); let unresolved_mark = Mark::new();
......
...@@ -5,6 +5,7 @@ use next_api::{ ...@@ -5,6 +5,7 @@ use next_api::{
route::{Endpoint, WrittenEndpoint}, route::{Endpoint, WrittenEndpoint},
server_paths::ServerPath, server_paths::ServerPath,
}; };
use tracing::Instrument;
use turbo_tasks::Vc; use turbo_tasks::Vc;
use turbopack_binding::turbopack::core::error::PrettyPrintError; use turbopack_binding::turbopack::core::error::PrettyPrintError;
...@@ -114,7 +115,8 @@ pub fn endpoint_server_changed_subscribe( ...@@ -114,7 +115,8 @@ pub fn endpoint_server_changed_subscribe(
subscribe( subscribe(
turbo_tasks, turbo_tasks,
func, func,
move || async move { move || {
async move {
let changed = endpoint.server_changed(); let changed = endpoint.server_changed();
changed.strongly_consistent().await?; changed.strongly_consistent().await?;
if issues { if issues {
...@@ -124,6 +126,8 @@ pub fn endpoint_server_changed_subscribe( ...@@ -124,6 +126,8 @@ pub fn endpoint_server_changed_subscribe(
} else { } else {
Ok((vec![], vec![])) Ok((vec![], vec![]))
} }
}
.instrument(tracing::info_span!("server changes subscription"))
}, },
|ctx| { |ctx| {
let (issues, diags) = ctx.value; let (issues, diags) = ctx.value;
...@@ -146,12 +150,15 @@ pub fn endpoint_client_changed_subscribe( ...@@ -146,12 +150,15 @@ pub fn endpoint_client_changed_subscribe(
subscribe( subscribe(
turbo_tasks, turbo_tasks,
func, func,
move || async move { move || {
async move {
let changed = endpoint.client_changed(); let changed = endpoint.client_changed();
// We don't capture issues and diagonistics here since we don't want to be // We don't capture issues and diagonistics here since we don't want to be
// notified when they change // notified when they change
changed.strongly_consistent().await?; changed.strongly_consistent().await?;
Ok(()) Ok(())
}
.instrument(tracing::info_span!("client changes subscription"))
}, },
|_| { |_| {
Ok(vec![TurbopackResult { Ok(vec![TurbopackResult {
......
...@@ -14,8 +14,10 @@ use next_api::{ ...@@ -14,8 +14,10 @@ use next_api::{
route::{Endpoint, Route}, route::{Endpoint, Route},
}; };
use next_core::tracing_presets::{ use next_core::tracing_presets::{
TRACING_NEXT_TARGETS, TRACING_NEXT_TURBOPACK_TARGETS, TRACING_NEXT_TURBO_TASKS_TARGETS, TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBOPACK_TARGETS,
TRACING_NEXT_TURBO_TASKS_TARGETS,
}; };
use tracing::Instrument;
use tracing_subscriber::{ use tracing_subscriber::{
prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry,
}; };
...@@ -36,7 +38,6 @@ use turbopack_binding::{ ...@@ -36,7 +38,6 @@ use turbopack_binding::{
exit::ExitGuard, exit::ExitGuard,
raw_trace::RawTraceLayer, raw_trace::RawTraceLayer,
trace_writer::{TraceWriter, TraceWriterGuard}, trace_writer::{TraceWriter, TraceWriterGuard},
tracing_presets::TRACING_OVERVIEW_TARGETS,
}, },
}, },
}; };
...@@ -216,8 +217,8 @@ pub async fn project_new( ...@@ -216,8 +217,8 @@ pub async fn project_new(
let guard = if let Some(mut trace) = trace { let guard = if let Some(mut trace) = trace {
// Trace presets // Trace presets
match trace.as_str() { match trace.as_str() {
"overview" => { "overview" | "1" => {
trace = TRACING_OVERVIEW_TARGETS.join(","); trace = TRACING_NEXT_OVERVIEW_TARGETS.join(",");
} }
"next" => { "next" => {
trace = TRACING_NEXT_TARGETS.join(","); trace = TRACING_NEXT_TARGETS.join(",");
...@@ -433,7 +434,8 @@ pub fn project_entrypoints_subscribe( ...@@ -433,7 +434,8 @@ pub fn project_entrypoints_subscribe(
subscribe( subscribe(
turbo_tasks.clone(), turbo_tasks.clone(),
func, func,
move || async move { move || {
async move {
let entrypoints_operation = container.entrypoints(); let entrypoints_operation = container.entrypoints();
let entrypoints = entrypoints_operation.strongly_consistent().await?; let entrypoints = entrypoints_operation.strongly_consistent().await?;
...@@ -441,6 +443,8 @@ pub fn project_entrypoints_subscribe( ...@@ -441,6 +443,8 @@ pub fn project_entrypoints_subscribe(
let diags = get_diagnostics(entrypoints_operation).await?; let diags = get_diagnostics(entrypoints_operation).await?;
Ok((entrypoints, issues, diags)) Ok((entrypoints, issues, diags))
}
.instrument(tracing::info_span!("entrypoints subscription"))
}, },
move |ctx| { move |ctx| {
let (entrypoints, issues, diags) = ctx.value; let (entrypoints, issues, diags) = ctx.value;
...@@ -500,10 +504,10 @@ pub fn project_hmr_events( ...@@ -500,10 +504,10 @@ pub fn project_hmr_events(
turbo_tasks.clone(), turbo_tasks.clone(),
func, func,
{ {
let identifier = identifier.clone(); let outer_identifier = identifier.clone();
let session = session.clone(); let session = session.clone();
move || { move || {
let identifier = identifier.clone(); let identifier = outer_identifier.clone();
let session = session.clone(); let session = session.clone();
async move { async move {
let state = project let state = project
...@@ -524,6 +528,10 @@ pub fn project_hmr_events( ...@@ -524,6 +528,10 @@ pub fn project_hmr_events(
} }
Ok((update, issues, diags)) Ok((update, issues, diags))
} }
.instrument(tracing::info_span!(
"HMR subscription",
identifier = outer_identifier
))
} }
}, },
move |ctx| { move |ctx| {
......
...@@ -35,6 +35,7 @@ use next_core::{ ...@@ -35,6 +35,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime}, util::{get_asset_prefix_from_pathname, NextRuntime},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc}; use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::{ turbo::{
...@@ -1084,12 +1085,33 @@ async fn concatenate_output_assets( ...@@ -1084,12 +1085,33 @@ async fn concatenate_output_assets(
impl Endpoint for AppEndpoint { impl Endpoint for AppEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let span = match this.ty {
AppEndpointType::Page {
ty: AppPageEndpointType::Html,
..
} => {
tracing::info_span!("app endpoint HTML", name = display(&this.page))
}
AppEndpointType::Page {
ty: AppPageEndpointType::Rsc,
..
} => {
tracing::info_span!("app endpoint RSC", name = display(&this.page))
}
AppEndpointType::Route { .. } => {
tracing::info_span!("app endpoint route", name = display(&this.page))
}
AppEndpointType::Metadata { .. } => {
tracing::info_span!("app endpoint metadata", name = display(&this.page))
}
};
async move {
let output = self.output(); let output = self.output();
// Must use self.output_assets() instead of output.output_assets() to make it a // Must use self.output_assets() instead of output.output_assets() to make it a
// single operation // single operation
let output_assets = self.output_assets(); let output_assets = self.output_assets();
let this = self.await?;
let node_root = this.app_project.project().node_root(); let node_root = this.app_project.project().node_root();
let node_root_ref = &node_root.await?; let node_root_ref = &node_root.await?;
...@@ -1116,6 +1138,9 @@ impl Endpoint for AppEndpoint { ...@@ -1116,6 +1138,9 @@ impl Endpoint for AppEndpoint {
}; };
Ok(written_endpoint.cell()) Ok(written_endpoint.cell())
} }
.instrument(span)
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> { async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> {
......
...@@ -5,6 +5,7 @@ use next_core::{ ...@@ -5,6 +5,7 @@ use next_core::{
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2}, next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType}, next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType},
}; };
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc}; use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::tasks_fs::{File, FileContent}, turbo::tasks_fs::{File, FileContent},
...@@ -171,6 +172,8 @@ impl InstrumentationEndpoint { ...@@ -171,6 +172,8 @@ impl InstrumentationEndpoint {
impl Endpoint for InstrumentationEndpoint { impl Endpoint for InstrumentationEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let span = tracing::info_span!("instrumentation endpoint");
async move {
let this = self.await?; let this = self.await?;
let output_assets = self.output_assets(); let output_assets = self.output_assets();
this.project this.project
...@@ -184,6 +187,9 @@ impl Endpoint for InstrumentationEndpoint { ...@@ -184,6 +187,9 @@ impl Endpoint for InstrumentationEndpoint {
Ok(WrittenEndpoint::Edge { server_paths }.cell()) Ok(WrittenEndpoint::Edge { server_paths }.cell())
} }
.instrument(span)
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> { async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> {
......
...@@ -7,6 +7,7 @@ use next_core::{ ...@@ -7,6 +7,7 @@ use next_core::{
next_server::{get_server_runtime_entries, ServerContextType}, next_server::{get_server_runtime_entries, ServerContextType},
util::parse_config_from_source, util::parse_config_from_source,
}; };
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc}; use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{ use turbopack_binding::{
turbo::tasks_fs::{File, FileContent}, turbo::tasks_fs::{File, FileContent},
...@@ -167,6 +168,8 @@ impl MiddlewareEndpoint { ...@@ -167,6 +168,8 @@ impl MiddlewareEndpoint {
impl Endpoint for MiddlewareEndpoint { impl Endpoint for MiddlewareEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let span = tracing::info_span!("middleware endpoint");
async move {
let this = self.await?; let this = self.await?;
let output_assets = self.output_assets(); let output_assets = self.output_assets();
this.project this.project
...@@ -180,6 +183,9 @@ impl Endpoint for MiddlewareEndpoint { ...@@ -180,6 +183,9 @@ impl Endpoint for MiddlewareEndpoint {
Ok(WrittenEndpoint::Edge { server_paths }.cell()) Ok(WrittenEndpoint::Edge { server_paths }.cell())
} }
.instrument(span)
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> { async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> {
......
...@@ -28,6 +28,7 @@ use next_core::{ ...@@ -28,6 +28,7 @@ use next_core::{
PageLoaderAsset, PageLoaderAsset,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
trace::TraceRawVcs, Completion, TaskInput, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc, trace::TraceRawVcs, Completion, TaskInput, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc,
}; };
...@@ -560,11 +561,15 @@ impl PageEndpoint { ...@@ -560,11 +561,15 @@ impl PageEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn client_chunks(self: Vc<Self>) -> Result<Vc<OutputAssets>> { async fn client_chunks(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
async move {
let this = self.await?; let this = self.await?;
let client_module_context = this.pages_project.client_module_context(); let client_module_context = this.pages_project.client_module_context();
let client_module = let client_module = create_page_loader_entry_module(
create_page_loader_entry_module(client_module_context, self.source(), this.pathname); client_module_context,
self.source(),
this.pathname,
);
let Some(client_module) = let Some(client_module) =
Vc::try_resolve_downcast_type::<EcmascriptModuleAsset>(client_module).await? Vc::try_resolve_downcast_type::<EcmascriptModuleAsset>(client_module).await?
...@@ -572,7 +577,7 @@ impl PageEndpoint { ...@@ -572,7 +577,7 @@ impl PageEndpoint {
bail!("expected an ECMAScript module asset"); bail!("expected an ECMAScript module asset");
}; };
let Some(client_main_module) = *esm_resolve( let client_main_module = esm_resolve(
Vc::upcast(PlainResolveOrigin::new( Vc::upcast(PlainResolveOrigin::new(
client_module_context, client_module_context,
this.pages_project this.pages_project
...@@ -589,9 +594,7 @@ impl PageEndpoint { ...@@ -589,9 +594,7 @@ impl PageEndpoint {
) )
.first_module() .first_module()
.await? .await?
else { .context("expected next/dist/client/next-dev-turbopack.js to resolve to a module")?;
bail!("expected next/dist/client/next-dev-turbopack.js to resolve to a module");
};
let Some(client_main_module) = let Some(client_main_module) =
Vc::try_resolve_downcast_type::<EcmascriptModuleAsset>(client_main_module).await? Vc::try_resolve_downcast_type::<EcmascriptModuleAsset>(client_main_module).await?
...@@ -621,6 +624,9 @@ impl PageEndpoint { ...@@ -621,6 +624,9 @@ impl PageEndpoint {
Ok(Vc::cell(client_chunks)) Ok(Vc::cell(client_chunks))
} }
.instrument(tracing::info_span!("page client side rendering"))
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn internal_ssr_chunk( async fn internal_ssr_chunk(
...@@ -635,6 +641,7 @@ impl PageEndpoint { ...@@ -635,6 +641,7 @@ impl PageEndpoint {
runtime_entries: Vc<EvaluatableAssets>, runtime_entries: Vc<EvaluatableAssets>,
edge_runtime_entries: Vc<EvaluatableAssets>, edge_runtime_entries: Vc<EvaluatableAssets>,
) -> Result<Vc<SsrChunk>> { ) -> Result<Vc<SsrChunk>> {
async move {
let this = self.await?; let this = self.await?;
let ssr_module = module_context.process(self.source(), reference_type.clone()); let ssr_module = module_context.process(self.source(), reference_type.clone());
...@@ -660,8 +667,10 @@ impl PageEndpoint { ...@@ -660,8 +667,10 @@ impl PageEndpoint {
}; };
evaluatable_assets.push(evaluatable); evaluatable_assets.push(evaluatable);
let edge_files = edge_chunking_context let edge_files = edge_chunking_context.evaluated_chunk_group(
.evaluated_chunk_group(ssr_module.ident(), Vc::cell(evaluatable_assets.clone())); ssr_module.ident(),
Vc::cell(evaluatable_assets.clone()),
);
let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?; let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?;
let dynamic_import_entries = collect_evaluated_chunk_group( let dynamic_import_entries = collect_evaluated_chunk_group(
...@@ -700,8 +709,11 @@ impl PageEndpoint { ...@@ -700,8 +709,11 @@ impl PageEndpoint {
let availability_info = Value::new(AvailabilityInfo::Root); let availability_info = Value::new(AvailabilityInfo::Root);
let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?; let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?;
let dynamic_import_entries = let dynamic_import_entries = collect_chunk_group(
collect_chunk_group(chunking_context, dynamic_import_modules, availability_info) chunking_context,
dynamic_import_modules,
availability_info,
)
.await?; .await?;
Ok(SsrChunk::NodeJs { Ok(SsrChunk::NodeJs {
...@@ -711,6 +723,9 @@ impl PageEndpoint { ...@@ -711,6 +723,9 @@ impl PageEndpoint {
.cell()) .cell())
} }
} }
.instrument(tracing::info_span!("page server side rendering"))
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn ssr_chunk(self: Vc<Self>) -> Result<Vc<SsrChunk>> { async fn ssr_chunk(self: Vc<Self>) -> Result<Vc<SsrChunk>> {
...@@ -1055,13 +1070,30 @@ impl PageEndpoint { ...@@ -1055,13 +1070,30 @@ impl PageEndpoint {
impl Endpoint for PageEndpoint { impl Endpoint for PageEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> { async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let span = {
let original_name = this.original_name.await?;
match this.ty {
PageEndpointType::Html => {
tracing::info_span!("page endpoint HTML", name = *original_name)
}
PageEndpointType::Data => {
tracing::info_span!("page endpoint data", name = *original_name)
}
PageEndpointType::Api => {
tracing::info_span!("page endpoint API", name = *original_name)
}
PageEndpointType::SsrOnly => {
tracing::info_span!("page endpoint SSR", name = *original_name)
}
}
};
async move {
let output = self.output(); let output = self.output();
// Must use self.output_assets() instead of output.output_assets() to make it a // Must use self.output_assets() instead of output.output_assets() to make it a
// single operation // single operation
let output_assets = self.output_assets(); let output_assets = self.output_assets();
let this = self.await?;
this.pages_project this.pages_project
.project() .project()
.emit_all_output_assets(Vc::cell(output_assets)) .emit_all_output_assets(Vc::cell(output_assets))
...@@ -1086,6 +1118,9 @@ impl Endpoint for PageEndpoint { ...@@ -1086,6 +1118,9 @@ impl Endpoint for PageEndpoint {
Ok(written_endpoint.cell()) Ok(written_endpoint.cell())
} }
.instrument(span)
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> { async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> {
......
...@@ -19,6 +19,7 @@ use next_core::{ ...@@ -19,6 +19,7 @@ use next_core::{
next_telemetry::NextFeatureTelemetry, next_telemetry::NextFeatureTelemetry,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
...@@ -787,6 +788,8 @@ impl Project { ...@@ -787,6 +788,8 @@ impl Project {
self: Vc<Self>, self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>, output_assets: Vc<OutputAssetsOperation>,
) -> Result<Vc<Completion>> { ) -> Result<Vc<Completion>> {
let span = tracing::info_span!("emitting");
async move {
let all_output_assets = all_assets_from_entries_operation(output_assets); let all_output_assets = all_assets_from_entries_operation(output_assets);
self.await? self.await?
...@@ -801,6 +804,9 @@ impl Project { ...@@ -801,6 +804,9 @@ impl Project {
self.node_root(), self.node_root(),
)) ))
} }
.instrument(span)
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn hmr_content( async fn hmr_content(
......
...@@ -7,6 +7,7 @@ use next_core::{ ...@@ -7,6 +7,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime}, util::{get_asset_prefix_from_pathname, NextRuntime},
}; };
use next_swc::server_actions::parse_server_actions; use next_swc::server_actions::parse_server_actions;
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
graph::{GraphTraversal, NonDeterministic}, graph::{GraphTraversal, NonDeterministic},
TryFlatJoinIterExt, Value, ValueToString, Vc, TryFlatJoinIterExt, Value, ValueToString, Vc,
...@@ -174,6 +175,7 @@ async fn get_actions( ...@@ -174,6 +175,7 @@ async fn get_actions(
server_reference_modules: Vc<Vec<Vc<Box<dyn Module>>>>, server_reference_modules: Vc<Vec<Vc<Box<dyn Module>>>>,
asset_context: Vc<Box<dyn AssetContext>>, asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<Vc<AllActions>> { ) -> Result<Vc<AllActions>> {
async move {
let actions = NonDeterministic::new() let actions = NonDeterministic::new()
.skip_duplicates() .skip_duplicates()
.visit( .visit(
...@@ -220,6 +222,9 @@ async fn get_actions( ...@@ -220,6 +222,9 @@ async fn get_actions(
all_actions.sort_keys(); all_actions.sort_keys();
Ok(Vc::cell(all_actions)) Ok(Vc::cell(all_actions))
}
.instrument(tracing::info_span!("find server actions"))
.await
} }
/// The ActionBrowser layer's module is in the Client context, and we need to /// The ActionBrowser layer's module is in the Client context, and we need to
......
...@@ -7,6 +7,7 @@ use indexmap::{ ...@@ -7,6 +7,7 @@ use indexmap::{
IndexMap, IndexMap,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString, debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString,
Vc, Vc,
...@@ -280,6 +281,19 @@ pub async fn find_app_dir_if_enabled(project_path: Vc<FileSystemPath>) -> Result ...@@ -280,6 +281,19 @@ pub async fn find_app_dir_if_enabled(project_path: Vc<FileSystemPath>) -> Result
async fn get_directory_tree( async fn get_directory_tree(
dir: Vc<FileSystemPath>, dir: Vc<FileSystemPath>,
page_extensions: Vc<Vec<String>>, page_extensions: Vc<Vec<String>>,
) -> Result<Vc<DirectoryTree>> {
let span = {
let dir = dir.to_string().await?;
tracing::info_span!("read app directory tree", name = *dir)
};
get_directory_tree_internal(dir, page_extensions)
.instrument(span)
.await
}
async fn get_directory_tree_internal(
dir: Vc<FileSystemPath>,
page_extensions: Vc<Vec<String>>,
) -> Result<Vc<DirectoryTree>> { ) -> Result<Vc<DirectoryTree>> {
let DirectoryContent::Entries(entries) = &*dir.read_dir().await? else { let DirectoryContent::Entries(entries) = &*dir.read_dir().await? else {
bail!("{} must be a directory", dir.to_string().await?); bail!("{} must be a directory", dir.to_string().await?);
...@@ -297,6 +311,7 @@ async fn get_directory_tree( ...@@ -297,6 +311,7 @@ async fn get_directory_tree(
for (basename, entry) in entries { for (basename, entry) in entries {
match *entry { match *entry {
DirectoryEntry::File(file) => { DirectoryEntry::File(file) => {
let file = file.resolve().await?;
if let Some((stem, ext)) = basename.split_once('.') { if let Some((stem, ext)) = basename.split_once('.') {
if page_extensions_value.iter().any(|e| e == ext) { if page_extensions_value.iter().any(|e| e == ext) {
match stem { match stem {
...@@ -362,6 +377,7 @@ async fn get_directory_tree( ...@@ -362,6 +377,7 @@ async fn get_directory_tree(
)); ));
} }
DirectoryEntry::Directory(dir) => { DirectoryEntry::Directory(dir) => {
let dir = dir.resolve().await?;
// appDir ignores paths starting with an underscore // appDir ignores paths starting with an underscore
if !basename.starts_with('_') { if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions); let result = get_directory_tree(dir, page_extensions);
...@@ -864,6 +880,25 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -864,6 +880,25 @@ async fn directory_tree_to_entrypoints_internal(
directory_name: String, directory_name: String,
directory_tree: Vc<DirectoryTree>, directory_tree: Vc<DirectoryTree>,
app_page: AppPage, app_page: AppPage,
) -> Result<Vc<Entrypoints>> {
let span = tracing::info_span!("build layout trees", name = display(&app_page));
directory_tree_to_entrypoints_internal_untraced(
app_dir,
global_metadata,
directory_name,
directory_tree,
app_page,
)
.instrument(span)
.await
}
async fn directory_tree_to_entrypoints_internal_untraced(
app_dir: Vc<FileSystemPath>,
global_metadata: Vc<GlobalMetadata>,
directory_name: String,
directory_tree: Vc<DirectoryTree>,
app_page: AppPage,
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let mut result = IndexMap::new(); let mut result = IndexMap::new();
......
use anyhow::Result; use anyhow::Result;
use indexmap::IndexMap; use indexmap::IndexMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc,
}; };
...@@ -35,6 +36,7 @@ pub async fn get_app_client_references_chunks( ...@@ -35,6 +36,7 @@ pub async fn get_app_client_references_chunks(
client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
) -> Result<Vc<ClientReferencesChunks>> { ) -> Result<Vc<ClientReferencesChunks>> {
async move {
let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types
.await? .await?
.iter() .iter()
...@@ -42,12 +44,15 @@ pub async fn get_app_client_references_chunks( ...@@ -42,12 +44,15 @@ pub async fn get_app_client_references_chunks(
Ok(( Ok((
*client_reference_ty, *client_reference_ty,
match client_reference_ty { match client_reference_ty {
ClientReferenceType::EcmascriptClientReference(ecmascript_client_reference) => { ClientReferenceType::EcmascriptClientReference(
let ecmascript_client_reference_ref = ecmascript_client_reference.await?; ecmascript_client_reference,
) => {
let ecmascript_client_reference_ref =
ecmascript_client_reference.await?;
ClientReferenceChunks { ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast( client_chunks: client_chunking_context.root_chunk_group(
ecmascript_client_reference_ref.client_module, Vc::upcast(ecmascript_client_reference_ref.client_module),
)), ),
ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast( ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast(
ecmascript_client_reference_ref.ssr_module, ecmascript_client_reference_ref.ssr_module,
)), )),
...@@ -56,9 +61,9 @@ pub async fn get_app_client_references_chunks( ...@@ -56,9 +61,9 @@ pub async fn get_app_client_references_chunks(
ClientReferenceType::CssClientReference(css_client_reference) => { ClientReferenceType::CssClientReference(css_client_reference) => {
let css_client_reference_ref = css_client_reference.await?; let css_client_reference_ref = css_client_reference.await?;
ClientReferenceChunks { ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast( client_chunks: client_chunking_context.root_chunk_group(
css_client_reference_ref.client_module, Vc::upcast(css_client_reference_ref.client_module),
)), ),
ssr_chunks: OutputAssets::empty(), ssr_chunks: OutputAssets::empty(),
} }
} }
...@@ -71,6 +76,9 @@ pub async fn get_app_client_references_chunks( ...@@ -71,6 +76,9 @@ pub async fn get_app_client_references_chunks(
.collect(); .collect();
Ok(Vc::cell(app_client_references_chunks)) Ok(Vc::cell(app_client_references_chunks))
}
.instrument(tracing::info_span!("process client references"))
.await
} }
/// Crawls all modules emitted in the client transition, returning a list of all /// Crawls all modules emitted in the client transition, returning a list of all
......
...@@ -3,6 +3,7 @@ use std::future::Future; ...@@ -3,6 +3,7 @@ use std::future::Future;
use anyhow::Result; use anyhow::Result;
use indexmap::IndexSet; use indexmap::IndexSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
...@@ -61,6 +62,7 @@ pub struct ClientReferenceGraph { ...@@ -61,6 +62,7 @@ pub struct ClientReferenceGraph {
impl ClientReferenceGraph { impl ClientReferenceGraph {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(entries: Vc<Modules>) -> Result<Vc<Self>> { pub async fn new(entries: Vc<Modules>) -> Result<Vc<Self>> {
async move {
let entries = entries.await?; let entries = entries.await?;
let graph = AdjacencyMap::new() let graph = AdjacencyMap::new()
...@@ -82,6 +84,9 @@ impl ClientReferenceGraph { ...@@ -82,6 +84,9 @@ impl ClientReferenceGraph {
Ok(ClientReferenceGraph { graph }.cell()) Ok(ClientReferenceGraph { graph }.cell())
} }
.instrument(tracing::info_span!("find client references"))
.await
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn types(self: Vc<Self>) -> Result<Vc<ClientReferenceTypes>> { pub async fn types(self: Vc<Self>) -> Result<Vc<ClientReferenceTypes>> {
......
use std::future::Future; use std::future::Future;
use anyhow::Result; use anyhow::Result;
use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
TryJoinIterExt, Vc, TryJoinIterExt, Vc,
...@@ -19,6 +20,7 @@ pub struct NextDynamicEntries(Vec<Vc<NextDynamicEntryModule>>); ...@@ -19,6 +20,7 @@ pub struct NextDynamicEntries(Vec<Vc<NextDynamicEntryModule>>);
impl NextDynamicEntries { impl NextDynamicEntries {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn from_entries(entries: Vc<Modules>) -> Result<Vc<NextDynamicEntries>> { pub async fn from_entries(entries: Vc<Modules>) -> Result<Vc<NextDynamicEntries>> {
async move {
let nodes: Vec<_> = AdjacencyMap::new() let nodes: Vec<_> = AdjacencyMap::new()
.skip_duplicates() .skip_duplicates()
.visit( .visit(
...@@ -52,6 +54,9 @@ impl NextDynamicEntries { ...@@ -52,6 +54,9 @@ impl NextDynamicEntries {
Ok(Vc::cell(next_dynamics)) Ok(Vc::cell(next_dynamics))
} }
.instrument(tracing::info_span!("find next/dynamic references"))
.await
}
} }
struct VisitDynamic; struct VisitDynamic;
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{Completion, Vc}; use tracing::Instrument;
use turbo_tasks::{Completion, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPathOption; use turbo_tasks_fs::FileSystemPathOption;
use turbopack_binding::turbo::tasks_fs::{ use turbopack_binding::turbo::tasks_fs::{
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
...@@ -319,6 +320,11 @@ async fn get_pages_structure_for_directory( ...@@ -319,6 +320,11 @@ async fn get_pages_structure_for_directory(
position: u32, position: u32,
page_extensions: Vc<Vec<String>>, page_extensions: Vc<Vec<String>>,
) -> Result<Vc<PagesDirectoryStructure>> { ) -> Result<Vc<PagesDirectoryStructure>> {
let span = {
let path = project_path.to_string().await?;
tracing::info_span!("analyse pages structure", name = *path)
};
async move {
let page_extensions_raw = &*page_extensions.await?; let page_extensions_raw = &*page_extensions.await?;
let mut children = vec![]; let mut children = vec![];
...@@ -374,6 +380,9 @@ async fn get_pages_structure_for_directory( ...@@ -374,6 +380,9 @@ async fn get_pages_structure_for_directory(
children: children.into_iter().map(|(_, v)| v).collect(), children: children.into_iter().map(|(_, v)| v).collect(),
} }
.cell()) .cell())
}
.instrument(span)
.await
} }
fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> { fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> {
......
...@@ -3,14 +3,32 @@ use turbopack_binding::turbopack::trace_utils::tracing_presets::{ ...@@ -3,14 +3,32 @@ use turbopack_binding::turbopack::trace_utils::tracing_presets::{
TRACING_OVERVIEW_TARGETS, TRACING_TURBOPACK_TARGETS, TRACING_TURBO_TASKS_TARGETS, TRACING_OVERVIEW_TARGETS, TRACING_TURBOPACK_TARGETS, TRACING_TURBO_TASKS_TARGETS,
}; };
pub static TRACING_NEXT_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| { pub static TRACING_NEXT_OVERVIEW_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[ [
&TRACING_OVERVIEW_TARGETS[..], &TRACING_OVERVIEW_TARGETS[..],
&[ &[
"next_swc_napi=info",
"next_swc=info",
"next_api=info",
"next_dev=info",
"next_core=info",
"next_font=info",
"turbopack_node=info",
],
]
.concat()
});
pub static TRACING_NEXT_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[
&TRACING_NEXT_OVERVIEW_TARGETS[..],
&[
"next_swc_napi=trace",
"next_swc=trace",
"next_api=trace",
"next_dev=trace", "next_dev=trace",
"next_core=trace", "next_core=trace",
"next_font=trace", "next_font=trace",
"turbopack_node=trace",
], ],
] ]
.concat() .concat()
...@@ -19,7 +37,7 @@ pub static TRACING_NEXT_TURBOPACK_TARGETS: Lazy<Vec<&str>> = ...@@ -19,7 +37,7 @@ pub static TRACING_NEXT_TURBOPACK_TARGETS: Lazy<Vec<&str>> =
Lazy::new(|| [&TRACING_NEXT_TARGETS[..], &TRACING_TURBOPACK_TARGETS[..]].concat()); Lazy::new(|| [&TRACING_NEXT_TARGETS[..], &TRACING_TURBOPACK_TARGETS[..]].concat());
pub static TRACING_NEXT_TURBO_TASKS_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| { pub static TRACING_NEXT_TURBO_TASKS_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[ [
&TRACING_TURBOPACK_TARGETS[..], &TRACING_NEXT_TURBOPACK_TARGETS[..],
&TRACING_TURBO_TASKS_TARGETS[..], &TRACING_TURBO_TASKS_TARGETS[..],
] ]
.concat() .concat()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment