1mod identity;
7mod metrics;
8mod model;
9
10#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub struct TimerRegistrationId {
18 epoch: TimerEpoch,
19 sequence: u64,
20}
21
22impl TimerRegistrationId {
23 pub(crate) const fn new(epoch: TimerEpoch, sequence: u64) -> Self {
24 Self { epoch, sequence }
25 }
26
27 #[must_use]
29 pub const fn epoch(self) -> TimerEpoch {
30 self.epoch
31 }
32
33 #[must_use]
35 pub const fn sequence(self) -> u64 {
36 self.sequence
37 }
38}
39
40pub use identity::{
41 MAX_TIMER_IDENTITY_COMPONENT_BYTES, TimerIdentity, TimerIdentityError, TimerIdentityField,
42};
43pub use metrics::{
44 MeasurementSummary, MemoryPageExtent, MemoryPageSample, MemoryPageSummary, TimerCounters,
45 TimerObservabilitySnapshot, TimerPerformance,
46};
47pub use model::{
48 DeclarationLifetime, InactiveReason, OrdinaryRuntimeStateSnapshot, TimerCompletion,
49 TimerCompletionOutcome, TimerControlFailure, TimerDirectiveSnapshot, TimerEpoch,
50 TimerLastOutcome, TimerOutcomeSnapshot, TimerPolicy, TimerProcessCondition,
51 TimerRegistrationStatus, TimerRunResult, TimerRuntimeStateSnapshot, TimerSchedulingMode,
52 WatchdogAttemptSnapshot, WatchdogAttemptStatus, WatchdogDecision, WatchdogRunResult,
53 WatchdogRuntimeStateSnapshot,
54};
55
56#[derive(Clone, Debug, Eq, PartialEq)]
62pub struct TimerInventorySnapshot {
63 epoch: TimerEpoch,
64 timers: Vec<TimerSnapshot>,
65}
66
67impl TimerInventorySnapshot {
68 pub(crate) const fn new(epoch: TimerEpoch, timers: Vec<TimerSnapshot>) -> Self {
69 Self { epoch, timers }
70 }
71
72 #[must_use]
74 pub const fn epoch(&self) -> TimerEpoch {
75 self.epoch
76 }
77
78 #[must_use]
80 pub fn timers(&self) -> &[TimerSnapshot] {
81 &self.timers
82 }
83
84 #[must_use]
86 pub fn into_timers(self) -> Vec<TimerSnapshot> {
87 self.timers
88 }
89
90 #[must_use]
92 pub const fn len(&self) -> usize {
93 self.timers.len()
94 }
95
96 #[must_use]
98 pub const fn is_empty(&self) -> bool {
99 self.timers.is_empty()
100 }
101}
102
103#[derive(Clone, Debug, Eq, PartialEq)]
105pub struct TimerSnapshot {
106 identity: TimerIdentity,
107 registration_id: TimerRegistrationId,
108 policy: TimerPolicy,
109 lifetime: DeclarationLifetime,
110 state: TimerRuntimeStateSnapshot,
111 scheduling_mode: TimerSchedulingMode,
112 latest_directive: Option<TimerDirectiveSnapshot>,
113 latest_requested_delay_ns: Option<u64>,
114 latest_armed_delay_ns: Option<u64>,
115 observability: TimerObservabilitySnapshot,
116}
117
118impl TimerSnapshot {
119 #[allow(clippy::too_many_arguments)] pub(crate) const fn new(
121 identity: TimerIdentity,
122 registration_id: TimerRegistrationId,
123 policy: TimerPolicy,
124 lifetime: DeclarationLifetime,
125 state: TimerRuntimeStateSnapshot,
126 scheduling_mode: TimerSchedulingMode,
127 latest_directive: Option<TimerDirectiveSnapshot>,
128 latest_requested_delay_ns: Option<u64>,
129 latest_armed_delay_ns: Option<u64>,
130 observability: &TimerObservabilitySnapshot,
131 ) -> Self {
132 Self {
133 identity,
134 registration_id,
135 policy,
136 lifetime,
137 state,
138 scheduling_mode,
139 latest_directive,
140 latest_requested_delay_ns,
141 latest_armed_delay_ns,
142 observability: *observability,
143 }
144 }
145
146 #[must_use]
148 pub const fn identity(&self) -> &TimerIdentity {
149 &self.identity
150 }
151
152 #[must_use]
159 pub const fn registration_id(&self) -> TimerRegistrationId {
160 self.registration_id
161 }
162
163 #[must_use]
165 pub const fn policy(&self) -> TimerPolicy {
166 self.policy
167 }
168
169 #[must_use]
171 pub const fn lifetime(&self) -> DeclarationLifetime {
172 self.lifetime
173 }
174
175 #[must_use]
177 pub const fn state(&self) -> TimerRuntimeStateSnapshot {
178 self.state
179 }
180
181 #[must_use]
187 pub const fn scheduling_mode(&self) -> TimerSchedulingMode {
188 self.scheduling_mode
189 }
190
191 #[must_use]
193 pub const fn latest_directive(&self) -> Option<TimerDirectiveSnapshot> {
194 self.latest_directive
195 }
196
197 #[must_use]
199 pub const fn latest_requested_delay_ns(&self) -> Option<u64> {
200 self.latest_requested_delay_ns
201 }
202
203 #[must_use]
205 pub const fn latest_armed_delay_ns(&self) -> Option<u64> {
206 self.latest_armed_delay_ns
207 }
208
209 #[must_use]
211 pub const fn next_deadline_ns(&self) -> Option<u64> {
212 self.state.next_deadline_ns()
213 }
214
215 #[must_use]
217 pub fn registration_status(&self) -> TimerRegistrationStatus {
218 self.state.into()
219 }
220
221 #[must_use]
223 pub const fn process_condition(&self) -> TimerProcessCondition {
224 match self.state {
225 TimerRuntimeStateSnapshot::Inactive {
226 reason: InactiveReason::Cancelled,
227 } => TimerProcessCondition::Disabled,
228 TimerRuntimeStateSnapshot::Inactive {
229 reason: InactiveReason::InvariantFailure | InactiveReason::ControlFailure(_),
230 } => TimerProcessCondition::Failed,
231 TimerRuntimeStateSnapshot::Inactive {
232 reason: InactiveReason::Stopped,
233 } if matches!(
234 self.observability.outcomes().last_outcome(),
235 Some(TimerLastOutcome::Completed(
236 TimerCompletionOutcome::RetryableFailure
237 ))
238 ) =>
239 {
240 TimerProcessCondition::Failed
241 }
242 TimerRuntimeStateSnapshot::Inactive { .. } => TimerProcessCondition::Idle,
243 TimerRuntimeStateSnapshot::Ordinary(_) | TimerRuntimeStateSnapshot::Watchdog(_)
244 if matches!(self.scheduling_mode, TimerSchedulingMode::Retry) =>
245 {
246 TimerProcessCondition::Retrying
247 }
248 TimerRuntimeStateSnapshot::Ordinary(_) | TimerRuntimeStateSnapshot::Watchdog(_) => {
249 TimerProcessCondition::Active
250 }
251 }
252 }
253
254 #[must_use]
259 pub const fn generation(&self) -> Option<u64> {
260 match self.state {
261 TimerRuntimeStateSnapshot::Inactive { .. } => None,
262 TimerRuntimeStateSnapshot::Ordinary(
263 OrdinaryRuntimeStateSnapshot::Scheduled { generation, .. }
264 | OrdinaryRuntimeStateSnapshot::Running { generation },
265 ) => Some(generation),
266 TimerRuntimeStateSnapshot::Watchdog(WatchdogRuntimeStateSnapshot::Scheduled {
267 scheduler_generation,
268 ..
269 }) => Some(scheduler_generation),
270 TimerRuntimeStateSnapshot::Watchdog(WatchdogRuntimeStateSnapshot::AwaitingWork {
271 successor_generation,
272 ..
273 }) => Some(successor_generation),
274 }
275 }
276
277 #[must_use]
279 pub const fn observability(&self) -> TimerObservabilitySnapshot {
280 self.observability
281 }
282}
283
284#[cfg(test)]
285mod tests;