@@ -210,10 +210,57 @@ impl RuntimeMetrics {
210210 . load ( Relaxed )
211211 }
212212
213+ /// Returns the number of tasks the given worker thread stole from
214+ /// another worker thread.
215+ ///
216+ /// This metric only applies to the **multi-threaded** runtime and will
217+ /// always return `0` when using the current thread runtime.
218+ ///
219+ /// The worker steal count starts at zero when the runtime is created and
220+ /// increases by `N` each time the worker has processed its scheduled queue
221+ /// and successfully steals `N` more pending tasks from another worker.
222+ ///
223+ /// The counter is monotonically increasing. It is never decremented or
224+ /// reset to zero.
225+ ///
226+ /// # Arguments
227+ ///
228+ /// `worker` is the index of the worker being queried. The given value must
229+ /// be between 0 and `num_workers()`. The index uniquely identifies a single
230+ /// worker and will continue to identify the worker throughout the lifetime
231+ /// of the runtime instance.
232+ ///
233+ /// # Panics
234+ ///
235+ /// The method panics when `worker` represents an invalid worker, i.e. is
236+ /// greater than or equal to `num_workers()`.
237+ ///
238+ /// # Examples
239+ ///
240+ /// ```
241+ /// use tokio::runtime::Handle;
242+ ///
243+ /// #[tokio::main]
244+ /// async fn main() {
245+ /// let metrics = Handle::current().metrics();
246+ ///
247+ /// let n = metrics.worker_steal_count(0);
248+ /// println!("worker 0 has stolen {} tasks", n);
249+ /// }
250+ /// ```
251+ pub fn worker_steal_count ( & self , worker : usize ) -> u64 {
252+ self . handle
253+ . inner
254+ . worker_metrics ( worker)
255+ . steal_count
256+ . load ( Relaxed )
257+ }
258+
213259 /// Returns the number of times the given worker thread stole tasks from
214260 /// another worker thread.
215261 ///
216- /// This metric only applies to the **multi-threaded** runtime and will always return `0` when using the current thread runtime.
262+ /// This metric only applies to the **multi-threaded** runtime and will
263+ /// always return `0` when using the current thread runtime.
217264 ///
218265 /// The worker steal count starts at zero when the runtime is created and
219266 /// increases by one each time the worker has processed its scheduled queue
@@ -243,15 +290,15 @@ impl RuntimeMetrics {
243290 /// async fn main() {
244291 /// let metrics = Handle::current().metrics();
245292 ///
246- /// let n = metrics.worker_noop_count (0);
293+ /// let n = metrics.worker_steal_operations (0);
247294 /// println!("worker 0 has stolen tasks {} times", n);
248295 /// }
249296 /// ```
250- pub fn worker_steal_count ( & self , worker : usize ) -> u64 {
297+ pub fn worker_steal_operations ( & self , worker : usize ) -> u64 {
251298 self . handle
252299 . inner
253300 . worker_metrics ( worker)
254- . steal_count
301+ . steal_operations
255302 . load ( Relaxed )
256303 }
257304
@@ -328,8 +375,8 @@ impl RuntimeMetrics {
328375 /// async fn main() {
329376 /// let metrics = Handle::current().metrics();
330377 ///
331- /// let n = metrics.worker_poll_count (0);
332- /// println!("worker 0 has polled {} tasks ", n);
378+ /// let n = metrics.worker_total_busy_duration (0);
379+ /// println!("worker 0 was busy for a total of {:?} ", n);
333380 /// }
334381 /// ```
335382 pub fn worker_total_busy_duration ( & self , worker : usize ) -> Duration {
0 commit comments