From e576bd3beeff9621ed58e696c83746c63699fe2a Mon Sep 17 00:00:00 2001 From: mox692 Date: Sat, 19 Oct 2024 03:24:47 +0900 Subject: [PATCH 1/3] metrics: rename `injection_queue_depth` to `global_queue_depth` --- tokio/src/runtime/metrics/runtime.rs | 39 +++++++++++++++++++++++----- tokio/tests/rt_metrics.rs | 8 +++--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tokio/src/runtime/metrics/runtime.rs b/tokio/src/runtime/metrics/runtime.rs index 008245ecc36..5e2614739e1 100644 --- a/tokio/src/runtime/metrics/runtime.rs +++ b/tokio/src/runtime/metrics/runtime.rs @@ -71,11 +71,11 @@ impl RuntimeMetrics { } /// Returns the number of tasks currently scheduled in the runtime's - /// injection queue. + /// global queue. /// /// Tasks that are spawned or notified from a non-runtime thread are - /// scheduled using the runtime's injection queue. This metric returns the - /// **current** number of tasks pending in the injection queue. As such, the + /// scheduled using the runtime's global queue. This metric returns the + /// **current** number of tasks pending in the global queue. As such, the /// returned value may increase or decrease as new tasks are scheduled and /// processed. /// @@ -88,11 +88,11 @@ impl RuntimeMetrics { /// async fn main() { /// let metrics = Handle::current().metrics(); /// - /// let n = metrics.injection_queue_depth(); - /// println!("{} tasks currently pending in the runtime's injection queue", n); + /// let n = metrics.global_queue_depth(); + /// println!("{} tasks currently pending in the runtime's global queue", n); /// } /// ``` - pub fn injection_queue_depth(&self) -> usize { + pub fn global_queue_depth(&self) -> usize { self.handle.inner.injection_queue_depth() } @@ -681,6 +681,33 @@ impl RuntimeMetrics { } } + /// Returns the number of tasks currently scheduled in the runtime's + /// injection queue. + /// + /// Tasks that are spawned or notified from a non-runtime thread are + /// scheduled using the runtime's injection queue. This metric returns the + /// **current** number of tasks pending in the injection queue. As such, the + /// returned value may increase or decrease as new tasks are scheduled and + /// processed. + /// + /// # Examples + /// + /// ``` + /// use tokio::runtime::Handle; + /// + /// #[tokio::main] + /// async fn main() { + /// let metrics = Handle::current().metrics(); + /// + /// let n = metrics.injection_queue_depth(); + /// println!("{} tasks currently pending in the runtime's injection queue", n); + /// } + /// ``` + #[deprecated = "Renamed to global_queue_depth"] + pub fn injection_queue_depth(&self) -> usize { + self.handle.inner.injection_queue_depth() + } + /// Returns the number of tasks currently scheduled in the given worker's /// local queue. /// diff --git a/tokio/tests/rt_metrics.rs b/tokio/tests/rt_metrics.rs index e2494cf5e64..dac8860b345 100644 --- a/tokio/tests/rt_metrics.rs +++ b/tokio/tests/rt_metrics.rs @@ -47,7 +47,7 @@ fn num_alive_tasks() { } #[test] -fn injection_queue_depth_current_thread() { +fn global_queue_depth_current_thread() { use std::thread; let rt = current_thread(); @@ -60,11 +60,11 @@ fn injection_queue_depth_current_thread() { .join() .unwrap(); - assert_eq!(1, metrics.injection_queue_depth()); + assert_eq!(1, metrics.global_queue_depth()); } #[test] -fn injection_queue_depth_multi_thread() { +fn global_queue_depth_multi_thread() { let rt = threaded(); let metrics = rt.metrics(); @@ -85,7 +85,7 @@ fn injection_queue_depth_multi_thread() { let mut fail: Option = None; for i in 0..10 { - let depth = metrics.injection_queue_depth(); + let depth = metrics.global_queue_depth(); if i != depth { fail = Some(format!("{i} is not equal to {depth}")); break; From 8e90e20351df67ea1370aeb36f4a52f337860d9e Mon Sep 17 00:00:00 2001 From: mox692 Date: Sat, 19 Oct 2024 03:48:10 +0900 Subject: [PATCH 2/3] doc fix --- tokio/src/runtime/metrics/runtime.rs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/tokio/src/runtime/metrics/runtime.rs b/tokio/src/runtime/metrics/runtime.rs index 5e2614739e1..c3ca5255c83 100644 --- a/tokio/src/runtime/metrics/runtime.rs +++ b/tokio/src/runtime/metrics/runtime.rs @@ -681,29 +681,8 @@ impl RuntimeMetrics { } } - /// Returns the number of tasks currently scheduled in the runtime's - /// injection queue. - /// - /// Tasks that are spawned or notified from a non-runtime thread are - /// scheduled using the runtime's injection queue. This metric returns the - /// **current** number of tasks pending in the injection queue. As such, the - /// returned value may increase or decrease as new tasks are scheduled and - /// processed. - /// - /// # Examples - /// - /// ``` - /// use tokio::runtime::Handle; - /// - /// #[tokio::main] - /// async fn main() { - /// let metrics = Handle::current().metrics(); - /// - /// let n = metrics.injection_queue_depth(); - /// println!("{} tasks currently pending in the runtime's injection queue", n); - /// } - /// ``` #[deprecated = "Renamed to global_queue_depth"] + /// Renamed to [`RuntimeMetrics::global_queue_depth`] pub fn injection_queue_depth(&self) -> usize { self.handle.inner.injection_queue_depth() } From b1af23d1b77f05b2427f9384bcaaa004a2643aa0 Mon Sep 17 00:00:00 2001 From: mox692 Date: Sat, 19 Oct 2024 04:10:04 +0900 Subject: [PATCH 3/3] doc hidden --- tokio/src/runtime/metrics/runtime.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tokio/src/runtime/metrics/runtime.rs b/tokio/src/runtime/metrics/runtime.rs index c3ca5255c83..c5614bcbef3 100644 --- a/tokio/src/runtime/metrics/runtime.rs +++ b/tokio/src/runtime/metrics/runtime.rs @@ -681,8 +681,9 @@ impl RuntimeMetrics { } } - #[deprecated = "Renamed to global_queue_depth"] /// Renamed to [`RuntimeMetrics::global_queue_depth`] + #[deprecated = "Renamed to global_queue_depth"] + #[doc(hidden)] pub fn injection_queue_depth(&self) -> usize { self.handle.inner.injection_queue_depth() }