pub struct RuntimeMetrics { /* private fields */ }
rt
only.Expand description
Handle to the runtime’s metrics.
This handle is internally reference-counted and can be freely cloned. A
RuntimeMetrics
handle is obtained using the Runtime::metrics
method.
Implementations§
Source§impl RuntimeMetrics
impl RuntimeMetrics
Sourcepub fn num_workers(&self) -> usize
pub fn num_workers(&self) -> usize
Returns the number of worker threads used by the runtime.
The number of workers is set by configuring worker_threads
on
runtime::Builder
. When using the current_thread
runtime, the return
value is always 1
.
§Examples
use tokio::runtime::Handle;
#[tokio::main]
async fn main() {
let metrics = Handle::current().metrics();
let n = metrics.num_workers();
println!("Runtime is using {} workers", n);
}
Sourcepub fn num_alive_tasks(&self) -> usize
pub fn num_alive_tasks(&self) -> usize
Returns the current number of alive tasks in the runtime.
This counter increases when a task is spawned and decreases when a task exits.
§Examples
use tokio::runtime::Handle;
#[tokio::main]
async fn main() {
let metrics = Handle::current().metrics();
let n = metrics.num_alive_tasks();
println!("Runtime has {} alive tasks", n);
}
Sourcepub fn global_queue_depth(&self) -> usize
pub fn global_queue_depth(&self) -> usize
Returns the number of tasks currently scheduled in the runtime’s global queue.
Tasks that are spawned or notified from a non-runtime thread are 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.
§Examples
use tokio::runtime::Handle;
#[tokio::main]
async fn main() {
let metrics = Handle::current().metrics();
let n = metrics.global_queue_depth();
println!("{} tasks currently pending in the runtime's global queue", n);
}
Trait Implementations§
Source§impl Clone for RuntimeMetrics
impl Clone for RuntimeMetrics
Source§fn clone(&self) -> RuntimeMetrics
fn clone(&self) -> RuntimeMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for RuntimeMetrics
impl !RefUnwindSafe for RuntimeMetrics
impl Send for RuntimeMetrics
impl Sync for RuntimeMetrics
impl Unpin for RuntimeMetrics
impl !UnwindSafe for RuntimeMetrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes