eryon_rt/types/
metrics.rs

1/*
2    Appellation: metrics <module>
3    Contrib: @FL03
4*/
5/// Resource metrics for a node
6#[derive(Clone, Debug, Default, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8pub struct ResourceMetrics<T = f32> {
9    /// Available memory in MB
10    pub(crate) available_memory: usize,
11    /// Available computational resources (0-100)
12    pub(crate) available_compute: usize,
13    pub(crate) capabilities: Vec<String>,
14    pub(crate) cpu_usage: T,
15    pub(crate) edge_count: usize,
16    pub(crate) feature_count: usize,
17    pub(crate) learning_nodes: usize,
18    pub(crate) memory_usage: T,
19    pub(crate) partition_count: usize,
20    pub(crate) queued_tasks: usize,
21    pub(crate) running_tasks: usize,
22    pub(crate) surface_network_count: usize,
23    pub(crate) vertex_count: usize,
24}
25
26impl<T> ResourceMetrics<T> {
27    pub fn new() -> Self
28    where
29        T: Default,
30    {
31        Self::default()
32    }
33    /// returns an immutable reference to the runtimes capabilities
34    pub const fn capabilities(&self) -> &Vec<String> {
35        &self.capabilities
36    }
37    /// returns a mutable reference to the runtimes capabilities
38    pub const fn capabilities_mut(&mut self) -> &mut Vec<String> {
39        &mut self.capabilities
40    }
41    /// returns a copy of the available compute
42    pub const fn available_compute(&self) -> usize {
43        self.available_compute
44    }
45    /// returns a mutable reference to the available compute
46    pub const fn available_compute_mut(&mut self) -> &mut usize {
47        &mut self.available_compute
48    }
49    /// returns a copy of the available memory
50    pub const fn available_memory(&self) -> usize {
51        self.available_memory
52    }
53    /// returns a mutable reference to the available memory
54    pub const fn available_memory_mut(&mut self) -> &mut usize {
55        &mut self.available_memory
56    }
57    /// returns a copy of the cpu usage
58    pub const fn cpu_usage(&self) -> &T {
59        &self.cpu_usage
60    }
61    /// returns a mutable reference to the cpu usage
62    pub const fn cpu_usage_mut(&mut self) -> &mut T {
63        &mut self.cpu_usage
64    }
65    /// returns a copy of the edge count
66    pub const fn edge_count(&self) -> usize {
67        self.edge_count
68    }
69    /// returns a mutable reference to the edge count
70    pub const fn edge_count_mut(&mut self) -> &mut usize {
71        &mut self.edge_count
72    }
73    /// returns a copy of the feature count
74    pub const fn feature_count(&self) -> usize {
75        self.feature_count
76    }
77    /// returns a mutable reference to the feature count
78    pub const fn feature_count_mut(&mut self) -> &mut usize {
79        &mut self.feature_count
80    }
81    /// returns a copy of the learning nodes
82    pub const fn learning_nodes(&self) -> usize {
83        self.learning_nodes
84    }
85    /// returns a mutable reference to the learning nodes
86    pub const fn learning_nodes_mut(&mut self) -> &mut usize {
87        &mut self.learning_nodes
88    }
89    /// returns a copy of the memory usage
90    pub const fn memory_usage(&self) -> &T {
91        &self.memory_usage
92    }
93    /// returns a mutable reference to the memory usage
94    pub const fn memory_usage_mut(&mut self) -> &mut T {
95        &mut self.memory_usage
96    }
97    /// returns a copy of the partition count
98    pub const fn partition_count(&self) -> usize {
99        self.partition_count
100    }
101    /// returns a mutable reference to the partition count
102    pub const fn partition_count_mut(&mut self) -> &mut usize {
103        &mut self.partition_count
104    }
105    /// returns a copy of the queued tasks
106    pub const fn queued_tasks(&self) -> usize {
107        self.queued_tasks
108    }
109    /// returns a mutable reference to the queued tasks
110    pub const fn queued_tasks_mut(&mut self) -> &mut usize {
111        &mut self.queued_tasks
112    }
113    /// returns a copy of the running tasks
114    pub const fn running_tasks(&self) -> usize {
115        self.running_tasks
116    }
117    /// returns a mutable reference to the running tasks
118    pub const fn running_tasks_mut(&mut self) -> &mut usize {
119        &mut self.running_tasks
120    }
121    /// returns a copy of the surface network count
122    pub const fn surface_network_count(&self) -> usize {
123        self.surface_network_count
124    }
125    /// returns a mutable reference to the surface network count
126    pub const fn surface_network_count_mut(&mut self) -> &mut usize {
127        &mut self.surface_network_count
128    }
129    /// returns a copy of the vertex count
130    pub const fn vertex_count(&self) -> usize {
131        self.vertex_count
132    }
133    /// returns a mutable reference to the vertex count
134    pub const fn vertex_count_mut(&mut self) -> &mut usize {
135        &mut self.vertex_count
136    }
137    /// updates the availible compute and returns a mutable reference to the current instance
138    pub fn set_available_compute(&mut self, compute: usize) -> &mut Self {
139        self.available_compute = compute;
140        self
141    }
142    /// updates the available memory and returns a mutable reference to the current instance
143    pub fn set_available_memory(&mut self, memory: usize) -> &mut Self {
144        self.available_memory = memory;
145        self
146    }
147    /// sets the runtimes capabilities
148    pub fn set_capabilities<I>(&mut self, iter: I) -> &mut Self
149    where
150        I: IntoIterator,
151        I::Item: ToString,
152    {
153        self.capabilities = iter.into_iter().map(|x| x.to_string()).collect();
154        self
155    }
156    /// sets the cpu usage and returns a mutable reference to the current instance
157    pub fn set_cpu_usage(&mut self, cpu_usage: T) -> &mut Self {
158        self.cpu_usage = cpu_usage;
159        self
160    }
161    /// sets the edge count and returns a mutable reference to the current instance
162    pub fn set_edge_count(&mut self, edge_count: usize) -> &mut Self {
163        self.edge_count = edge_count;
164        self
165    }
166    /// sets the feature count and returns a mutable reference to the current instance
167    pub fn set_feature_count(&mut self, feature_count: usize) -> &mut Self {
168        self.feature_count = feature_count;
169        self
170    }
171    /// sets the learning nodes and returns a mutable reference to the current instance
172    pub fn set_learning_nodes(&mut self, learning_nodes: usize) -> &mut Self {
173        self.learning_nodes = learning_nodes;
174        self
175    }
176    /// sets the memory usage and returns a mutable reference to the current instance
177    pub fn set_memory_usage(&mut self, memory_usage: T) -> &mut Self {
178        self.memory_usage = memory_usage;
179        self
180    }
181    /// sets the partition count and returns a mutable reference to the current instance
182    pub fn set_partition_count(&mut self, partition_count: usize) -> &mut Self {
183        self.partition_count = partition_count;
184        self
185    }
186    /// sets the queued tasks and returns a mutable reference to the current instance
187    pub fn set_queued_tasks(&mut self, queued_tasks: usize) -> &mut Self {
188        self.queued_tasks = queued_tasks;
189        self
190    }
191    /// sets the running tasks and returns a mutable reference to the current instance
192    pub fn set_running_tasks(&mut self, running_tasks: usize) -> &mut Self {
193        self.running_tasks = running_tasks;
194        self
195    }
196    /// sets the surface network count and returns a mutable reference to the current instance
197    pub fn set_surface_network_count(&mut self, surface_network_count: usize) -> &mut Self {
198        self.surface_network_count = surface_network_count;
199        self
200    }
201    /// sets the vertex count and returns a mutable reference to the current instance
202    pub fn set_vertex_count(&mut self, vertex_count: usize) -> &mut Self {
203        self.vertex_count = vertex_count;
204        self
205    }
206    /// consumes the current instance to create another with the given available compute
207    pub fn with_available_compute(self, compute: usize) -> Self {
208        Self {
209            available_compute: compute,
210            ..self
211        }
212    }
213    /// consumes the current instance to create another with the given available memory
214    pub fn with_available_memory(self, memory: usize) -> Self {
215        Self {
216            available_memory: memory,
217            ..self
218        }
219    }
220    /// consumes the current instance to create another with the given capabilities
221    pub fn with_capabilities<I>(self, iter: I) -> Self
222    where
223        I: IntoIterator,
224        I::Item: ToString,
225    {
226        let capabilities = iter.into_iter().map(|x| x.to_string()).collect::<Vec<_>>();
227        Self {
228            capabilities,
229            ..self
230        }
231    }
232    /// consumes the current instance to create another with the given cpu usage
233    pub fn with_cpu_usage(self, cpu_usage: T) -> Self {
234        Self { cpu_usage, ..self }
235    }
236    /// consumes the current instance to create another with the given edge count
237    pub fn with_edge_count(self, edge_count: usize) -> Self {
238        Self { edge_count, ..self }
239    }
240    /// consumes the current instance to create another with the given feature count
241    pub fn with_feature_count(self, feature_count: usize) -> Self {
242        Self {
243            feature_count,
244            ..self
245        }
246    }
247    /// consumes the current instance to create another with the given learning nodes
248    pub fn with_learning_nodes(self, learning_nodes: usize) -> Self {
249        Self {
250            learning_nodes,
251            ..self
252        }
253    }
254    /// consumes the current instance to create another with the given memory usage
255    pub fn with_memory_usage(self, memory_usage: T) -> Self {
256        Self {
257            memory_usage,
258            ..self
259        }
260    }
261    /// consumes the current instance to create another with the given partition count
262    pub fn with_partition_count(self, partition_count: usize) -> Self {
263        Self {
264            partition_count,
265            ..self
266        }
267    }
268    /// consumes the current instance to create another with the given queued tasks
269    pub fn with_queued_tasks(self, queued_tasks: usize) -> Self {
270        Self {
271            queued_tasks,
272            ..self
273        }
274    }
275    /// consumes the current instance to create another with the given running tasks
276    pub fn with_running_tasks(self, running_tasks: usize) -> Self {
277        Self {
278            running_tasks,
279            ..self
280        }
281    }
282    /// consumes the current instance to create another with the given surface network count
283    pub fn with_surface_network_count(self, surface_network_count: usize) -> Self {
284        Self {
285            surface_network_count,
286            ..self
287        }
288    }
289    /// consumes the current instance to create another with the given vertex count
290    pub fn with_vertex_count(self, vertex_count: usize) -> Self {
291        Self {
292            vertex_count,
293            ..self
294        }
295    }
296}