pub struct RuntimeMetrics { /* private fields */ }
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 more