Repository: tokio-rs/tokio
File: tokio/src/runtime/handle.rs (Rust)

Code before:

    /// Returns a view that lets you get information about how the runtime
    /// is performing.
    pub fn metrics(&self) -> RuntimeMetrics {
        RuntimeMetrics::new(self.clone())
    }
}

/// TEST PURPOSE RELATED TO PR #7773
#[cfg(feature = "full")]
impl Handle {
    /// Returns the number of pending registrations (test-only, not part of public API)
    #[doc(hidden)]
    #[allow(unreachable_pub)]
    pub fn io_pending_registration_count(&self) -> usize {
        self.inner.driver().io().pending_registration_count()
    }

    /// Returns the total number of registrations in the main list (test-only, not part of public API)
    #[doc(hidden)]
    #[allow(unreachable_pub)]
    pub fn io_total_registration_count(&self) -> usize {
        self.inner.driver().io().total_registration_count()
    }
}

impl std::panic::UnwindSafe for Handle {}

impl std::panic::RefUnwindSafe for Handle {}

cfg_taskdump! {
    impl Handle {
        /// Captures a snapshot of the runtime's state.
        ///
        /// If you only want to capture a snapshot of a single future's state, you can use
        /// [`Trace::capture`][crate::runtime::dump::Trace].
        ///
        /// This functionality is experimental, and comes with a number of
        /// requirements and limitations.
        ///
        /// # Examples
        ///
        /// This can be used to get call traces of each task in the runtime.
        /// Calls to `Handle::dump` should usually be enclosed in a
        /// [timeout][crate::time::timeout], so that dumping does not escalate a
        /// single blocked runtime thread into an entirely blocked runtime.
        ///
        /// ```
        /// # use tokio::runtime::Runtime;
        /// # fn dox() {
        /// # let rt = Runtime::new().unwrap();

Review comment (suggestion):
We'd better avoiding exposing public (even with `#[doc(hidden)]`) interface just for internal testing.

Code after:
impl std::panic::UnwindSafe for Handle {}

impl std::panic::RefUnwindSafe for Handle {}

cfg_taskdump! {
    impl Handle {
        /// Captures a snapshot of the runtime's state.
        ///
        /// If you only want to capture a snapshot of a single future's state, you can use
        /// [`Trace::capture`][crate::runtime::dump::Trace].
        ///
        /// This functionality is experimental, and comes with a number of
        /// requirements and limitations.
        ///
        /// # Examples
        ///
        /// This can be used to get call traces of each task in the runtime.
        /// Calls to `Handle::dump` should usually be enclosed in a
        /// [timeout][crate::time::timeout], so that dumping does not escalate a
        /// single blocked runtime thread into an entirely blocked runtime.
        ///
        /// ```
        /// # use tokio::runtime::Runtime;
        /// # fn dox() {
        /// # let rt = Runtime::new().unwrap();
        /// # rt.spawn(async {
        /// use tokio::runtime::Handle;
        /// use tokio::time::{timeout, Duration};
        ///
        /// // Inside an async block or function.
        /// let handle = Handle::current();
        /// if let Ok(dump) = timeout(Duration::from_secs(2), handle.dump()).await {
        ///     for (i, task) in dump.tasks().iter().enumerate() {
        ///         let trace = task.trace();
        ///         println!("TASK {i}:");
        ///         println!("{trace}\n");
        ///     }
        /// }
        /// # });
        /// # }
        /// ```
        ///
        /// This produces highly detailed traces of tasks; e.g.:
        ///
        /// ```plain
        /// TASK 0:
        /// ╼ dump::main::{{closure}}::a::{{closure}} at /tokio/examples/dump.rs:18:20
        /// └╼ dump::main::{{closure}}::b::{{closure}} at /tokio/examples/dump.rs:23:20
        ///    └╼ dump::main::{{closure}}::c::{{closure}} at /tokio/examples/dump.rs:28:24
        ///       └╼ tokio::sync::barrier::Barrier::wait::{{closure}} at /tokio/tokio/src/sync/barrier.rs:129:10
        ///          └╼ <tokio::util::trace::InstrumentedAsyncOp<F> as core::future::future::Future>::poll at /tokio/tokio/src/util/trace.rs:77:46