@@ -143,6 +143,103 @@ impl RuntimeMetrics {
143
143
. load( Relaxed ) ;
144
144
Duration :: from_nanos( nanos)
145
145
}
146
+
147
+ /// Returns the total number of times the given worker thread has parked.
148
+ ///
149
+ /// The worker park count starts at zero when the runtime is created and
150
+ /// increases by one each time the worker parks the thread waiting for new
151
+ /// inbound events to process. This usually means the worker has processed
152
+ /// all pending work and is currently idle.
153
+ ///
154
+ /// The counter is monotonically increasing. It is never decremented or
155
+ /// reset to zero.
156
+ ///
157
+ /// # Arguments
158
+ ///
159
+ /// `worker` is the index of the worker being queried. The given value must
160
+ /// be between 0 and `num_workers()`. The index uniquely identifies a single
161
+ /// worker and will continue to identify the worker throughout the lifetime
162
+ /// of the runtime instance.
163
+ ///
164
+ /// # Panics
165
+ ///
166
+ /// The method panics when `worker` represents an invalid worker, i.e. is
167
+ /// greater than or equal to `num_workers()`.
168
+ ///
169
+ /// # Examples
170
+ ///
171
+ /// ```
172
+ /// use tokio::runtime::Handle;
173
+ ///
174
+ /// #[tokio::main]
175
+ /// async fn main() {
176
+ /// let metrics = Handle::current().metrics();
177
+ ///
178
+ /// let n = metrics.worker_park_count(0);
179
+ /// println!("worker 0 parked {} times", n);
180
+ /// }
181
+ /// ```
182
+ pub fn worker_park_count( & self , worker: usize ) -> u64 {
183
+ self . handle
184
+ . inner
185
+ . worker_metrics( worker)
186
+ . park_count
187
+ . load( Relaxed )
188
+ }
189
+
190
+ /// Returns the total number of times the given worker thread has parked
191
+ /// and unparked.
192
+ ///
193
+ /// The worker park/unpark count starts at zero when the runtime is created
194
+ /// and increases by one each time the worker parks the thread waiting for
195
+ /// new inbound events to process. This usually means the worker has processed
196
+ /// all pending work and is currently idle. When new work becomes available,
197
+ /// the worker is unparked and the park/unpark count is again increased by one.
198
+ ///
199
+ /// An odd count means that the worker is currently parked.
200
+ /// An even count means that the worker is currently active.
201
+ ///
202
+ /// The counter is monotonically increasing. It is never decremented or
203
+ /// reset to zero.
204
+ ///
205
+ /// # Arguments
206
+ ///
207
+ /// `worker` is the index of the worker being queried. The given value must
208
+ /// be between 0 and `num_workers()`. The index uniquely identifies a single
209
+ /// worker and will continue to identify the worker throughout the lifetime
210
+ /// of the runtime instance.
211
+ ///
212
+ /// # Panics
213
+ ///
214
+ /// The method panics when `worker` represents an invalid worker, i.e. is
215
+ /// greater than or equal to `num_workers()`.
216
+ ///
217
+ /// # Examples
218
+ ///
219
+ /// ```
220
+ /// use tokio::runtime::Handle;
221
+ ///
222
+ /// #[tokio::main]
223
+ /// async fn main() {
224
+ /// let metrics = Handle::current().metrics();
225
+ /// let n = metrics.worker_park_unpark_count(0);
226
+ ///
227
+ /// println!("worker 0 parked and unparked {} times", n);
228
+ ///
229
+ /// if n % 2 == 0 {
230
+ /// println!("worker 0 is active");
231
+ /// } else {
232
+ /// println!("worker 0 is parked");
233
+ /// }
234
+ /// }
235
+ /// ```
236
+ pub fn worker_park_unpark_count( & self , worker: usize ) -> u64 {
237
+ self . handle
238
+ . inner
239
+ . worker_metrics( worker)
240
+ . park_unpark_count
241
+ . load( Relaxed )
242
+ }
146
243
}
147
244
148
245
cfg_unstable_metrics ! {
@@ -318,104 +415,6 @@ impl RuntimeMetrics {
318
415
. load( Relaxed )
319
416
}
320
417
321
- /// Returns the total number of times the given worker thread has parked.
322
- ///
323
- /// The worker park count starts at zero when the runtime is created and
324
- /// increases by one each time the worker parks the thread waiting for new
325
- /// inbound events to process. This usually means the worker has processed
326
- /// all pending work and is currently idle.
327
- ///
328
- /// The counter is monotonically increasing. It is never decremented or
329
- /// reset to zero.
330
- ///
331
- /// # Arguments
332
- ///
333
- /// `worker` is the index of the worker being queried. The given value must
334
- /// be between 0 and `num_workers()`. The index uniquely identifies a single
335
- /// worker and will continue to identify the worker throughout the lifetime
336
- /// of the runtime instance.
337
- ///
338
- /// # Panics
339
- ///
340
- /// The method panics when `worker` represents an invalid worker, i.e. is
341
- /// greater than or equal to `num_workers()`.
342
- ///
343
- /// # Examples
344
- ///
345
- /// ```
346
- /// use tokio::runtime::Handle;
347
- ///
348
- /// #[tokio::main]
349
- /// async fn main() {
350
- /// let metrics = Handle::current().metrics();
351
- ///
352
- /// let n = metrics.worker_park_count(0);
353
- /// println!("worker 0 parked {} times", n);
354
- /// }
355
- /// ```
356
- pub fn worker_park_count( & self , worker: usize ) -> u64 {
357
- self . handle
358
- . inner
359
- . worker_metrics( worker)
360
- . park_count
361
- . load( Relaxed )
362
- }
363
-
364
- /// Returns the total number of times the given worker thread has parked
365
- /// and unparked.
366
- ///
367
- /// The worker park/unpark count starts at zero when the runtime is created
368
- /// and increases by one each time the worker parks the thread waiting for
369
- /// new inbound events to process. This usually means the worker has processed
370
- /// all pending work and is currently idle. When new work becomes available,
371
- /// the worker is unparked and the park/unpark count is again increased by one.
372
- ///
373
- /// An odd count means that the worker is currently parked.
374
- /// An even count means that the worker is currently active.
375
- ///
376
- /// The counter is monotonically increasing. It is never decremented or
377
- /// reset to zero.
378
- ///
379
- /// # Arguments
380
- ///
381
- /// `worker` is the index of the worker being queried. The given value must
382
- /// be between 0 and `num_workers()`. The index uniquely identifies a single
383
- /// worker and will continue to identify the worker throughout the lifetime
384
- /// of the runtime instance.
385
- ///
386
- /// # Panics
387
- ///
388
- /// The method panics when `worker` represents an invalid worker, i.e. is
389
- /// greater than or equal to `num_workers()`.
390
- ///
391
- /// # Examples
392
- ///
393
- /// ```
394
- /// use tokio::runtime::Handle;
395
- ///
396
- /// #[tokio::main]
397
- /// async fn main() {
398
- /// let metrics = Handle::current().metrics();
399
- /// let n = metrics.worker_park_unpark_count(0);
400
- ///
401
- /// println!("worker 0 parked and unparked {} times", n);
402
- ///
403
- /// if n % 2 == 0 {
404
- /// println!("worker 0 is active");
405
- /// } else {
406
- /// println!("worker 0 is parked");
407
- /// }
408
- /// }
409
- /// ```
410
- pub fn worker_park_unpark_count( & self , worker: usize ) -> u64 {
411
- self . handle
412
- . inner
413
- . worker_metrics( worker)
414
- . park_unpark_count
415
- . load( Relaxed )
416
- }
417
-
418
-
419
418
/// Returns the number of times the given worker thread unparked but
420
419
/// performed no work before parking again.
421
420
///
0 commit comments