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) {
auto_modularize_imports: None,
optimize_barrel_exports: None,
optimize_server_react: None,
prefer_esm: false,
};
let unresolved_mark = Mark::new();
......
......@@ -5,6 +5,7 @@ use next_api::{
route::{Endpoint, WrittenEndpoint},
server_paths::ServerPath,
};
use tracing::Instrument;
use turbo_tasks::Vc;
use turbopack_binding::turbopack::core::error::PrettyPrintError;
......@@ -114,16 +115,19 @@ pub fn endpoint_server_changed_subscribe(
subscribe(
turbo_tasks,
func,
move || async move {
let changed = endpoint.server_changed();
changed.strongly_consistent().await?;
if issues {
let issues = get_issues(changed).await?;
let diags = get_diagnostics(changed).await?;
Ok((issues, diags))
} else {
Ok((vec![], vec![]))
move || {
async move {
let changed = endpoint.server_changed();
changed.strongly_consistent().await?;
if issues {
let issues = get_issues(changed).await?;
let diags = get_diagnostics(changed).await?;
Ok((issues, diags))
} else {
Ok((vec![], vec![]))
}
}
.instrument(tracing::info_span!("server changes subscription"))
},
|ctx| {
let (issues, diags) = ctx.value;
......@@ -146,12 +150,15 @@ pub fn endpoint_client_changed_subscribe(
subscribe(
turbo_tasks,
func,
move || async move {
let changed = endpoint.client_changed();
// We don't capture issues and diagonistics here since we don't want to be
// notified when they change
changed.strongly_consistent().await?;
Ok(())
move || {
async move {
let changed = endpoint.client_changed();
// We don't capture issues and diagonistics here since we don't want to be
// notified when they change
changed.strongly_consistent().await?;
Ok(())
}
.instrument(tracing::info_span!("client changes subscription"))
},
|_| {
Ok(vec![TurbopackResult {
......
......@@ -14,8 +14,10 @@ use next_api::{
route::{Endpoint, Route},
};
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::{
prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry,
};
......@@ -36,7 +38,6 @@ use turbopack_binding::{
exit::ExitGuard,
raw_trace::RawTraceLayer,
trace_writer::{TraceWriter, TraceWriterGuard},
tracing_presets::TRACING_OVERVIEW_TARGETS,
},
},
};
......@@ -216,8 +217,8 @@ pub async fn project_new(
let guard = if let Some(mut trace) = trace {
// Trace presets
match trace.as_str() {
"overview" => {
trace = TRACING_OVERVIEW_TARGETS.join(",");
"overview" | "1" => {
trace = TRACING_NEXT_OVERVIEW_TARGETS.join(",");
}
"next" => {
trace = TRACING_NEXT_TARGETS.join(",");
......@@ -433,14 +434,17 @@ pub fn project_entrypoints_subscribe(
subscribe(
turbo_tasks.clone(),
func,
move || async move {
let entrypoints_operation = container.entrypoints();
let entrypoints = entrypoints_operation.strongly_consistent().await?;
move || {
async move {
let entrypoints_operation = container.entrypoints();
let entrypoints = entrypoints_operation.strongly_consistent().await?;
let issues = get_issues(entrypoints_operation).await?;
let diags = get_diagnostics(entrypoints_operation).await?;
let issues = get_issues(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| {
let (entrypoints, issues, diags) = ctx.value;
......@@ -500,10 +504,10 @@ pub fn project_hmr_events(
turbo_tasks.clone(),
func,
{
let identifier = identifier.clone();
let outer_identifier = identifier.clone();
let session = session.clone();
move || {
let identifier = identifier.clone();
let identifier = outer_identifier.clone();
let session = session.clone();
async move {
let state = project
......@@ -524,6 +528,10 @@ pub fn project_hmr_events(
}
Ok((update, issues, diags))
}
.instrument(tracing::info_span!(
"HMR subscription",
identifier = outer_identifier
))
}
},
move |ctx| {
......
......@@ -35,6 +35,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime},
};
use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc};
use turbopack_binding::{
turbo::{
......@@ -1084,37 +1085,61 @@ async fn concatenate_output_assets(
impl Endpoint for AppEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let output = self.output();
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let this = self.await?;
let node_root = this.app_project.project().node_root();
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();
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let node_root_ref = &node_root.await?;
let node_root = this.app_project.project().node_root();
let node_root = this.app_project.project().node_root();
this.app_project
.project()
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let node_root_ref = &node_root.await?;
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
let written_endpoint = match *output.await? {
AppEndpointOutput::NodeJs { rsc_chunk, .. } => WrittenEndpoint::NodeJs {
server_entry_path: node_root_ref
.get_path_to(&*rsc_chunk.ident().path().await?)
.context("Node.js chunk entry path must be inside the node root")?
.to_string(),
server_paths,
},
AppEndpointOutput::Edge { .. } => WrittenEndpoint::Edge { server_paths },
};
Ok(written_endpoint.cell())
let node_root = this.app_project.project().node_root();
this.app_project
.project()
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
let written_endpoint = match *output.await? {
AppEndpointOutput::NodeJs { rsc_chunk, .. } => WrittenEndpoint::NodeJs {
server_entry_path: node_root_ref
.get_path_to(&*rsc_chunk.ident().path().await?)
.context("Node.js chunk entry path must be inside the node root")?
.to_string(),
server_paths,
},
AppEndpointOutput::Edge { .. } => WrittenEndpoint::Edge { server_paths },
};
Ok(written_endpoint.cell())
}
.instrument(span)
.await
}
#[turbo_tasks::function]
......
......@@ -5,6 +5,7 @@ use next_core::{
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType},
};
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{
turbo::tasks_fs::{File, FileContent},
......@@ -171,18 +172,23 @@ impl InstrumentationEndpoint {
impl Endpoint for InstrumentationEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let output_assets = self.output_assets();
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let span = tracing::info_span!("instrumentation endpoint");
async move {
let this = self.await?;
let output_assets = self.output_assets();
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
Ok(WrittenEndpoint::Edge { server_paths }.cell())
Ok(WrittenEndpoint::Edge { server_paths }.cell())
}
.instrument(span)
.await
}
#[turbo_tasks::function]
......
......@@ -7,6 +7,7 @@ use next_core::{
next_server::{get_server_runtime_entries, ServerContextType},
util::parse_config_from_source,
};
use tracing::Instrument;
use turbo_tasks::{Completion, TryJoinIterExt, Value, Vc};
use turbopack_binding::{
turbo::tasks_fs::{File, FileContent},
......@@ -167,18 +168,23 @@ impl MiddlewareEndpoint {
impl Endpoint for MiddlewareEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let output_assets = self.output_assets();
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
let span = tracing::info_span!("middleware endpoint");
async move {
let this = self.await?;
let output_assets = self.output_assets();
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;
let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
Ok(WrittenEndpoint::Edge { server_paths }.cell())
Ok(WrittenEndpoint::Edge { server_paths }.cell())
}
.instrument(span)
.await
}
#[turbo_tasks::function]
......
......@@ -19,6 +19,7 @@ use next_core::{
next_telemetry::NextFeatureTelemetry,
};
use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{
debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal},
......@@ -787,19 +788,24 @@ impl Project {
self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>,
) -> Result<Vc<Completion>> {
let all_output_assets = all_assets_from_entries_operation(output_assets);
self.await?
.versioned_content_map
.insert_output_assets(all_output_assets)
.await?;
Ok(emit_assets(
*all_output_assets.await?,
self.node_root(),
self.client_relative_path(),
self.node_root(),
))
let span = tracing::info_span!("emitting");
async move {
let all_output_assets = all_assets_from_entries_operation(output_assets);
self.await?
.versioned_content_map
.insert_output_assets(all_output_assets)
.await?;
Ok(emit_assets(
*all_output_assets.await?,
self.node_root(),
self.client_relative_path(),
self.node_root(),
))
}
.instrument(span)
.await
}
#[turbo_tasks::function]
......
......@@ -7,6 +7,7 @@ use next_core::{
util::{get_asset_prefix_from_pathname, NextRuntime},
};
use next_swc::server_actions::parse_server_actions;
use tracing::Instrument;
use turbo_tasks::{
graph::{GraphTraversal, NonDeterministic},
TryFlatJoinIterExt, Value, ValueToString, Vc,
......@@ -174,52 +175,56 @@ async fn get_actions(
server_reference_modules: Vc<Vec<Vc<Box<dyn Module>>>>,
asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<Vc<AllActions>> {
let actions = NonDeterministic::new()
.skip_duplicates()
.visit(
once((ActionLayer::Rsc, rsc_entry)).chain(
server_reference_modules
.await?
.iter()
.map(|m| (ActionLayer::ActionBrowser, *m)),
),
get_referenced_modules,
)
.await
.completed()?
.into_inner()
.into_iter()
.map(parse_actions_filter_map)
.try_flat_join()
.await?;
async move {
let actions = NonDeterministic::new()
.skip_duplicates()
.visit(
once((ActionLayer::Rsc, rsc_entry)).chain(
server_reference_modules
.await?
.iter()
.map(|m| (ActionLayer::ActionBrowser, *m)),
),
get_referenced_modules,
)
.await
.completed()?
.into_inner()
.into_iter()
.map(parse_actions_filter_map)
.try_flat_join()
.await?;
// Actions can be imported by both Client and RSC layers, in which case we need
// to use the RSC layer's module. We do that by merging the hashes (which match
// in both layers) and preferring the RSC layer's action.
let mut all_actions: HashToLayerNameModule = IndexMap::new();
for ((layer, module), actions_map) in actions.iter() {
let module = if *layer == ActionLayer::Rsc {
*module
} else {
to_rsc_context(*module, asset_context).await?
};
// Actions can be imported by both Client and RSC layers, in which case we need
// to use the RSC layer's module. We do that by merging the hashes (which match
// in both layers) and preferring the RSC layer's action.
let mut all_actions: HashToLayerNameModule = IndexMap::new();
for ((layer, module), actions_map) in actions.iter() {
let module = if *layer == ActionLayer::Rsc {
*module
} else {
to_rsc_context(*module, asset_context).await?
};
for (hash_id, name) in &*actions_map.await? {
match all_actions.entry(hash_id.to_owned()) {
Entry::Occupied(e) => {
if e.get().0 == ActionLayer::ActionBrowser {
*e.into_mut() = (*layer, name.to_string(), module);
for (hash_id, name) in &*actions_map.await? {
match all_actions.entry(hash_id.to_owned()) {
Entry::Occupied(e) => {
if e.get().0 == ActionLayer::ActionBrowser {
*e.into_mut() = (*layer, name.to_string(), module);
}
}
Entry::Vacant(e) => {
e.insert((*layer, name.to_string(), module));
}
}
Entry::Vacant(e) => {
e.insert((*layer, name.to_string(), module));
}
}
}
}
all_actions.sort_keys();
Ok(Vc::cell(all_actions))
all_actions.sort_keys();
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
......
......@@ -7,6 +7,7 @@ use indexmap::{
IndexMap,
};
use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, Completions, TaskInput, ValueToString,
Vc,
......@@ -280,6 +281,19 @@ pub async fn find_app_dir_if_enabled(project_path: Vc<FileSystemPath>) -> Result
async fn get_directory_tree(
dir: Vc<FileSystemPath>,
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>> {
let DirectoryContent::Entries(entries) = &*dir.read_dir().await? else {
bail!("{} must be a directory", dir.to_string().await?);
......@@ -297,6 +311,7 @@ async fn get_directory_tree(
for (basename, entry) in entries {
match *entry {
DirectoryEntry::File(file) => {
let file = file.resolve().await?;
if let Some((stem, ext)) = basename.split_once('.') {
if page_extensions_value.iter().any(|e| e == ext) {
match stem {
......@@ -362,6 +377,7 @@ async fn get_directory_tree(
));
}
DirectoryEntry::Directory(dir) => {
let dir = dir.resolve().await?;
// appDir ignores paths starting with an underscore
if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions);
......@@ -864,6 +880,25 @@ async fn directory_tree_to_entrypoints_internal(
directory_name: String,
directory_tree: Vc<DirectoryTree>,
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>> {
let mut result = IndexMap::new();
......@@ -954,26 +989,26 @@ async fn directory_tree_to_entrypoints_internal(
// is considered as its own entry point.
if let Some(_not_found) = components.not_found {
let dev_not_found_tree = LoaderTree {
page: app_page.clone(),
segment: directory_name.clone(),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
page: app_page.clone(),
segment: "__DEFAULT__".to_string(),
parallel_routes: IndexMap::new(),
components: Components {
default: Some(get_next_package(app_dir).join("dist/client/components/parallel-route-default.js".to_string())),
..Default::default()
page: app_page.clone(),
segment: directory_name.clone(),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
page: app_page.clone(),
segment: "__DEFAULT__".to_string(),
parallel_routes: IndexMap::new(),
components: Components {
default: Some(get_next_package(app_dir).join("dist/client/components/parallel-route-default.js".to_string())),
..Default::default()
}
.cell(),
global_metadata,
}
.cell(),
global_metadata,
}
.cell(),
},
components: components.without_leafs().cell(),
global_metadata,
}
.cell();
},
components: components.without_leafs().cell(),
global_metadata,
}
.cell();
{
let app_page = app_page.clone_push_str("not-found")?;
......@@ -987,26 +1022,26 @@ async fn directory_tree_to_entrypoints_internal(
// Create default not-found page for production if there's no customized
// not-found
let prod_not_found_tree = LoaderTree {
page: app_page.clone(),
segment: directory_name.to_string(),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
page: app_page.clone(),
segment: "__PAGE__".to_string(),
parallel_routes: IndexMap::new(),
components: Components {
page: Some(get_next_package(app_dir).join("dist/client/components/not-found-error.js".to_string())),
..Default::default()
page: app_page.clone(),
segment: directory_name.to_string(),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
page: app_page.clone(),
segment: "__PAGE__".to_string(),
parallel_routes: IndexMap::new(),
components: Components {
page: Some(get_next_package(app_dir).join("dist/client/components/not-found-error.js".to_string())),
..Default::default()
}
.cell(),
global_metadata,
}
.cell(),
global_metadata,
}
.cell(),
},
components: components.without_leafs().cell(),
global_metadata,
}
.cell();
},
components: components.without_leafs().cell(),
global_metadata,
}
.cell();
let app_page = app_page.clone_push_str("_not-found")?;
add_app_page(app_dir, &mut result, app_page, prod_not_found_tree).await?;
......
use anyhow::Result;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc,
};
......@@ -35,42 +36,49 @@ pub async fn get_app_client_references_chunks(
client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
) -> Result<Vc<ClientReferencesChunks>> {
let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types
.await?
.iter()
.map(|client_reference_ty| async move {
Ok((
*client_reference_ty,
match client_reference_ty {
ClientReferenceType::EcmascriptClientReference(ecmascript_client_reference) => {
let ecmascript_client_reference_ref = ecmascript_client_reference.await?;
ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast(
ecmascript_client_reference_ref.client_module,
)),
ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast(
ecmascript_client_reference_ref.ssr_module,
)),
async move {
let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types
.await?
.iter()
.map(|client_reference_ty| async move {
Ok((
*client_reference_ty,
match client_reference_ty {
ClientReferenceType::EcmascriptClientReference(
ecmascript_client_reference,
) => {
let ecmascript_client_reference_ref =
ecmascript_client_reference.await?;
ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(
Vc::upcast(ecmascript_client_reference_ref.client_module),
),
ssr_chunks: ssr_chunking_context.root_chunk_group(Vc::upcast(
ecmascript_client_reference_ref.ssr_module,
)),
}
}
}
ClientReferenceType::CssClientReference(css_client_reference) => {
let css_client_reference_ref = css_client_reference.await?;
ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(Vc::upcast(
css_client_reference_ref.client_module,
)),
ssr_chunks: OutputAssets::empty(),
ClientReferenceType::CssClientReference(css_client_reference) => {
let css_client_reference_ref = css_client_reference.await?;
ClientReferenceChunks {
client_chunks: client_chunking_context.root_chunk_group(
Vc::upcast(css_client_reference_ref.client_module),
),
ssr_chunks: OutputAssets::empty(),
}
}
}
},
))
})
.try_join()
.await?
.into_iter()
.collect();
},
))
})
.try_join()
.await?
.into_iter()
.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
......
......@@ -3,6 +3,7 @@ use std::future::Future;
use anyhow::Result;
use indexmap::IndexSet;
use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{
debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
......@@ -61,26 +62,30 @@ pub struct ClientReferenceGraph {
impl ClientReferenceGraph {
#[turbo_tasks::function]
pub async fn new(entries: Vc<Modules>) -> Result<Vc<Self>> {
let entries = entries.await?;
let graph = AdjacencyMap::new()
.skip_duplicates()
.visit(
entries
.iter()
.copied()
.map(|module| VisitClientReferenceNode {
server_component: None,
ty: VisitClientReferenceNodeType::Internal(module),
})
.collect::<Vec<_>>(),
VisitClientReference,
)
.await
.completed()?
.into_inner();
Ok(ClientReferenceGraph { graph }.cell())
async move {
let entries = entries.await?;
let graph = AdjacencyMap::new()
.skip_duplicates()
.visit(
entries
.iter()
.copied()
.map(|module| VisitClientReferenceNode {
server_component: None,
ty: VisitClientReferenceNodeType::Internal(module),
})
.collect::<Vec<_>>(),
VisitClientReference,
)
.await
.completed()?
.into_inner();
Ok(ClientReferenceGraph { graph }.cell())
}
.instrument(tracing::info_span!("find client references"))
.await
}
#[turbo_tasks::function]
......
use std::future::Future;
use anyhow::Result;
use tracing::Instrument;
use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
TryJoinIterExt, Vc,
......@@ -19,38 +20,42 @@ pub struct NextDynamicEntries(Vec<Vc<NextDynamicEntryModule>>);
impl NextDynamicEntries {
#[turbo_tasks::function]
pub async fn from_entries(entries: Vc<Modules>) -> Result<Vc<NextDynamicEntries>> {
let nodes: Vec<_> = AdjacencyMap::new()
.skip_duplicates()
.visit(
entries
.await?
.iter()
.copied()
.map(VisitDynamicNode::Internal)
.collect::<Vec<_>>(),
VisitDynamic,
)
.await
.completed()?
.into_inner()
.into_reverse_topological()
.collect();
let mut next_dynamics = vec![];
for node in nodes {
match node {
VisitDynamicNode::Internal(_asset) => {
// No-op. These nodes are only useful during graph
// traversal.
}
VisitDynamicNode::Dynamic(dynamic_asset) => {
next_dynamics.push(dynamic_asset);
async move {
let nodes: Vec<_> = AdjacencyMap::new()
.skip_duplicates()
.visit(
entries
.await?
.iter()
.copied()
.map(VisitDynamicNode::Internal)
.collect::<Vec<_>>(),
VisitDynamic,
)
.await
.completed()?
.into_inner()
.into_reverse_topological()
.collect();
let mut next_dynamics = vec![];
for node in nodes {
match node {
VisitDynamicNode::Internal(_asset) => {
// No-op. These nodes are only useful during graph
// traversal.
}
VisitDynamicNode::Dynamic(dynamic_asset) => {
next_dynamics.push(dynamic_asset);
}
}
}
}
Ok(Vc::cell(next_dynamics))
Ok(Vc::cell(next_dynamics))
}
.instrument(tracing::info_span!("find next/dynamic references"))
.await
}
}
......
use anyhow::Result;
use turbo_tasks::{Completion, Vc};
use tracing::Instrument;
use turbo_tasks::{Completion, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPathOption;
use turbopack_binding::turbo::tasks_fs::{
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
......@@ -319,61 +320,69 @@ async fn get_pages_structure_for_directory(
position: u32,
page_extensions: Vc<Vec<String>>,
) -> Result<Vc<PagesDirectoryStructure>> {
let page_extensions_raw = &*page_extensions.await?;
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 mut children = vec![];
let mut items = vec![];
let dir_content = project_path.read_dir().await?;
if let DirectoryContent::Entries(entries) = &*dir_content {
for (name, entry) in entries.iter() {
match entry {
DirectoryEntry::File(file_project_path) => {
let Some(basename) = page_basename(name, page_extensions_raw) else {
continue;
};
let item_next_router_path = match basename {
"index" => next_router_path,
_ => next_router_path.join(basename.to_string()),
};
let item_original_name = next_router_path.join(basename.to_string());
items.push((
basename,
PagesStructureItem::new(
*file_project_path,
item_next_router_path,
item_original_name,
),
));
}
DirectoryEntry::Directory(dir_project_path) => {
children.push((
name,
get_pages_structure_for_directory(
*dir_project_path,
next_router_path.join(name.clone()),
position + 1,
page_extensions,
),
));
let mut children = vec![];
let mut items = vec![];
let dir_content = project_path.read_dir().await?;
if let DirectoryContent::Entries(entries) = &*dir_content {
for (name, entry) in entries.iter() {
match entry {
DirectoryEntry::File(file_project_path) => {
let Some(basename) = page_basename(name, page_extensions_raw) else {
continue;
};
let item_next_router_path = match basename {
"index" => next_router_path,
_ => next_router_path.join(basename.to_string()),
};
let item_original_name = next_router_path.join(basename.to_string());
items.push((
basename,
PagesStructureItem::new(
*file_project_path,
item_next_router_path,
item_original_name,
),
));
}
DirectoryEntry::Directory(dir_project_path) => {
children.push((
name,
get_pages_structure_for_directory(
*dir_project_path,
next_router_path.join(name.clone()),
position + 1,
page_extensions,
),
));
}
_ => {}
}
_ => {}
}
}
}
// Ensure deterministic order since read_dir is not deterministic
items.sort_by_key(|(k, _)| *k);
// Ensure deterministic order since read_dir is not deterministic
items.sort_by_key(|(k, _)| *k);
// Ensure deterministic order since read_dir is not deterministic
children.sort_by_key(|(k, _)| *k);
// Ensure deterministic order since read_dir is not deterministic
children.sort_by_key(|(k, _)| *k);
Ok(PagesDirectoryStructure {
project_path,
next_router_path,
items: items.into_iter().map(|(_, v)| v).collect(),
children: children.into_iter().map(|(_, v)| v).collect(),
Ok(PagesDirectoryStructure {
project_path,
next_router_path,
items: items.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> {
......
......@@ -3,14 +3,32 @@ use turbopack_binding::turbopack::trace_utils::tracing_presets::{
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[..],
&[
"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_core=trace",
"next_font=trace",
"turbopack_node=trace",
],
]
.concat()
......@@ -19,7 +37,7 @@ pub static TRACING_NEXT_TURBOPACK_TARGETS: Lazy<Vec<&str>> =
Lazy::new(|| [&TRACING_NEXT_TARGETS[..], &TRACING_TURBOPACK_TARGETS[..]].concat());
pub static TRACING_NEXT_TURBO_TASKS_TARGETS: Lazy<Vec<&str>> = Lazy::new(|| {
[
&TRACING_TURBOPACK_TARGETS[..],
&TRACING_NEXT_TURBOPACK_TARGETS[..],
&TRACING_TURBO_TASKS_TARGETS[..],
]
.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