eryon_rt/types/
statistics.rs

1/*
2    Appellation: statistics <module>
3    Contrib: @FL03
4*/
5
6/// Statistics about runtime resource utilization
7#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
8#[cfg_attr(
9    feature = "serde",
10    derive(serde_derive::Deserialize, serde_derive::Serialize),
11    serde(rename_all = "snake_case")
12)]
13pub struct RuntimeStats {
14    /// Total number of nodes in the fragment
15    pub(crate) node_count: usize,
16    /// Number of currently active nodes
17    pub(crate) active_node_count: usize,
18    /// Number of worker threads available
19    pub(crate) worker_count: usize,
20    /// Number of queued tasks
21    pub(crate) queued_task_count: usize,
22    /// Number of active tasks
23    pub(crate) active_task_count: usize,
24}
25
26/// Statistics about task execution
27#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)]
28#[cfg_attr(
29    feature = "serde",
30    derive(serde_derive::Deserialize, serde_derive::Serialize),
31    serde(rename_all = "snake_case")
32)]
33pub struct ExecutionStats {
34    /// Total tasks completed
35    pub(crate) completed_tasks: usize,
36    /// Total tasks that failed
37    pub(crate) failed_tasks: usize,
38    /// Average execution time in milliseconds
39    pub(crate) avg_execution_time_ms: f32,
40    /// Number of tasks currently running
41    pub(crate) active_tasks: usize,
42}
43
44impl ExecutionStats {
45    /// Create a new execution stats object
46    pub fn new() -> Self {
47        ExecutionStats::default()
48    }
49    /// returns a mutable reference to the active tasks
50    pub const fn active_tasks_mut(&mut self) -> &mut usize {
51        &mut self.active_tasks
52    }
53    /// return a copy of the average execution time in milliseconds
54    pub const fn avg_execution_time_ms(&self) -> f32 {
55        self.avg_execution_time_ms
56    }
57    /// returns a mutable reference to the average execution time in milliseconds
58    pub const fn avg_execution_time_ms_mut(&mut self) -> &mut f32 {
59        &mut self.avg_execution_time_ms
60    }
61    /// return a copy of the completed tasks
62    pub const fn completed_tasks(&self) -> usize {
63        self.completed_tasks
64    }
65    /// returns a mutable reference to the completed tasks
66    pub const fn completed_tasks_mut(&mut self) -> &mut usize {
67        &mut self.completed_tasks
68    }
69    /// return a copy of the failed tasks
70    pub const fn failed_tasks(&self) -> usize {
71        self.failed_tasks
72    }
73    /// returns a mutable reference to the failed tasks
74    pub const fn failed_tasks_mut(&mut self) -> &mut usize {
75        &mut self.failed_tasks
76    }
77    /// return a copy of the active tasks
78    pub const fn active_tasks(&self) -> usize {
79        self.active_tasks
80    }
81    /// updates the current active tasks and returns a mutable reference to the current
82    /// instance
83    pub fn set_active_tasks(&mut self, active_tasks: usize) -> &mut Self {
84        self.active_tasks = active_tasks;
85        self
86    }
87    /// updates the current average execution time in milliseconds and returns a mutable reference
88    pub fn set_avg_execution_time_ms(&mut self, avg_execution_time_ms: f32) -> &mut Self {
89        self.avg_execution_time_ms = avg_execution_time_ms;
90        self
91    }
92    /// updates the current completed tasks and returns a mutable reference to the current instance
93    pub fn set_completed_tasks(&mut self, completed_tasks: usize) -> &mut Self {
94        self.completed_tasks = completed_tasks;
95        self
96    }
97    /// updates the current failed tasks and returns a mutable reference to the current instance
98    pub fn set_failed_tasks(&mut self, failed_tasks: usize) -> &mut Self {
99        self.failed_tasks = failed_tasks;
100        self
101    }
102    /// consumes the current instance to create another with the given active tasks
103    pub fn with_active_tasks(self, active_tasks: usize) -> Self {
104        Self {
105            active_tasks,
106            ..self
107        }
108    }
109    /// consumes the current instance to create another with the given average execution time in milliseconds
110    pub fn with_avg_execution_time_ms(self, avg_execution_time_ms: f32) -> Self {
111        Self {
112            avg_execution_time_ms,
113            ..self
114        }
115    }
116    /// consumes the current instance to create another with the given completed tasks
117    pub fn with_completed_tasks(self, completed_tasks: usize) -> Self {
118        Self {
119            completed_tasks,
120            ..self
121        }
122    }
123    /// consumes the current instance to create another with the given failed tasks
124    pub fn with_failed_tasks(self, failed_tasks: usize) -> Self {
125        Self {
126            failed_tasks,
127            ..self
128        }
129    }
130}
131
132impl RuntimeStats {
133    /// Create a new runtime stats object
134    pub fn new() -> Self {
135        RuntimeStats::default()
136    }
137    /// return a copy of the active node count
138    pub const fn active_node_count(&self) -> usize {
139        self.active_node_count
140    }
141    /// returns a mutable reference to the active node count
142    pub const fn active_node_count_mut(&mut self) -> &mut usize {
143        &mut self.active_node_count
144    }
145    /// return a copy of the active task count
146    pub const fn active_task_count(&self) -> usize {
147        self.active_task_count
148    }
149    /// returns a mutable reference to the active task count
150    pub const fn active_task_count_mut(&mut self) -> &mut usize {
151        &mut self.active_task_count
152    }
153    /// return a copy of the node count
154    pub const fn node_count(&self) -> usize {
155        self.node_count
156    }
157    /// returns a mutable reference to the node count
158    pub const fn node_count_mut(&mut self) -> &mut usize {
159        &mut self.node_count
160    }
161    /// return a copy of the queued task count
162    pub const fn queued_task_count(&self) -> usize {
163        self.queued_task_count
164    }
165    /// returns a mutable reference to the queued task count
166    pub const fn queued_task_count_mut(&mut self) -> &mut usize {
167        &mut self.queued_task_count
168    }
169    /// return a copy of the worker count
170    pub const fn worker_count(&self) -> usize {
171        self.worker_count
172    }
173    /// returns a mutable reference to the worker count
174    pub const fn worker_count_mut(&mut self) -> &mut usize {
175        &mut self.worker_count
176    }
177    /// updates the current active node count and returns a mutable reference to the current
178    ///  instance
179    pub fn set_active_node_count(&mut self, active_node_count: usize) -> &mut Self {
180        self.active_node_count = active_node_count;
181        self
182    }
183    /// updates the current active task count and returns a mutable reference to the current
184    /// instance
185    pub fn set_active_task_count(&mut self, active_task_count: usize) -> &mut Self {
186        self.active_task_count = active_task_count;
187        self
188    }
189    /// updates the current node count and returns a mutable reference to the current instance
190    pub fn set_node_count(&mut self, node_count: usize) -> &mut Self {
191        self.node_count = node_count;
192        self
193    }
194    /// updates the current queued task count and returns a mutable reference to the current
195    /// instance
196    pub fn set_queued_task_count(&mut self, queued_task_count: usize) -> &mut Self {
197        self.queued_task_count = queued_task_count;
198        self
199    }
200    /// updates the current worker count and returns a mutable reference to the current instance
201    pub fn set_worker_count(&mut self, worker_count: usize) -> &mut Self {
202        self.worker_count = worker_count;
203        self
204    }
205
206    // "with_" methods (alphabetically ordered)
207    /// consumes the current instance to create another with the given active node count
208    pub fn with_active_node_count(self, active_node_count: usize) -> Self {
209        Self {
210            active_node_count,
211            ..self
212        }
213    }
214    /// consumes the current instance to create another with the given active task count
215    pub fn with_active_task_count(self, active_task_count: usize) -> Self {
216        Self {
217            active_task_count,
218            ..self
219        }
220    }
221    /// consumes the current instance to create another with the given node count
222    pub fn with_node_count(self, node_count: usize) -> Self {
223        Self { node_count, ..self }
224    }
225    /// consumes the current instance to create another with the given queued task count
226    pub fn with_queued_task_count(self, queued_task_count: usize) -> Self {
227        Self {
228            queued_task_count,
229            ..self
230        }
231    }
232    /// consumes the current instance to create another with the given worker count
233    pub fn with_worker_count(self, worker_count: usize) -> Self {
234        Self {
235            worker_count,
236            ..self
237        }
238    }
239}