Skip to main content

euv_performance/allocator/
struct.rs

1use super::*;
2
3/// Zero-sized global allocator delegating directly to `System` with a single-load disabled fast path.
4#[derive(Clone, Copy, Debug, Default)]
5pub struct CountingAllocator;
6
7/// Snapshot of raw monotonic allocation counters captured at a scope boundary.
8#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
9pub struct RawAllocCounters {
10    /// Cumulative allocation count at snapshot time.
11    #[get(type(copy))]
12    pub(crate) alloc_count: u64,
13    /// Cumulative deallocation count at snapshot time.
14    #[get(type(copy))]
15    pub(crate) free_count: u64,
16    /// Cumulative bytes allocated at snapshot time.
17    #[get(type(copy))]
18    pub(crate) bytes_allocated: u64,
19    /// Cumulative bytes freed at snapshot time.
20    #[get(type(copy))]
21    pub(crate) bytes_freed: u64,
22    /// Signed net live bytes delta at snapshot time.
23    #[get(type(copy))]
24    pub(crate) live_bytes_delta: i64,
25    /// Signed net live allocation count delta at snapshot time.
26    #[get(type(copy))]
27    pub(crate) live_allocs_delta: i64,
28    /// Peak positive live bytes delta recorded in the enclosing scope.
29    #[get(type(copy))]
30    pub(crate) peak_live_bytes: u64,
31}
32
33/// Exact heap allocation delta recorded across a measured steady-state frame or workload scope.
34#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
35pub struct AllocationSnapshot {
36    /// Total heap allocation calls (`alloc`, `alloc_zeroed`, `realloc`) in the measured scope.
37    #[get(type(copy))]
38    pub(crate) alloc_count: u64,
39    /// Total heap deallocation calls (`dealloc`, `realloc`) in the measured scope.
40    #[get(type(copy))]
41    pub(crate) free_count: u64,
42    /// Total heap bytes allocated in the measured scope.
43    #[get(type(copy))]
44    pub(crate) bytes_allocated: u64,
45    /// Total heap bytes freed in the measured scope.
46    #[get(type(copy))]
47    pub(crate) bytes_freed: u64,
48    /// Net retained live bytes delta clamped at zero at scope exit.
49    #[get(type(copy))]
50    pub(crate) live_bytes_delta: u64,
51    /// Net retained live allocation delta clamped at zero at scope exit.
52    #[get(type(copy))]
53    pub(crate) live_allocs_delta: u64,
54    /// Peak positive live bytes observed during the measured scope.
55    #[get(type(copy))]
56    pub(crate) peak_live_bytes: u64,
57}
58
59/// RAII scope guard enabling `CountingAllocator` tracking for the lifetime of a benchmark loop.
60#[derive(Debug)]
61pub struct AllocationScopeGuard {
62    /// Mutex guard held by the outermost active scope on this thread.
63    pub(crate) _lock_guard: Option<MutexGuard<'static, ()>>,
64    /// Whether this guard owns the outermost scope entry on the current thread.
65    pub(crate) owns_scope: bool,
66    /// Raw counter baseline captured immediately after enabling tracking.
67    pub(crate) start_counters: RawAllocCounters,
68}
69
70/// Multi-cycle native heap lifecycle probe capturing baseline, post-drain live bytes, and per-cycle slope.
71#[derive(Clone, Copy, Debug, Default, Deserialize, Getter, PartialEq, Serialize)]
72pub struct NativeHeapLifecycleProbe {
73    /// Number of mount/step/dispose lifecycle drain cycles executed after warmup.
74    #[get(type(copy))]
75    pub(crate) cycles: u64,
76    /// Post-warmup live heap bytes baseline in bytes.
77    #[get(type(copy))]
78    pub(crate) baseline_live_bytes: u64,
79    /// Post-drain live heap bytes after all lifecycle cycles complete.
80    #[get(type(copy))]
81    pub(crate) after_drain_live_bytes: u64,
82    /// Linear slope of live heap bytes per lifecycle cycle.
83    #[get(type(copy))]
84    pub(crate) live_bytes_slope_per_cycle: f64,
85    /// Post-warmup live allocation count baseline.
86    #[get(type(copy))]
87    pub(crate) baseline_live_allocations: u64,
88    /// Post-drain live allocation count after all lifecycle cycles complete.
89    #[get(type(copy))]
90    pub(crate) after_drain_live_allocations: u64,
91    /// Linear slope of live allocations per lifecycle cycle.
92    #[get(type(copy))]
93    pub(crate) live_allocations_slope_per_cycle: f64,
94    /// Peak positive live heap bytes observed during the lifecycle probe.
95    #[get(type(copy))]
96    pub(crate) peak_live_bytes: u64,
97    /// Total heap allocations recorded across the measured lifecycle cycles.
98    #[get(type(copy))]
99    pub(crate) total_alloc_count: u64,
100    /// Total heap frees recorded across the measured lifecycle cycles.
101    #[get(type(copy))]
102    pub(crate) total_free_count: u64,
103    /// Total heap bytes allocated across the measured lifecycle cycles.
104    #[get(type(copy))]
105    pub(crate) total_bytes_allocated: u64,
106}