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

allow getting task dump backtraces in a programmatic format #6975

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arielb1
Copy link

@arielb1 arielb1 commented Nov 14, 2024

This PR creates structs that allow dumping backtraces in a programmatic format, for example JSON. A JSON serializer is not natively included to avoid creating a Tokio dependency on one, but serialization can be done by customers.

Fixes #6309.

@github-actions github-actions bot added R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR R-loom-multi-thread-alt Run loom multi-thread alt tests on this PR labels Nov 14, 2024
@arielb1 arielb1 force-pushed the programmatic-backtraces branch 3 times, most recently from df04fc7 to ede6e06 Compare November 14, 2024 18:00
@arielb1
Copy link
Author

arielb1 commented Nov 19, 2024

What is this waiting for?

@arielb1
Copy link
Author

arielb1 commented Nov 20, 2024

So @Darksonn is busy these days. Could @mox692 please review this?

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-taskdump --cfg tokio_taskdump labels Nov 21, 2024
Copy link
Member

@mox692 mox692 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left high level questions about suggested apis.

Comment on lines 62 to 70
/// Return the raw name of the symbol.
pub fn name_raw(&self) -> Option<&[u8]> {
self.name.as_deref()
}

/// Return the demangled name of the symbol.
pub fn name_demangled(&self) -> Option<&str> {
self.name_demangled.as_deref()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both? I think users can construct demangled one by using name_raw.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had it since backtrace had that, and for some reason I thought the API was somewhat private. Apparently rustc_demangle is a perfectly fine public API.

Comment on lines 167 to 171
/// Resolve and return a list of backtraces that are involved in polls in this task.
pub fn resolve_backtraces(&self) -> Vec<Vec<BacktraceFrame>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for one Trace to return multiple backtraces? If such a case does not exist, I feel it would be clearer to return Vec<BacktraceFrame>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this may have to do with tokio::join! and similar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation to that effect.

Comment on lines +173 to +182
let mut backtrace = backtrace::Backtrace::from(backtrace.clone());
backtrace.resolve();
backtrace
.frames()
.iter()
.map(BacktraceFrame::from_resolved_backtrace_frame)
.collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can fix this in the follow up PR, but if we are going to have our own Backtrace type, I think we can avoid this conversion by making trace_leaf function construct tokio's Backtrace struct directly.

Copy link
Author

@arielb1 arielb1 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resolves the backtrace, and therefore is expensive (see warning in docs), and therefore shouldn't be done in trace_leaf

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 M-taskdump --cfg tokio_taskdump R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR R-loom-multi-thread-alt Run loom multi-thread alt tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support an API to extract backtrace information from taskdump
3 participants