Unverified Commit 5de932a4 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

feat(turbopack): Add a compile-time feature to turbopack to enable tokio-console support (#74675)

I'm trying to use this to debug a hang in turbo-tasks. There's some overlap with https://turbo-trace-viewer.vercel.app/, but this is more realtime, which is useful for finding hanging futures.

There's some similar functionality in turbopack-cli: https://github.com/vercel/next.js/blob/c51b53680de4b1c00cd66bb00b7ff6b878646583/turbopack/crates/turbopack-cli/src/dev/mod.rs#L349

Enable this by building with `--features next-swc-napi/tokio-console`.
parent 641612e4
......@@ -616,18 +616,17 @@ dependencies = [
[[package]]
name = "axum"
version = "0.6.20"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf"
dependencies = [
"async-trait",
"axum-core",
"bitflags 1.3.2",
"bytes",
"futures-util",
"http 0.2.11",
"http-body",
"hyper",
"http 1.1.0",
"http-body 1.0.1",
"http-body-util",
"itoa",
"matchit",
"memchr",
......@@ -644,17 +643,20 @@ dependencies = [
[[package]]
name = "axum-core"
version = "0.3.4"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http 0.2.11",
"http-body",
"http 1.1.0",
"http-body 1.0.1",
"http-body-util",
"mime",
"pin-project-lite",
"rustversion",
"sync_wrapper",
"tower-layer",
"tower-service",
]
......@@ -728,7 +730,7 @@ dependencies = [
"bitflags 2.5.0",
"cexpr",
"clang-sys",
"itertools 0.10.5",
"itertools 0.13.0",
"log",
"prettyplease",
"proc-macro2",
......@@ -1296,10 +1298,11 @@ dependencies = [
[[package]]
name = "console-api"
version = "0.5.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2895653b4d9f1538a83970077cb01dfc77a4810524e51a110944688e916b18e"
checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857"
dependencies = [
"futures-core",
"prost",
"prost-types",
"tonic",
......@@ -1308,16 +1311,18 @@ dependencies = [
[[package]]
name = "console-subscriber"
version = "0.1.10"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4cf42660ac07fcebed809cfe561dd8730bcd35b075215e6479c516bcd0d11cb"
checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01"
dependencies = [
"console-api",
"crossbeam-channel",
"crossbeam-utils",
"futures",
"futures-task",
"hdrhistogram",
"humantime",
"hyper-util",
"prost",
"prost-types",
"serde",
"serde_json",
......@@ -2673,6 +2678,25 @@ dependencies = [
"tracing",
]
[[package]]
name = "h2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e"
dependencies = [
"atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"http 1.1.0",
"indexmap 2.5.0",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "half"
version = "2.4.1"
......@@ -2856,6 +2880,29 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-body"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
dependencies = [
"bytes",
"http 1.1.0",
]
[[package]]
name = "http-body-util"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
dependencies = [
"bytes",
"futures-util",
"http 1.1.0",
"http-body 1.0.1",
"pin-project-lite",
]
[[package]]
name = "httparse"
version = "1.8.0"
......@@ -2881,7 +2928,7 @@ dependencies = [
"crossbeam-utils",
"form_urlencoded",
"futures-util",
"hyper",
"hyper 0.14.28",
"isahc",
"lazy_static",
"levenshtein",
......@@ -2911,20 +2958,41 @@ dependencies = [
"futures-channel",
"futures-core",
"futures-util",
"h2",
"h2 0.3.24",
"http 0.2.11",
"http-body",
"http-body 0.4.5",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.4.9",
"socket2 0.5.8",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"h2 0.4.7",
"http 1.1.0",
"http-body 1.0.1",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"smallvec",
"tokio",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.23.2"
......@@ -2932,7 +3000,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
dependencies = [
"http 0.2.11",
"hyper",
"hyper 0.14.28",
"rustls 0.20.9",
"tokio",
"tokio-rustls",
......@@ -2940,14 +3008,15 @@ dependencies = [
[[package]]
name = "hyper-timeout"
version = "0.4.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1"
checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0"
dependencies = [
"hyper",
"hyper 1.5.2",
"hyper-util",
"pin-project-lite",
"tokio",
"tokio-io-timeout",
"tower-service",
]
[[package]]
......@@ -2957,7 +3026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes",
"hyper",
"hyper 0.14.28",
"native-tls",
"tokio",
"tokio-native-tls",
......@@ -2969,13 +3038,32 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "880b8b1c98a5ec2a505c7c90db6d3f6f1f480af5655d9c5b55facc9382a5a5b5"
dependencies = [
"hyper",
"hyper 0.14.28",
"pin-project",
"tokio",
"tokio-tungstenite",
"tungstenite 0.18.0",
]
[[package]]
name = "hyper-util"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http 1.1.0",
"http-body 1.0.1",
"hyper 1.5.2",
"pin-project-lite",
"socket2 0.5.8",
"tokio",
"tower-service",
"tracing",
]
[[package]]
name = "iana-time-zone"
version = "0.1.57"
......@@ -4472,6 +4560,7 @@ version = "0.0.0"
dependencies = [
"anyhow",
"backtrace",
"console-subscriber",
"dhat",
"fxhash",
"getrandom",
......@@ -5367,9 +5456,9 @@ dependencies = [
[[package]]
name = "prost"
version = "0.11.9"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd"
checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec"
dependencies = [
"bytes",
"prost-derive",
......@@ -5377,22 +5466,22 @@ dependencies = [
[[package]]
name = "prost-derive"
version = "0.11.9"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4"
checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.13.0",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.95",
]
[[package]]
name = "prost-types"
version = "0.11.9"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13"
checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc"
dependencies = [
"prost",
]
......@@ -5797,10 +5886,10 @@ dependencies = [
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"h2 0.3.24",
"http 0.2.11",
"http-body",
"hyper",
"http-body 0.4.5",
"hyper 0.14.28",
"hyper-rustls",
"hyper-tls",
"ipnet",
......@@ -8226,9 +8315,9 @@ dependencies = [
[[package]]
name = "sync_wrapper"
version = "0.1.2"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
name = "synstructure"
......@@ -8524,16 +8613,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-io-timeout"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf"
dependencies = [
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-macros"
version = "2.4.0"
......@@ -8578,9 +8657,9 @@ dependencies = [
[[package]]
name = "tokio-stream"
version = "0.1.15"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047"
dependencies = [
"futures-core",
"pin-project-lite",
......@@ -8685,24 +8764,26 @@ dependencies = [
[[package]]
name = "tonic"
version = "0.9.2"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a"
checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52"
dependencies = [
"async-stream",
"async-trait",
"axum",
"base64 0.21.4",
"base64 0.22.1",
"bytes",
"futures-core",
"futures-util",
"h2",
"http 0.2.11",
"http-body",
"hyper",
"h2 0.4.7",
"http 1.1.0",
"http-body 1.0.1",
"http-body-util",
"hyper 1.5.2",
"hyper-timeout",
"hyper-util",
"percent-encoding",
"pin-project",
"prost",
"socket2 0.5.8",
"tokio",
"tokio-stream",
"tower",
......@@ -9483,7 +9564,7 @@ dependencies = [
"async-compression",
"auto-hash-map",
"futures",
"hyper",
"hyper 0.14.28",
"hyper-tungstenite",
"indexmap 2.5.0",
"mime",
......
......@@ -132,7 +132,7 @@ chrono = "0.4.23"
clap = { version = "4.5.2", features = ["derive"] }
concurrent-queue = "2.5.0"
console = "0.15.5"
console-subscriber = "0.1.8"
console-subscriber = "0.4.1"
criterion = "0.5.1"
crossbeam-channel = "0.5.8"
dashmap = "6.1.0"
......
......@@ -37,12 +37,16 @@ __internal_dhat-heap = ["dhat"]
# effectively does nothing.
__internal_dhat-ad-hoc = ["dhat"]
# Enable support for the tokio console: https://github.com/tokio-rs/console
tokio-console = ["dep:console-subscriber"]
[lints]
workspace = true
[dependencies]
anyhow = "1.0.66"
backtrace = "0.3"
console-subscriber = { workspace = true, optional = true }
fxhash = "0.2.1"
dhat = { workspace = true, optional = true }
indexmap = { workspace = true }
......
......@@ -296,10 +296,18 @@ pub async fn project_new(
) -> napi::Result<External<ProjectInstance>> {
register();
let trace = std::env::var("NEXT_TURBOPACK_TRACING").ok();
let mut trace = std::env::var("NEXT_TURBOPACK_TRACING")
.ok()
.filter(|v| !v.is_empty());
let (exit, exit_receiver) = ExitHandler::new_receiver();
if let Some(mut trace) = trace.filter(|v| !v.is_empty()) {
if cfg!(feature = "tokio-console") && trace.is_none() {
// ensure `trace` is set to *something* so that the `tokio-console` feature works, otherwise
// you just get empty output from `tokio-console`, which can be confusing.
trace = Some("overview".to_owned());
}
if let Some(mut trace) = trace {
// Trace presets
match trace.as_str() {
"overview" | "1" => {
......@@ -319,6 +327,12 @@ pub async fn project_new(
let subscriber = Registry::default();
if cfg!(feature = "tokio-console") {
trace = format!("{trace},tokio=trace,runtime=trace");
}
#[cfg(feature = "tokio-console")]
let subscriber = subscriber.with(console_subscriber::spawn());
let subscriber = subscriber.with(FilterLayer::try_new(&trace).unwrap());
let dist_dir = options.dist_dir.clone();
......
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