rsiot/executor/tokio_runtime_metrics.rs
1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5/// Метрики tokio
6#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
7pub struct TokioRuntimeMetrics {
8 /// The number of worker threads used by the runtime.
9 ///
10 /// Ссылка: [`tokio_metrics::RuntimeMetrics::workers_count`]
11 pub workers_count: usize,
12
13 /// The number of times worker threads parked.
14 ///
15 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_park_count`]
16 pub total_park_count: u64,
17
18 /// The maximum number of times any worker thread parked.
19 ///
20 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_park_count`]
21 pub max_park_count: u64,
22
23 /// The minimum number of times any worker thread parked.
24 ///
25 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_park_count`]
26 pub min_park_count: u64,
27
28 /// The amount of time worker threads were busy.
29 ///
30 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_busy_duration`]
31 pub total_busy_duration: Duration,
32
33 /// The maximum amount of time a worker thread was busy.
34 ///
35 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_busy_duration`]
36 pub max_busy_duration: Duration,
37
38 /// The minimum amount of time a worker thread was busy.
39 ///
40 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_busy_duration`]
41 pub min_busy_duration: Duration,
42
43 /// The number of tasks currently scheduled in the runtime's global queue.
44 ///
45 /// Ссылка: [`tokio_metrics::RuntimeMetrics::global_queue_depth`]
46 pub global_queue_depth: usize,
47
48 /// Total amount of time elapsed since observing runtime metrics.
49 ///
50 /// Ссылка: [`tokio_metrics::RuntimeMetrics::elapsed`]
51 pub elapsed: Duration,
52
53 /// The average duration of a single invocation of poll on a task.
54 ///
55 /// Ссылка: [`tokio_metrics::RuntimeMetrics::mean_poll_duration`]
56 pub mean_poll_duration: Duration,
57
58 /// The average duration of a single invocation of poll on a task on the worker with the lowest
59 /// value.
60 ///
61 /// Ссылка: [`tokio_metrics::RuntimeMetrics::mean_poll_duration_worker_min`]
62 pub mean_poll_duration_worker_min: Duration,
63
64 /// The average duration of a single invocation of poll on a task on the worker with the highest
65 /// value.
66 ///
67 /// Ссылка: [`tokio_metrics::RuntimeMetrics::mean_poll_duration_worker_max`]
68 pub mean_poll_duration_worker_max: Duration,
69
70 /// A histogram of task polls since the previous probe grouped by poll times.
71 pub poll_time_histogram: Vec<u64>,
72
73 /// The number of times worker threads unparked but performed no work before parking again.
74 ///
75 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_noop_count`]
76 pub total_noop_count: u64,
77
78 /// The maximum number of times any worker thread unparked but performed no work before parking
79 /// again.
80 ///
81 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_noop_count`]
82 pub max_noop_count: u64,
83
84 /// The minimum number of times any worker thread unparked but performed no work before parking
85 /// again.
86 ///
87 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_noop_count`]
88 pub min_noop_count: u64,
89
90 /// The number of tasks worker threads stole from another worker thread.
91 ///
92 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_steal_count`]
93 pub total_steal_count: u64,
94
95 /// The maximum number of tasks any worker thread stole from another worker thread.
96 ///
97 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_steal_count`]
98 pub max_steal_count: u64,
99
100 /// The minimum number of tasks any worker thread stole from another worker thread.
101 ///
102 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_steal_count`]
103 pub min_steal_count: u64,
104
105 /// The number of times worker threads stole tasks from another worker thread.
106 ///
107 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_steal_operations`]
108 pub total_steal_operations: u64,
109
110 /// The maximum number of times any worker thread stole tasks from another worker thread.
111 ///
112 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_steal_operations`]
113 pub max_steal_operations: u64,
114
115 /// The minimum number of times any worker thread stole tasks from another worker thread.
116 ///
117 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_steal_operations`]
118 pub min_steal_operations: u64,
119
120 /// The number of tasks scheduled from **outside** of the runtime.
121 ///
122 /// Ссылка: [`tokio_metrics::RuntimeMetrics::num_remote_schedules`]
123 pub num_remote_schedules: u64,
124
125 /// The number of tasks scheduled from worker threads.
126 ///
127 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_local_schedule_count`]
128 pub total_local_schedule_count: u64,
129
130 /// The maximum number of tasks scheduled from any one worker thread.
131 ///
132 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_local_schedule_count`]
133 pub max_local_schedule_count: u64,
134
135 /// The minimum number of tasks scheduled from any one worker thread.
136 ///
137 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_local_schedule_count`]
138 pub min_local_schedule_count: u64,
139
140 /// The number of times worker threads saturated their local queues.
141 ///
142 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_overflow_count`]
143 pub total_overflow_count: u64,
144
145 /// The maximum number of times any one worker saturated its local queue.
146 ///
147 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_overflow_count`]
148 pub max_overflow_count: u64,
149
150 /// The minimum number of times any one worker saturated its local queue.
151 ///
152 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_overflow_count`]
153 pub min_overflow_count: u64,
154
155 /// The number of tasks that have been polled across all worker threads.
156 ///
157 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_polls_count`]
158 pub total_polls_count: u64,
159
160 /// The maximum number of tasks that have been polled in any worker thread.
161 ///
162 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_polls_count`]
163 pub max_polls_count: u64,
164
165 /// The minimum number of tasks that have been polled in any worker thread.
166 ///
167 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_polls_count`]
168 pub min_polls_count: u64,
169
170 /// The total number of tasks currently scheduled in workers' local queues.
171 ///
172 /// Ссылка: [`tokio_metrics::RuntimeMetrics::total_local_queue_depth`]
173 pub total_local_queue_depth: usize,
174
175 /// The maximum number of tasks currently scheduled any worker's local queue.
176 ///
177 /// Ссылка: [`tokio_metrics::RuntimeMetrics::max_local_queue_depth`]
178 pub max_local_queue_depth: usize,
179
180 /// The minimum number of tasks currently scheduled any worker's local queue.
181 ///
182 /// Ссылка: [`tokio_metrics::RuntimeMetrics::min_local_queue_depth`]
183 pub min_local_queue_depth: usize,
184
185 /// The number of tasks currently waiting to be executed in the runtime's blocking threadpool.
186 ///
187 /// Ссылка: [`tokio_metrics::RuntimeMetrics::blocking_queue_depth`]
188 pub blocking_queue_depth: usize,
189
190 /// The current number of alive tasks in the runtime.
191 ///
192 /// Ссылка: [`tokio_metrics::RuntimeMetrics::live_tasks_count`]
193 pub live_tasks_count: usize,
194
195 /// The number of additional threads spawned by the runtime.
196 ///
197 /// Ссылка: [`tokio_metrics::RuntimeMetrics::blocking_threads_count`]
198 pub blocking_threads_count: usize,
199
200 /// The number of idle threads, which have spawned by the runtime for `spawn_blocking` calls.
201 ///
202 /// Ссылка: [`tokio_metrics::RuntimeMetrics::idle_blocking_threads_count`]
203 pub idle_blocking_threads_count: usize,
204
205 /// Returns the number of times that tasks have been forced to yield back to the scheduler after
206 /// exhausting their task budgets.
207 ///
208 /// Ссылка: [`tokio_metrics::RuntimeMetrics::budget_forced_yield_count`]
209 pub budget_forced_yield_count: u64,
210
211 /// Returns the number of ready events processed by the runtime’s I/O driver.
212 ///
213 /// Ссылка: [`tokio_metrics::RuntimeMetrics::io_driver_ready_count`]
214 pub io_driver_ready_count: u64,
215
216 /// Returns the ratio of the `total_polls_count` to the `total_noop_count`.
217 pub mean_polls_per_park: f64,
218
219 /// Returns the ratio of the `total_busy_duration` to the `elapsed`.
220 pub busy_ratio: f64,
221}
222
223#[cfg(feature = "log_tokio")]
224impl From<tokio_metrics::RuntimeMetrics> for TokioRuntimeMetrics {
225 fn from(value: tokio_metrics::RuntimeMetrics) -> Self {
226 Self {
227 workers_count: value.workers_count,
228 total_park_count: value.total_park_count,
229 max_park_count: value.max_park_count,
230 min_park_count: value.min_park_count,
231 total_busy_duration: value.total_busy_duration,
232 max_busy_duration: value.max_busy_duration,
233 min_busy_duration: value.min_busy_duration,
234 global_queue_depth: value.global_queue_depth,
235 elapsed: value.elapsed,
236 mean_poll_duration: value.mean_poll_duration,
237 mean_poll_duration_worker_min: value.mean_poll_duration_worker_min,
238 mean_poll_duration_worker_max: value.mean_poll_duration_worker_max,
239 poll_time_histogram: value.poll_time_histogram.as_counts().clone(),
240 total_noop_count: value.total_noop_count,
241 max_noop_count: value.max_noop_count,
242 min_noop_count: value.min_noop_count,
243 total_steal_count: value.total_steal_count,
244 max_steal_count: value.max_steal_count,
245 min_steal_count: value.min_steal_count,
246 total_steal_operations: value.total_steal_operations,
247 max_steal_operations: value.max_steal_operations,
248 min_steal_operations: value.min_steal_operations,
249 num_remote_schedules: value.num_remote_schedules,
250 total_local_schedule_count: value.total_local_schedule_count,
251 max_local_schedule_count: value.max_local_schedule_count,
252 min_local_schedule_count: value.min_local_schedule_count,
253 total_overflow_count: value.total_overflow_count,
254 max_overflow_count: value.max_overflow_count,
255 min_overflow_count: value.min_overflow_count,
256 total_polls_count: value.total_polls_count,
257 max_polls_count: value.max_polls_count,
258 min_polls_count: value.min_polls_count,
259 total_local_queue_depth: value.total_local_queue_depth,
260 max_local_queue_depth: value.max_local_queue_depth,
261 min_local_queue_depth: value.min_local_queue_depth,
262 blocking_queue_depth: value.blocking_queue_depth,
263 live_tasks_count: value.live_tasks_count,
264 blocking_threads_count: value.blocking_threads_count,
265 idle_blocking_threads_count: value.idle_blocking_threads_count,
266 budget_forced_yield_count: value.budget_forced_yield_count,
267 io_driver_ready_count: value.io_driver_ready_count,
268 mean_polls_per_park: value.mean_polls_per_park(),
269 busy_ratio: value.busy_ratio(),
270 }
271 }
272}