
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1203 · main · 9 min 56 s
1Étoiles
0Forks
0Issues
| 1 | use std::sync::atomic::{AtomicU64, Ordering}; |
| 2 | |
| 3 | /// What is counted. |
| 4 | #[derive(Clone, Copy)] |
| 5 | pub(crate) enum Kind { |
| 6 | /// Slices run. |
| 7 | Slices, |
| 8 | /// Slices run on another thread than the actor's previous one. |
| 9 | Moved, |
| 10 | /// Slices taken from a thread's next slot. |
| 11 | Next, |
| 12 | /// Slices stolen from another thread's queues. |
| 13 | Stolen, |
| 14 | /// Wake-ups queued on another thread (the actor's home). |
| 15 | Sent, |
| 16 | /// Times a thread parked. |
| 17 | Parks, |
| 18 | } |
| 19 | |
| 20 | const KINDS: usize = 6; |
| 21 | |
| 22 | /// What each [`Kind`] is called in the report. |
| 23 | pub(crate) const NAMES: [&str; KINDS] = [ |
| 24 | "slices", |
| 25 | "slices on another thread than the last", |
| 26 | "slices from the next slot", |
| 27 | "slices stolen", |
| 28 | "wake-ups queued on another thread", |
| 29 | "parks", |
| 30 | ]; |
| 31 | |
| 32 | static TOTALS: [AtomicU64; KINDS] = [const { AtomicU64::new(0) }; KINDS]; |
| 33 | |
| 34 | thread_local! { |
| 35 | // Read and written only on the scheduler thread's own stack. |
| 36 | static MINE: std::cell::Cell<[u64; KINDS]> = const { std::cell::Cell::new([0; KINDS]) }; |
| 37 | } |
| 38 | |
| 39 | pub(crate) fn count(kind: Kind) { |
| 40 | let mut mine = MINE.get(); |
| 41 | mine[kind as usize] += 1; |
| 42 | MINE.set(mine); |
| 43 | } |
| 44 | |
| 45 | /// Add this thread's counts to the totals. |
| 46 | pub(super) fn flush() { |
| 47 | for (i, n) in MINE.replace([0; KINDS]).into_iter().enumerate() { |
| 48 | TOTALS[i].fetch_add(n, Ordering::Relaxed); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /// The totals, once the scheduler threads stopped. |
| 53 | pub(crate) fn totals() -> [u64; KINDS] { |
| 54 | std::array::from_fn(|i| TOTALS[i].load(Ordering::Relaxed)) |
| 55 | } |