| 1 |
//! Snapshots of runtime state. |
| 2 |
//! |
| 3 |
//! See [Handle::dump][crate::runtime::Handle::dump]. |
| 4 |
|
| 5 |
use crate::task::Id; |
| 6 |
use std::fmt; |
| 7 |
|
| 8 |
/// A snapshot of a runtime's state. |
| 9 |
/// |
| 10 |
/// See [Handle::dump][crate::runtime::Handle::dump]. |
| 11 |
#[derive(Debug)] |
| 12 |
pub struct Dump { |
| 13 |
tasks: Tasks, |
| 14 |
} |
| 15 |
|
| 16 |
/// Snapshots of tasks. |
| 17 |
/// |
| 18 |
/// See [Handle::dump][crate::runtime::Handle::dump]. |
| 19 |
#[derive(Debug)] |
| 20 |
pub struct Tasks { |
| 21 |
tasks: Vec<Task>, |
| 22 |
} |
| 23 |
|
| 24 |
/// A snapshot of a task. |
| 25 |
/// |
| 26 |
/// See [Handle::dump][crate::runtime::Handle::dump]. |
| 27 |
#[derive(Debug)] |
| 28 |
pub struct Task { |
| 29 |
id: Id, |
| 30 |
trace: Trace, |
| 31 |
} |
| 32 |
|
| 33 |
/// An execution trace of a task's last poll. |
| 34 |
/// |
| 35 |
/// See [Handle::dump][crate::runtime::Handle::dump]. |
| 36 |
#[derive(Debug)] |
| 37 |
pub struct Trace { |
| 38 |
inner: super::task::trace::Trace, |
| 39 |
} |
| 40 |
|
| 41 |
impl Dump { |
| 42 |
pub(crate) fn new(tasks: Vec<Task>) -> Self { |
| 43 |
Self { |
| 44 |
tasks: Tasks { tasks }, |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/// Tasks in this snapshot. |
| 49 |
pub fn tasks(&self) -> &Tasks { |
| 50 |
&self.tasks |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
impl Tasks { |
| 55 |
/// Iterate over tasks. |
| 56 |
pub fn iter(&self) -> impl Iterator<Item = &Task> { |
| 57 |
self.tasks.iter() |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
impl Task { |
| 62 |
pub(crate) fn new(id: Id, trace: super::task::trace::Trace) -> Self { |
| 63 |
Self { |
| 64 |
id, |
| 65 |
trace: Trace { inner: trace }, |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/// Returns a [task ID] that uniquely identifies this task relative to other |
| 70 |
/// tasks spawned at the time of the dump. |
| 71 |
/// |
| 72 |
/// **Note**: This is an [unstable API][unstable]. The public API of this type |
| 73 |
/// may break in 1.x releases. See [the documentation on unstable |
| 74 |
/// features][unstable] for details. |
| 75 |
/// |
| 76 |
/// [task ID]: crate::task::Id |
| 77 |
/// [unstable]: crate#unstable-features |
| 78 |
#[cfg(tokio_unstable)] |
| 79 |
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] |
| 80 |
pub fn id(&self) -> Id { |
| 81 |
self.id |
| 82 |
} |
| 83 |
|
| 84 |
/// A trace of this task's state. |
| 85 |
pub fn trace(&self) -> &Trace { |
| 86 |
&self.trace |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
impl fmt::Display for Trace { |
| 91 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 92 |
self.inner.fmt(f) |
| 93 |
} |
| 94 |
} |