-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stats: initial work on runtime stats (#4043)
- Loading branch information
Showing
14 changed files
with
276 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! This file contains mocks of the types in src/runtime/stats/stats.rs | ||
pub(crate) struct RuntimeStats {} | ||
|
||
impl RuntimeStats { | ||
pub(crate) fn new(_worker_threads: usize) -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
pub(crate) struct WorkerStatsBatcher {} | ||
|
||
impl WorkerStatsBatcher { | ||
pub(crate) fn new(_my_index: usize) -> Self { | ||
Self {} | ||
} | ||
|
||
pub(crate) fn submit(&mut self, _to: &RuntimeStats) {} | ||
|
||
pub(crate) fn about_to_park(&mut self) {} | ||
pub(crate) fn returned_from_park(&mut self) {} | ||
|
||
#[cfg(feature = "rt-multi-thread")] | ||
pub(crate) fn incr_steal_count(&mut self, _by: u16) {} | ||
|
||
pub(crate) fn incr_poll_count(&mut self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//! This module contains information need to view information about how the | ||
//! runtime is performing. | ||
#![allow(clippy::module_inception)] | ||
|
||
cfg_stats! { | ||
mod stats; | ||
|
||
pub use self::stats::{RuntimeStats, WorkerStats}; | ||
pub(crate) use self::stats::WorkerStatsBatcher; | ||
} | ||
|
||
cfg_not_stats! { | ||
#[path = "mock.rs"] | ||
mod stats; | ||
|
||
pub(crate) use self::stats::{RuntimeStats, WorkerStatsBatcher}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//! This file contains the types necessary to collect various types of stats. | ||
use crate::loom::sync::atomic::{AtomicU64, Ordering::Relaxed}; | ||
|
||
/// This type contains methods to retrieve stats from a Tokio runtime. | ||
#[derive(Debug)] | ||
pub struct RuntimeStats { | ||
workers: Box<[WorkerStats]>, | ||
} | ||
|
||
/// This type contains methods to retrieve stats from a worker thread on a Tokio runtime. | ||
#[derive(Debug)] | ||
#[repr(align(128))] | ||
pub struct WorkerStats { | ||
park_count: AtomicU64, | ||
steal_count: AtomicU64, | ||
poll_count: AtomicU64, | ||
} | ||
|
||
impl RuntimeStats { | ||
pub(crate) fn new(worker_threads: usize) -> Self { | ||
let mut workers = Vec::with_capacity(worker_threads); | ||
for _ in 0..worker_threads { | ||
workers.push(WorkerStats { | ||
park_count: AtomicU64::new(0), | ||
steal_count: AtomicU64::new(0), | ||
poll_count: AtomicU64::new(0), | ||
}); | ||
} | ||
|
||
Self { | ||
workers: workers.into_boxed_slice(), | ||
} | ||
} | ||
|
||
/// Returns a slice containing the worker stats for each worker thread. | ||
pub fn workers(&self) -> impl Iterator<Item = &WorkerStats> { | ||
self.workers.iter() | ||
} | ||
} | ||
|
||
impl WorkerStats { | ||
/// Returns the total number of times this worker thread has parked. | ||
pub fn park_count(&self) -> u64 { | ||
self.park_count.load(Relaxed) | ||
} | ||
|
||
/// Returns the number of tasks this worker has stolen from other worker | ||
/// threads. | ||
pub fn steal_count(&self) -> u64 { | ||
self.steal_count.load(Relaxed) | ||
} | ||
|
||
/// Returns the number of times this worker has polled a task. | ||
pub fn poll_count(&self) -> u64 { | ||
self.poll_count.load(Relaxed) | ||
} | ||
} | ||
|
||
pub(crate) struct WorkerStatsBatcher { | ||
my_index: usize, | ||
park_count: u64, | ||
steal_count: u64, | ||
poll_count: u64, | ||
} | ||
|
||
impl WorkerStatsBatcher { | ||
pub(crate) fn new(my_index: usize) -> Self { | ||
Self { | ||
my_index, | ||
park_count: 0, | ||
steal_count: 0, | ||
poll_count: 0, | ||
} | ||
} | ||
pub(crate) fn submit(&mut self, to: &RuntimeStats) { | ||
let worker = &to.workers[self.my_index]; | ||
|
||
worker.park_count.store(self.park_count, Relaxed); | ||
worker.steal_count.store(self.steal_count, Relaxed); | ||
worker.poll_count.store(self.poll_count, Relaxed); | ||
} | ||
|
||
pub(crate) fn about_to_park(&mut self) { | ||
self.park_count += 1; | ||
} | ||
|
||
pub(crate) fn returned_from_park(&mut self) {} | ||
|
||
#[cfg(feature = "rt-multi-thread")] | ||
pub(crate) fn incr_steal_count(&mut self, by: u16) { | ||
self.steal_count += u64::from(by); | ||
} | ||
|
||
pub(crate) fn incr_poll_count(&mut self) { | ||
self.poll_count += 1; | ||
} | ||
} |
Oops, something went wrong.