From a08f49f43ee48b8c3de3b7fc302c563e023fb9c5 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 21 Jan 2025 00:10:20 +0100 Subject: [PATCH] DNM: add taskdump --- .cargo/config.toml | 2 +- pageserver/src/http/routes.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index c71d491303..368093e552 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -11,7 +11,7 @@ rustdocflags = ["-Arustdoc::private_intra_doc_links"] # * # # NB: the RUSTFLAGS envvar will replace this. Make sure to update e.g. Dockerfile as well. -rustflags = ["-Cforce-frame-pointers=yes"] +rustflags = ["-Cforce-frame-pointers=yes", "--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"] [alias] build_testing = ["build", "--features", "testing"] diff --git a/pageserver/src/http/routes.rs b/pageserver/src/http/routes.rs index 33b2d04588..9ea3adbe2a 100644 --- a/pageserver/src/http/routes.rs +++ b/pageserver/src/http/routes.rs @@ -2923,6 +2923,33 @@ async fn get_utilization( .map_err(ApiError::InternalServerError) } +async fn get_taskdump( + request: Request, + _cancel: CancellationToken, +) -> Result, ApiError> { + check_permission(&request, None)?; + + use std::io::Write; + use tokio::runtime::Handle; + + let out = async { + let mut out = Vec::new(); + // Inside an async block or function. + let handle = Handle::current(); + let dump = handle.dump().await; + for (i, task) in dump.tasks().iter().enumerate() { + let trace = task.trace(); + writeln!(out, "TASK {i}:")?; + writeln!(out, "{trace}\n")?; + } + Ok(String::from_utf8(out).unwrap()) + } + .await + .map_err(|e: anyhow::Error| ApiError::InternalServerError(e))?; + + json_response(StatusCode::OK, out) +} + async fn list_aux_files( mut request: Request, _cancel: CancellationToken, @@ -3608,5 +3635,9 @@ pub fn make_router( "/v1/tenant/:tenant_id/timeline/:timeline_id/import_wal", |r| api_handler(r, put_tenant_timeline_import_wal), ) + .get( + "/debug/taskdump", + |r| api_handler(r, get_taskdump), + ) .any(handler_404)) }