Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNM: add tokio taskdump support #10458

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rustdocflags = ["-Arustdoc::private_intra_doc_links"]
# * <https://github.com/rust-lang/rust/pull/122646>
#
# 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"]
Expand Down
31 changes: 31 additions & 0 deletions pageserver/src/http/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,33 @@ async fn get_utilization(
.map_err(ApiError::InternalServerError)
}

async fn get_taskdump(
request: Request<Body>,
_cancel: CancellationToken,
) -> Result<Response<Body>, 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<Body>,
_cancel: CancellationToken,
Expand Down Expand Up @@ -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))
}
Loading