Skip to content

Commit 7c1437d

Browse files
committed
Added sending events to log how long writing entrypoints to disk takes.
1 parent 3fc7d17 commit 7c1437d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

crates/napi/src/next_api/project.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,14 @@ pub async fn project_write_all_entrypoints_to_disk(
831831
app_dir_only: bool,
832832
) -> napi::Result<TurbopackResult<NapiEntrypoints>> {
833833
let turbo_tasks = project.turbo_tasks.clone();
834+
let compilation_event_sender = turbo_tasks.clone();
835+
834836
let (entrypoints, issues, diags) = turbo_tasks
835837
.run_once(async move {
836838
let entrypoints_with_issues_op =
837839
get_all_written_entrypoints_with_issues_operation(project.container, app_dir_only);
838840

841+
// Read and compile the files
839842
let EntrypointsWithIssues {
840843
entrypoints,
841844
issues,
@@ -844,8 +847,26 @@ pub async fn project_write_all_entrypoints_to_disk(
844847
} = &*entrypoints_with_issues_op
845848
.read_strongly_consistent()
846849
.await?;
850+
851+
// Start timing writing the files to disk
852+
let now = Instant::now();
853+
compilation_event_sender.send_compilation_event(Arc::new(DiagnosticEvent::new(
854+
"Starting to write all entrypoints to disk...".to_owned(),
855+
Severity::Event,
856+
)));
857+
858+
// Write the files to disk
847859
effects.apply().await?;
848860

861+
// Send a compilation event to indicate that the files have been written to disk
862+
compilation_event_sender.send_compilation_event(Arc::new(DiagnosticEvent::new(
863+
format!(
864+
"Finished writing all entrypoints to disk in {:?}",
865+
now.elapsed()
866+
),
867+
Severity::Event,
868+
)));
869+
849870
Ok((entrypoints.clone(), issues.clone(), diagnostics.clone()))
850871
})
851872
.await

packages/next/src/build/turbopack-build/impl.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import loadConfig from '../../server/config'
1919
import { hasCustomExportOutput } from '../../export/utils'
2020
import { Telemetry } from '../../telemetry/storage'
2121
import { setGlobal } from '../../trace'
22+
import * as Log from '../output/log'
2223

2324
export async function turbopackBuild(): Promise<{
2425
duration: number
@@ -87,6 +88,14 @@ export async function turbopackBuild(): Promise<{
8788
}
8889
)
8990
try {
91+
;(async function logCompilationEvents() {
92+
for await (const event of project.compilationEventsSubscribe()) {
93+
if (event.severity === 'EVENT') {
94+
Log.event(event.message)
95+
}
96+
}
97+
})()
98+
9099
// Write an empty file in a known location to signal this was built with Turbopack
91100
await fs.writeFile(path.join(distDir, 'turbopack'), '')
92101

turbopack/crates/turbo-tasks/src/message_queue.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type CompilationEventChannel = mpsc::Sender<Arc<dyn CompilationEvent>>;
1717

1818
pub struct CompilationEventQueue {
1919
event_history: ArcMx<VecDeque<Arc<dyn CompilationEvent>>>,
20-
subscribers: DashMap<String, Vec<CompilationEventChannel>>,
20+
subscribers: Arc<DashMap<String, Vec<CompilationEventChannel>>>,
2121
}
2222

2323
impl Default for CompilationEventQueue {
@@ -27,7 +27,7 @@ impl Default for CompilationEventQueue {
2727

2828
Self {
2929
event_history: Arc::new(Mutex::new(VecDeque::with_capacity(MAX_QUEUE_SIZE))),
30-
subscribers,
30+
subscribers: Arc::new(subscribers),
3131
}
3232
}
3333
}
@@ -125,6 +125,7 @@ pub enum Severity {
125125
Warning,
126126
Error,
127127
Fatal,
128+
Event,
128129
}
129130

130131
impl Display for Severity {
@@ -135,6 +136,7 @@ impl Display for Severity {
135136
Severity::Warning => write!(f, "WARNING"),
136137
Severity::Error => write!(f, "ERROR"),
137138
Severity::Fatal => write!(f, "FATAL"),
139+
Severity::Event => write!(f, "EVENT"),
138140
}
139141
}
140142
}

0 commit comments

Comments
 (0)