Skip to content

Commit

Permalink
Export task tree public api
Browse files Browse the repository at this point in the history
  • Loading branch information
mox692 committed Mar 3, 2024
1 parent 5658d7c commit 2de89f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tokio/src/runtime/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! See [Handle::dump][crate::runtime::Handle::dump].
use crate::runtime::task::trace::tree::Tree;
use crate::task::Id;
use std::fmt;

Expand Down Expand Up @@ -30,6 +31,13 @@ pub struct Task {
trace: Trace,
}

impl Task {
/// Returns a trace tree of this task.
pub fn task_trace(&self) -> Tree {
self.trace.inner.trace_tree()
}
}

/// An execution trace of a task's last poll.
///
/// See [Handle::dump][crate::runtime::Handle::dump].
Expand Down
8 changes: 7 additions & 1 deletion tokio/src/runtime/task/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::ptr::{self, NonNull};
use std::task::{self, Poll};

mod symbol;
mod tree;
pub(crate) mod tree;

use symbol::Symbol;
use tree::Tree;
Expand Down Expand Up @@ -53,6 +53,12 @@ pub(crate) struct Trace {
backtraces: Vec<Backtrace>,
}

impl Trace {
pub(crate) fn trace_tree(&self) -> Tree {
Tree::from_trace(self.clone())
}
}

pin_project_lite::pin_project! {
#[derive(Debug, Clone)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/runtime/task/trace/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use super::{Backtrace, Symbol, SymbolTrace, Trace};
///
/// This tree provides a convenient intermediate representation for formatting
/// [`Trace`] as a tree.
pub(super) struct Tree {
#[allow(missing_debug_implementations)]
pub struct Tree {
/// The roots of the trees.
///
/// There should only be one root, but the code is robust to multiple roots.
Expand Down

0 comments on commit 2de89f7

Please sign in to comment.