seismograph_rallocator 0.1.0

Rallocator snapshot source for seismograph.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Rallocator snapshot model types.

/// Version of the snapshot producer.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Version {
    /// Major producer version.
    pub major: u16,
    /// Minor producer version.
    pub minor: u16,
    /// Patch producer version.
    pub patch: u16,
}

impl Version {
    /// Creates a producer version.
    #[must_use]
    pub const fn new(major: u16, minor: u16, patch: u16) -> Self {
        Self { major, minor, patch }
    }
}

/// A bounded estimate with lower and upper bounds.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Estimate {
    /// Estimated value.
    pub value: u64,
    /// Inclusive lower bound.
    pub lower_bound: u64,
    /// Inclusive upper bound.
    pub upper_bound: u64,
}

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct EstimateFields {
    pub value: u64,
    pub lower_bound: u64,
    pub upper_bound: u64,
}

impl Estimate {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: EstimateFields) -> Self {
        let EstimateFields {
            value,
            lower_bound,
            upper_bound,
        } = fields;
        Self {
            value,
            lower_bound,
            upper_bound,
        }
    }
}

/// Process-wide allocator counters.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Stats {
    /// Cumulative requested bytes allocated.
    pub allocated_bytes: u64,
    /// Cumulative requested bytes deallocated.
    pub deallocated_bytes: u64,
    /// Currently live requested bytes.
    pub live_bytes: u64,
    /// Highest observed live requested bytes.
    pub peak_live_bytes: u64,
    /// Currently mapped allocator bytes.
    pub mapped_bytes: u64,
    /// Operating-system mappings performed.
    pub os_mappings: u64,
    /// Operating-system unmappings performed.
    pub os_unmappings: u64,
    /// Successful allocation operations.
    pub allocations: u64,
    /// Deallocation operations.
    pub deallocations: u64,
    /// Cross-thread deallocation operations.
    pub remote_frees: u64,
    /// Remote blocks awaiting reclamation.
    pub pending_remote_blocks: u64,
    /// Remote push operations in progress.
    pub remote_pushes_in_progress: u64,
    /// Remote blocks reclaimed by owners.
    pub drained_remote_blocks: u64,
}

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct StatsFields {
    pub allocated_bytes: u64,
    pub deallocated_bytes: u64,
    pub live_bytes: u64,
    pub peak_live_bytes: u64,
    pub mapped_bytes: u64,
    pub os_mappings: u64,
    pub os_unmappings: u64,
    pub allocations: u64,
    pub deallocations: u64,
    pub remote_frees: u64,
    pub pending_remote_blocks: u64,
    pub remote_pushes_in_progress: u64,
    pub drained_remote_blocks: u64,
}

impl Stats {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: StatsFields) -> Self {
        let StatsFields {
            allocated_bytes,
            deallocated_bytes,
            live_bytes,
            peak_live_bytes,
            mapped_bytes,
            os_mappings,
            os_unmappings,
            allocations,
            deallocations,
            remote_frees,
            pending_remote_blocks,
            remote_pushes_in_progress,
            drained_remote_blocks,
        } = fields;
        Self {
            allocated_bytes,
            deallocated_bytes,
            live_bytes,
            peak_live_bytes,
            mapped_bytes,
            os_mappings,
            os_unmappings,
            allocations,
            deallocations,
            remote_frees,
            pending_remote_blocks,
            remote_pushes_in_progress,
            drained_remote_blocks,
        }
    }
}

/// Statistics for one allocation size class.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct SizeClass {
    /// Allocator-defined size-class index.
    pub class_index: u32,
    /// Usable block size in bytes.
    pub block_bytes: u64,
    /// Live allocation count estimate.
    pub live_allocations: Estimate,
    /// Requested-byte estimate.
    pub requested_bytes: Estimate,
    /// Usable-byte estimate.
    pub usable_bytes: Estimate,
}

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct SizeClassFields {
    pub class_index: u32,
    pub block_bytes: u64,
    pub live_allocations: Estimate,
    pub requested_bytes: Estimate,
    pub usable_bytes: Estimate,
}

impl SizeClass {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: SizeClassFields) -> Self {
        let SizeClassFields {
            class_index,
            block_bytes,
            live_allocations,
            requested_bytes,
            usable_bytes,
        } = fields;
        Self {
            class_index,
            block_bytes,
            live_allocations,
            requested_bytes,
            usable_bytes,
        }
    }
}

/// Aggregate state for one allocator region.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Region {
    /// Region index.
    pub region_index: u32,
    /// Reserved virtual bytes.
    pub reserved_bytes: u64,
    /// Allocator-assigned slices.
    pub used_slices: u64,
    /// Available slices.
    pub free_slices: u64,
}

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct RegionFields {
    pub region_index: u32,
    pub reserved_bytes: u64,
    pub used_slices: u64,
    pub free_slices: u64,
}

impl Region {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: RegionFields) -> Self {
        let RegionFields {
            region_index,
            reserved_bytes,
            used_slices,
            free_slices,
        } = fields;
        Self {
            region_index,
            reserved_bytes,
            used_slices,
            free_slices,
        }
    }
}

/// Allocation-domain aggregate state.
#[non_exhaustive]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Domain {
    /// Process-local domain identifier.
    pub domain_id: u64,
    /// Whether this is the default domain.
    pub is_default: bool,
    /// Number of owned regions.
    pub region_count: u64,
    /// Reserved virtual bytes.
    pub reserved_bytes: u64,
    /// Allocator-assigned slices.
    pub used_slices: u64,
    /// Available slices.
    pub free_slices: u64,
    /// Slices used for small slabs.
    pub small_slices: u64,
    /// Slices used for medium spans.
    pub medium_slices: u64,
    /// Slices used for bump heaps.
    pub bump_slices: u64,
    /// Assigned slices without a stable classification.
    pub unknown_slices: u64,
    /// Indices of owned regions.
    pub region_indices: Vec<u32>,
}

#[doc(hidden)]
#[derive(Debug)]
pub struct DomainFields {
    pub domain_id: u64,
    pub is_default: bool,
    pub region_count: u64,
    pub reserved_bytes: u64,
    pub used_slices: u64,
    pub free_slices: u64,
    pub small_slices: u64,
    pub medium_slices: u64,
    pub bump_slices: u64,
    pub unknown_slices: u64,
    pub region_indices: Vec<u32>,
}

impl Domain {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: DomainFields) -> Self {
        let DomainFields {
            domain_id,
            is_default,
            region_count,
            reserved_bytes,
            used_slices,
            free_slices,
            small_slices,
            medium_slices,
            bump_slices,
            unknown_slices,
            region_indices,
        } = fields;
        Self {
            domain_id,
            is_default,
            region_count,
            reserved_bytes,
            used_slices,
            free_slices,
            small_slices,
            medium_slices,
            bump_slices,
            unknown_slices,
            region_indices,
        }
    }
}

/// Allocation-size histograms.
#[non_exhaustive]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Histograms {
    /// Counts of allocated sizes by bucket.
    pub allocated: Vec<u64>,
    /// Counts of live sizes by bucket.
    pub live: Vec<u64>,
}

#[doc(hidden)]
#[derive(Debug)]
pub struct HistogramsFields {
    pub allocated: Vec<u64>,
    pub live: Vec<u64>,
}

impl Histograms {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: HistogramsFields) -> Self {
        let HistogramsFields { allocated, live } = fields;
        Self { allocated, live }
    }
}

/// Metadata associated with a snapshot.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Metadata {
    /// Version of the enclosing wire format.
    pub wire_format_version: u16,
    /// Version of the decoded telemetry schema.
    pub telemetry_schema_version: u16,
    /// Version of the snapshot producer.
    pub producer_version: Version,
    /// Time spent collecting the snapshot.
    pub capture_duration_nanos: u64,
}

/// A snapshot section skipped because its identifier is unknown or its version is older or newer
/// than the versions supported by this decoder.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SkippedSection {
    /// Wire section identifier.
    pub id: u16,
    /// Version reported by the skipped section.
    pub version: u16,
}

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct SkippedSectionFields {
    pub id: u16,
    pub version: u16,
}

impl SkippedSection {
    #[doc(hidden)]
    #[must_use]
    pub fn from_fields(fields: SkippedSectionFields) -> Self {
        let SkippedSectionFields { id, version } = fields;
        Self { id, version }
    }
}

/// Complete owned allocator telemetry snapshot.
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Snapshot {
    /// Snapshot metadata.
    pub metadata: Metadata,
    /// Process-wide allocator statistics.
    pub stats: Stats,
    /// Per-size-class statistics.
    pub size_classes: Vec<SizeClass>,
    /// Aggregate region statistics.
    pub regions: Vec<Region>,
    /// Physical allocator topology.
    pub topology: Vec<crate::topology::TopologyRegion>,
    /// Allocation-domain statistics.
    pub domains: Vec<Domain>,
    /// Retained caller data, when captured.
    pub callers: Option<crate::callers::Callers>,
    /// Retained ownership and synchronization events, when captured.
    pub runtime_events: Option<seismograph::recorder::event::Events>,
    /// Allocation-size histograms.
    pub histograms: Histograms,
    /// Symbol information for caller addresses.
    pub addresses: Vec<crate::callers::AddressLookup>,
    /// Sections skipped because their identifiers were unknown or their versions were unsupported.
    pub skipped_sections: Vec<SkippedSection>,
}

impl Snapshot {
    /// Creates an empty snapshot for `producer_version`.
    #[must_use]
    pub fn new(producer_version: Version) -> Self {
        Self {
            metadata: Metadata {
                wire_format_version: crate::wire::format::Header::new(1, producer_version).wire_format(),
                telemetry_schema_version: crate::TELEMETRY_SCHEMA_VERSION,
                producer_version,
                capture_duration_nanos: 0,
            },
            stats: Stats::default(),
            size_classes: Vec::new(),
            regions: Vec::new(),
            topology: Vec::new(),
            domains: Vec::new(),
            callers: None,
            runtime_events: None,
            histograms: Histograms::default(),
            addresses: Vec::new(),
            skipped_sections: Vec::new(),
        }
    }
}