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

Support an API to extract backtrace information from taskdump #6309

Open
mox692 opened this issue Jan 26, 2024 · 3 comments
Open

Support an API to extract backtrace information from taskdump #6309

mox692 opened this issue Jan 26, 2024 · 3 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-taskdump --cfg tokio_taskdump

Comments

@mox692
Copy link
Member

mox692 commented Jan 26, 2024

Is your feature request related to a problem? Please describe.
Currently, the only supported output for taskdump is logging, as shown in the examples here. However, I would like to add a public API that can extract this backtrace information. By adding such an API, it will become possible to handle taskdump data programmatically, making it useful for various purposes.

Describe the solution you'd like
I would like to add a public API something like this:

struct Symbol {
  // one call stack info
}

pub struct TraceTree {
  symbol: Symbol,
  children: Vec<TraceTree>
}

impl Task {
  pub fn trace_tree(&self) -> TraceTree { ... }
}

async fn run {
  let handle = tokio::runtime::Handle::current();
  let dump = handle.dump().await;
  for task in dump.tasks().iter() {
    // get a trace tree per one tokio task.
    let root: TraceTree = task.trace_tree();
		
    // some traverse operations...
  }
}

We already have an internal struct named Tree, so I believe it's not too hard to provide such an API.

Additional context
related issue: #5638

@mox692 mox692 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jan 26, 2024
@Darksonn Darksonn added the M-taskdump --cfg tokio_taskdump label Jan 26, 2024
@Darksonn
Copy link
Contributor

cc @jswrenn

@jswrenn
Copy link
Contributor

jswrenn commented Jan 30, 2024

It's not hard to provide an API here, but it might be hard to provide the right API. The current Tree type is an implementation detail used to aid printing task dumps. It's not currently designed to function well as a public API for traversing the tracing tree. Rust doesn't have a standard interface for tree traversal, so we'll need to decide for ourselves what interface to expose. We'll also need to ensure that this API doesn't lock us into sub-optimal representation decisions.

@mox692
Copy link
Member Author

mox692 commented Feb 1, 2024

Thanks for clarifying the context!
Yeah, deciding on the right api seems difficult, but I believe we should eventually reach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-taskdump --cfg tokio_taskdump
Projects
None yet
Development

No branches or pull requests

3 participants