Skip to content

Commit

Permalink
Update inner struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mox692 committed Mar 3, 2024
1 parent 2de89f7 commit 63da3c2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
53 changes: 51 additions & 2 deletions tokio/src/runtime/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
//!
//! See [Handle::dump][crate::runtime::Handle::dump].
use crate::runtime::task::trace::tree::Tree;
use crate::runtime::task::Symbol as SymbolInner;
use crate::runtime::task::Tree as TreeInner;
use crate::task::Id;
use backtrace::BacktraceSymbol;
use std::collections::{HashMap, HashSet};
use std::fmt;

/// A snapshot of a runtime's state.
Expand Down Expand Up @@ -34,7 +37,53 @@ pub struct Task {
impl Task {
/// Returns a trace tree of this task.
pub fn task_trace(&self) -> Tree {
self.trace.inner.trace_tree()
let inner = self.trace.inner.trace_tree();
Tree::from(inner)
}
}

/// docs
#[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.
pub roots: HashSet<Symbol>,

/// The adjacency list of symbols in the execution tree(s).
pub edges: HashMap<Symbol, HashSet<Symbol>>,
}

/// docs
#[derive(Eq, PartialEq, Hash, Clone)]
#[allow(missing_debug_implementations)]
pub struct Symbol {
inner: super::task::Symbol,
}

impl Symbol {
/// docs
pub fn backtrace_symbol(&self) -> &BacktraceSymbol {
&self.inner.symbol
}
}

impl From<SymbolInner> for Symbol {
fn from(symbol: SymbolInner) -> Self {
Self { inner: symbol }
}
}

impl From<TreeInner> for Tree {
fn from(tree: TreeInner) -> Self {
Self {
roots: tree.roots.into_iter().map(Symbol::from).collect(),
edges: tree
.edges
.into_iter()
.map(|(k, v)| (Symbol::from(k), v.into_iter().map(Symbol::from).collect()))
.collect(),
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tokio/src/runtime/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ mod waker;

cfg_taskdump! {
pub(crate) mod trace;

pub(crate) use trace::tree::Tree;
pub(crate) use trace::symbol::Symbol;
}

use crate::future::Future;
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/task/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use std::pin::Pin;
use std::ptr::{self, NonNull};
use std::task::{self, Poll};

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

use symbol::Symbol;
use tree::Tree;
pub(crate) use symbol::Symbol;
pub(crate) use tree::Tree;

use super::{Notified, OwnedTasks, Schedule};

Expand Down
7 changes: 4 additions & 3 deletions tokio/src/runtime/task/trace/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use std::ptr;
/// would not be able to distinguish between recursive calls of a function at
/// different depths.
#[derive(Clone)]
pub(super) struct Symbol {
pub(super) symbol: BacktraceSymbol,
pub(super) parent_hash: u64,
#[allow(missing_debug_implementations)]
pub struct Symbol {
pub symbol: BacktraceSymbol,
pub parent_hash: u64,
}

impl Hash for Symbol {
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/runtime/task/trace/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub struct Tree {
/// The roots of the trees.
///
/// There should only be one root, but the code is robust to multiple roots.
roots: HashSet<Symbol>,
pub(crate) roots: HashSet<Symbol>,

/// The adjacency list of symbols in the execution tree(s).
edges: HashMap<Symbol, HashSet<Symbol>>,
pub(crate) edges: HashMap<Symbol, HashSet<Symbol>>,
}

impl Tree {
Expand Down

0 comments on commit 63da3c2

Please sign in to comment.