Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Ben-Yehuda committed Jan 9, 2025
1 parent 6e64f61 commit ba0f34d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
26 changes: 11 additions & 15 deletions tokio/src/runtime/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,21 @@ impl Trace {
///
/// Example usage:
/// ```
/// let mut trace = None;
///
/// // some future
/// let mut test_future = Box::pin(async move { tokio::task::yield_now().await; 0 });
/// let mut test_future = std::pin::pin!(async move { tokio::task::yield_now().await; 0 });
///
/// // trace it once
/// Trace::root(std::future::poll_fn(|cx| {
/// if trace.is_none() {
/// // make sure we only trace once
/// let (res, captured) = Trace::capture(|| test_future.as_mut().poll(cx));
/// trace = Some(captured);
/// res
/// } else {
/// test_future.as_mut().poll(cx)
/// }
/// })).await;@@
/// let (trace, res) = Trace::root(std::future::poll_fn(|cx| {
/// let (res, trace) = Trace::capture(|| test_future.as_mut().poll(cx));
/// Poll::Ready((trace, res))
/// })).await;
///
/// let output = match res {
/// Poll::Ready(output) => output,
/// Poll::Pending => test_future.await,
/// };
///
/// // check that there are backtraces
/// assert!(!trace.unwrap().resolve_backtraces().is_empty());
/// println!("{trace}");
/// ```
///
/// ### Nested calls
Expand Down
25 changes: 12 additions & 13 deletions tokio/tests/task_trace_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
))]

use std::{
future::Future,
pin::Pin,
sync::{Arc, Mutex},
task::{Context, Poll},
time::{Duration, Instant},
};
use std::future::Future;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use std::time::{Duration, Instant};

use tokio::runtime::dump::{Root, Trace};

pin_project_lite::pin_project! { pub struct PrettyFuture<F: Future> {
#[pin]
f: Root<F>,
t_last: State,
logs: Arc<Mutex<Vec<Trace>>>,
}
pin_project_lite::pin_project! {
pub struct PrettyFuture<F: Future> {
#[pin]
f: Root<F>,
t_last: State,
logs: Arc<Mutex<Vec<Trace>>>,
}
}

enum State {
Expand Down

0 comments on commit ba0f34d

Please sign in to comment.