-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial tracing implementation (vercel/turborepo#4966)
### Description * adds a raw_trace subscriber that will emit the raw trace events into `.turbopack/trace.log` (resp. `.next/trace.log` for next.js) * adds a CLI script which converts the raw trace into a chrome trace json file -> https://ui.perfetto.dev/ * adds a `TURBOPACK_TRACING` (resp. `NEXT_TURBOPACK_TRACING`) env var to enable tracing * adds some presets e. g. `turbopack` or `next` to enable tracing for certain things. * add tracing for invalidations There are three different visualization modes: #### `--single` Shows all cpu time as it would look like when a single cpu would execute the workload. (10 concurrent tasks that take 1s are shown as 10 tasks that take 1s with total time of 10s) Pro: * Concurrency is visualized by bar filling (dark filled bars -> too few concurrency) * It injects pseudo bars with "cpus idle" for low concurrency (with `--idle`) Con: * Total time won't be represented correctly, since a single CPU would take longer Use Case: Gives a good overview of slow tasks in a build. #### `--merged` Shows all cpu time scaled by the concurrency. (10 concurrent tasks that take 1s are shown as 10 tasks that take 0.1s with total time of 1s) Pro: * Total time is represented correctly * Low concurrent tasks are bigger * Concurrency is visualized by bar filling (dark filled bars -> too few concurrency) * It injects pseudo bars with "cpus idle" for low concurrency (with `--idle`) Con: * Individual tasks time won't be represented correctly. Use Case: Gives a good overview why a build is slow overall. #### `--threads` Shows cpu time distributed on infinite virtual cpus/threads. (10 concurrent tasks that take 1s are shown as 10 concurrent tasks that take 1s with total time of 1s) Pro: * Concurrency is shown via multiple CPU * Most realistic visualization Con: * Hard to read
- Loading branch information
Showing
41 changed files
with
1,468 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::time::Instant; | ||
|
||
/// Guard that emits a tracing event when dropped with the duration of the | ||
/// lifetime of the guard. | ||
pub struct DurationSpanGuard<F: FnOnce(u64)> { | ||
start: Instant, | ||
f: Option<F>, | ||
} | ||
|
||
impl<F: FnOnce(u64)> DurationSpanGuard<F> { | ||
pub fn new(f: F) -> Self { | ||
Self { | ||
start: Instant::now(), | ||
f: Some(f), | ||
} | ||
} | ||
} | ||
|
||
impl<F: FnOnce(u64)> Drop for DurationSpanGuard<F> { | ||
fn drop(&mut self) { | ||
if let Some(f) = self.f.take() { | ||
f(self.start.elapsed().as_micros() as u64); | ||
} | ||
} | ||
} | ||
|
||
/// Creates a event-based span that traces a certain duration (lifetime of the | ||
/// guard). It's not a real span, which means it can be used across threads. It | ||
/// will trace a duration and not the time the cpu is doing actual work. This | ||
/// way it can be used to trace non-cpu-time or time that is spend in other | ||
/// processes. | ||
#[macro_export] | ||
macro_rules! duration_span { | ||
($name:literal) => { | ||
turbo_tasks::duration_span::DurationSpanGuard::new(|duration| { | ||
turbo_tasks::macro_helpers::tracing::info!(name = $name, duration = duration); | ||
}) | ||
}; | ||
($name:literal, $($arg:tt)+) => { | ||
turbo_tasks::duration_span::DurationSpanGuard::new(|duration| { | ||
turbo_tasks::macro_helpers::tracing::info!(name = $name, $($arg)+, duration = duration); | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.