tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

55 lignes · 1477 octetsBrut · Historique
1use std::sync::atomic::{AtomicU64, Ordering};
2
3/// What is counted.
4#[derive(Clone, Copy)]
5pub(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
20const KINDS: usize = 6;
21
22/// What each [`Kind`] is called in the report.
23pub(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
32static TOTALS: [AtomicU64; KINDS] = [const { AtomicU64::new(0) }; KINDS];
33
34thread_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
39pub(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.
46pub(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.
53pub(crate) fn totals() -> [u64; KINDS] {
54 std::array::from_fn(|i| TOTALS[i].load(Ordering::Relaxed))
55}