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 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)