1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! How long each system's [`SystemTrait::tick`](crate::SystemTrait::tick) took,
//! as the [`Schedule`](crate::Schedule)'s clock measured it — see [`TickTime`].
use Duration;
use VecDeque;
/// How many ticks a system's [`TickTime::mean`] averages over.
///
/// One second of ticks at [`World::DEFAULT_TICK_DT`](crate::World::DEFAULT_TICK_DT)
/// — the default is asserted below. Long enough that a system costing a few
/// microseconds reads as a steady number rather than timer noise; short enough
/// that a change in its cost shows while you are still looking at the panel.
pub const TICK_TIME_WINDOW: usize = 60;
// The window's claim to be a second at the default rate, checked where it is
// made rather than restated.
const _: = assert!;
/// One system's measured tick cost: the last tick, and the mean over the last
/// [`TICK_TIME_WINDOW`] ticks.
///
/// # Wall time, kept out of the simulation
///
/// A tick time is the one number in this crate that comes from a real clock,
/// which `docs/notes/process.md` forbids anywhere a simulation could read it.
/// It is sound here because nothing that decides state can: the times live
/// beside the systems in the schedule, are read back only through
/// [`Inspector::collect`](crate::Inspector::collect), and never reach
/// [`Schedule::hash_state`](crate::Schedule::hash_state), a snapshot or a save.
/// The clock is injected ([`Schedule::set_clock`](crate::Schedule::set_clock))
/// rather than read here, so a test drives it by hand and a world nobody gave a
/// clock reads none at all.
/// A rolling window of one system's tick durations.
///
/// The mean is `total / len`, kept incrementally so recording is O(1);
/// `Duration` addition is exact, so the total cannot drift from the samples.
pub