1use crate::{AnchorId, Key, ScopeId};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6pub struct SlotTableLocalDebugStats {
7 pub group_count: usize,
9 pub group_capacity: usize,
11 pub group_record_size: usize,
13 pub group_heap_bytes: usize,
15 pub payload_count: usize,
17 pub payload_capacity: usize,
19 pub active_payload_anchor_count: usize,
21 pub payload_anchor_slot_count: usize,
23 pub detached_payload_anchor_count: usize,
25 pub invalidated_payload_anchor_count: usize,
27 pub free_payload_anchor_count: usize,
29 pub payload_anchor_capacity: usize,
31 pub payload_anchor_heap_bytes: usize,
33 pub node_count: usize,
35 pub node_capacity: usize,
37 pub active_anchor_count: usize,
39 pub anchor_slot_count: usize,
41 pub detached_anchor_count: usize,
43 pub invalidated_anchor_count: usize,
45 pub free_anchor_count: usize,
47 pub anchor_capacity: usize,
49 pub anchor_heap_bytes: usize,
51 #[cfg(any(test, feature = "leak-debug"))]
53 pub mutation: SlotTableMutationDebugStats,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57pub(crate) struct SlotLifecycleDebugStats {
58 pub pending_drop_count: usize,
59 pub pending_drop_capacity: usize,
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
65pub struct SlotRetentionDebugStats {
66 pub retained_subtree_count: usize,
68 pub retained_group_count: usize,
70 pub retained_payload_count: usize,
72 pub retained_node_count: usize,
74 pub retained_scope_count: usize,
76 pub retained_anchor_count: usize,
78 pub retained_heap_bytes: usize,
80 pub retained_evictions_total: usize,
82}
83
84#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88pub struct SlotTableDebugStats {
89 pub group_count: usize,
91 pub group_capacity: usize,
93 pub group_record_size: usize,
95 pub group_heap_bytes: usize,
97 pub payload_count: usize,
99 pub payload_capacity: usize,
101 pub active_payload_anchor_count: usize,
103 pub payload_anchor_slot_count: usize,
105 pub detached_payload_anchor_count: usize,
107 pub invalidated_payload_anchor_count: usize,
109 pub free_payload_anchor_count: usize,
111 pub payload_anchor_capacity: usize,
113 pub payload_anchor_heap_bytes: usize,
115 pub node_count: usize,
117 pub node_capacity: usize,
119 pub pending_drop_count: usize,
121 pub pending_drop_capacity: usize,
123 pub active_anchor_count: usize,
125 pub anchor_slot_count: usize,
127 pub detached_anchor_count: usize,
129 pub invalidated_anchor_count: usize,
131 pub free_anchor_count: usize,
133 pub anchor_capacity: usize,
135 pub anchor_heap_bytes: usize,
137 pub retained_subtree_count: usize,
139 pub retained_group_count: usize,
141 pub retained_payload_count: usize,
143 pub retained_node_count: usize,
145 pub retained_scope_count: usize,
147 pub retained_anchor_count: usize,
149 pub retained_heap_bytes: usize,
151 pub retained_evictions_total: usize,
153 #[cfg(any(test, feature = "leak-debug"))]
155 pub mutation: SlotTableMutationDebugStats,
156}
157
158impl SlotTableDebugStats {
159 pub(crate) fn from_parts(
160 local: SlotTableLocalDebugStats,
161 lifecycle: SlotLifecycleDebugStats,
162 retention: SlotRetentionDebugStats,
163 ) -> Self {
164 Self {
165 group_count: local.group_count,
166 group_capacity: local.group_capacity,
167 group_record_size: local.group_record_size,
168 group_heap_bytes: local.group_heap_bytes,
169 payload_count: local.payload_count,
170 payload_capacity: local.payload_capacity,
171 active_payload_anchor_count: local.active_payload_anchor_count,
172 payload_anchor_slot_count: local.payload_anchor_slot_count,
173 detached_payload_anchor_count: local.detached_payload_anchor_count,
174 invalidated_payload_anchor_count: local.invalidated_payload_anchor_count,
175 free_payload_anchor_count: local.free_payload_anchor_count,
176 payload_anchor_capacity: local.payload_anchor_capacity,
177 payload_anchor_heap_bytes: local.payload_anchor_heap_bytes,
178 node_count: local.node_count,
179 node_capacity: local.node_capacity,
180 pending_drop_count: lifecycle.pending_drop_count,
181 pending_drop_capacity: lifecycle.pending_drop_capacity,
182 active_anchor_count: local.active_anchor_count,
183 anchor_slot_count: local.anchor_slot_count,
184 detached_anchor_count: local.detached_anchor_count,
185 invalidated_anchor_count: local.invalidated_anchor_count,
186 free_anchor_count: local.free_anchor_count,
187 anchor_capacity: local.anchor_capacity,
188 anchor_heap_bytes: local.anchor_heap_bytes,
189 retained_subtree_count: retention.retained_subtree_count,
190 retained_group_count: retention.retained_group_count,
191 retained_payload_count: retention.retained_payload_count,
192 retained_node_count: retention.retained_node_count,
193 retained_scope_count: retention.retained_scope_count,
194 retained_anchor_count: retention.retained_anchor_count,
195 retained_heap_bytes: retention.retained_heap_bytes,
196 retained_evictions_total: retention.retained_evictions_total,
197 #[cfg(any(test, feature = "leak-debug"))]
198 mutation: local.mutation,
199 }
200 }
201}
202
203#[cfg(any(test, feature = "leak-debug"))]
207#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
208pub struct SlotTableMutationDebugStats {
209 pub subtree_move_count: usize,
211 pub moved_group_count: usize,
213 pub moved_group_max_span: usize,
215 pub moved_payload_count: usize,
217 pub moved_payload_max_span: usize,
219 pub moved_node_count: usize,
221 pub moved_node_max_span: usize,
223 pub payload_location_range_refresh_count: usize,
225 pub payload_location_range_refresh_group_count: usize,
227 pub payload_location_range_refresh_group_max_span: usize,
229 pub payload_location_range_refresh_payload_count: usize,
231 pub payload_location_range_refresh_payload_max_span: usize,
233 pub payload_location_refresh_count: usize,
235 pub payload_location_refresh_payload_count: usize,
237 pub payload_location_refresh_max_span: usize,
239 pub group_index_refresh_count: usize,
241 pub group_index_refresh_group_count: usize,
243 pub group_index_refresh_max_span: usize,
245 pub segment_range_update_count: usize,
247 pub segment_range_update_group_count: usize,
249 pub segment_range_update_max_span: usize,
251 pub payload_shift_bytes: usize,
254}
255
256#[cfg(any(test, feature = "leak-debug"))]
259pub(crate) type SlotTableDiagnostics = SlotTableMutationDebugStats;
260
261#[cfg(not(any(test, feature = "leak-debug")))]
262#[derive(Default)]
263pub(crate) struct SlotTableDiagnostics;
264
265#[cfg(not(any(test, feature = "leak-debug")))]
266impl SlotTableDiagnostics {
267 pub(crate) fn record_subtree_move(&mut self, _groups: usize, _payloads: usize, _nodes: usize) {}
268
269 pub(crate) fn record_payload_location_range_refresh(
270 &mut self,
271 _groups: usize,
272 _payloads: usize,
273 ) {
274 }
275
276 pub(crate) fn record_group_index_refresh(&mut self, _groups: usize) {}
277
278 pub(crate) fn record_payload_location_refresh(&mut self, _payloads: usize) {}
279
280 pub(crate) fn record_segment_range_update(&mut self, _groups: usize) {}
281}
282
283#[cfg(any(test, feature = "leak-debug"))]
284impl SlotTableMutationDebugStats {
285 pub(crate) fn record_subtree_move(
286 &mut self,
287 group_span: usize,
288 payload_span: usize,
289 node_span: usize,
290 ) {
291 self.subtree_move_count = self.subtree_move_count.saturating_add(1);
292 self.moved_group_count = self.moved_group_count.saturating_add(group_span);
293 self.moved_group_max_span = self.moved_group_max_span.max(group_span);
294 self.moved_payload_count = self.moved_payload_count.saturating_add(payload_span);
295 self.moved_payload_max_span = self.moved_payload_max_span.max(payload_span);
296 self.moved_node_count = self.moved_node_count.saturating_add(node_span);
297 self.moved_node_max_span = self.moved_node_max_span.max(node_span);
298 }
299
300 pub(crate) fn record_payload_location_range_refresh(
301 &mut self,
302 group_span: usize,
303 payload_span: usize,
304 ) {
305 self.payload_location_range_refresh_count =
306 self.payload_location_range_refresh_count.saturating_add(1);
307 self.payload_location_range_refresh_group_count = self
308 .payload_location_range_refresh_group_count
309 .saturating_add(group_span);
310 self.payload_location_range_refresh_group_max_span = self
311 .payload_location_range_refresh_group_max_span
312 .max(group_span);
313 self.payload_location_range_refresh_payload_count = self
314 .payload_location_range_refresh_payload_count
315 .saturating_add(payload_span);
316 self.payload_location_range_refresh_payload_max_span = self
317 .payload_location_range_refresh_payload_max_span
318 .max(payload_span);
319 }
320
321 pub(crate) fn record_group_index_refresh(&mut self, group_span: usize) {
322 self.group_index_refresh_count = self.group_index_refresh_count.saturating_add(1);
323 self.group_index_refresh_group_count = self
324 .group_index_refresh_group_count
325 .saturating_add(group_span);
326 self.group_index_refresh_max_span = self.group_index_refresh_max_span.max(group_span);
327 }
328
329 pub(crate) fn record_payload_location_refresh(&mut self, payload_span: usize) {
330 self.payload_location_refresh_count = self.payload_location_refresh_count.saturating_add(1);
331 self.payload_location_refresh_payload_count = self
332 .payload_location_refresh_payload_count
333 .saturating_add(payload_span);
334 self.payload_location_refresh_max_span =
335 self.payload_location_refresh_max_span.max(payload_span);
336 }
337
338 pub(crate) fn record_segment_range_update(&mut self, group_span: usize) {
339 self.segment_range_update_count = self.segment_range_update_count.saturating_add(1);
340 self.segment_range_update_group_count = self
341 .segment_range_update_group_count
342 .saturating_add(group_span);
343 self.segment_range_update_max_span = self.segment_range_update_max_span.max(group_span);
344 }
345}
346
347#[derive(Debug, Clone, Copy, PartialEq, Eq)]
349pub enum SlotDebugEntryKind {
350 Group,
352 Payload,
354 Node,
356}
357
358#[derive(Debug, Clone, PartialEq, Eq)]
360pub struct SlotDebugEntry {
361 pub kind: SlotDebugEntryKind,
363 pub path: String,
365 pub line: String,
367}
368
369#[derive(Debug, Clone, PartialEq, Eq, Default)]
371pub struct SlotDebugSnapshot {
372 pub active_groups: Vec<SlotDebugGroup>,
374 pub anchors: Vec<SlotDebugAnchor>,
376 pub scopes: Vec<SlotDebugScope>,
378 pub active_payload_count: usize,
380 pub active_node_count: usize,
382 pub active_scope_count: usize,
384 pub retained_subtree_count: usize,
386 pub retained_group_count: usize,
388 pub retained_payload_count: usize,
390 pub retained_node_count: usize,
392 pub retained_scope_count: usize,
394}
395
396#[derive(Debug, Clone, Copy, PartialEq, Eq)]
398pub struct SlotDebugGroup {
399 pub index: usize,
401 pub anchor: AnchorId,
403 pub parent_anchor: AnchorId,
405 pub static_key: Key,
407 pub explicit_key: Option<Key>,
409 pub ordinal: u32,
412 pub scope_id: Option<ScopeId>,
414 pub depth: u32,
416 pub subtree_len: u32,
418 pub payload_len: usize,
420 pub node_len: usize,
422 pub subtree_node_count: u32,
424}
425
426#[derive(Debug, Clone, Copy, PartialEq, Eq)]
428pub struct SlotDebugAnchor {
429 pub anchor: AnchorId,
431 pub group_index: usize,
433}
434
435#[derive(Debug, Clone, Copy, PartialEq, Eq)]
437pub struct SlotDebugScope {
438 pub scope_id: ScopeId,
440 pub anchor: AnchorId,
442 pub group_index: usize,
444}