euv_core/app/accounting/struct.rs
1use super::*;
2
3/// Unique owner identity pairing ownership domain, owner identifier, and monotonic generation.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, Ord, PartialEq, PartialOrd)]
5pub struct ResourceOwnerId {
6 /// Ownership domain (`Page`, `Surface`, `DynamicModule`, etc.).
7 #[get(type(copy))]
8 pub(crate) kind: ResourceOwnerKind,
9 /// Domain-local owner identifier (e.g. `page_id` or `surface_id`).
10 #[get(type(copy))]
11 pub(crate) owner_id: u64,
12 /// Monotonic generation distinguishing recreated instances reusing the same `owner_id`.
13 #[get(type(copy))]
14 pub(crate) generation: u64,
15}
16
17/// Single-owner tracked allocation record keyed by `(kind, handle_id)` to prevent double-counting.
18#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
19pub(crate) struct TrackedResourceRecord {
20 /// Single authoritative owner responsible for releasing this resource.
21 #[get(type(copy))]
22 pub(crate) owner: ResourceOwnerId,
23 /// Tracked resource category.
24 #[get(type(copy))]
25 pub(crate) kind: TrackedResourceKind,
26 /// Unique resource handle identifier within `kind`.
27 #[get(type(copy))]
28 pub(crate) handle_id: u64,
29 /// Estimated memory/VRAM byte footprint.
30 #[get(type(copy))]
31 pub(crate) byte_size: usize,
32 /// Retention classification (`Active`, `ExpectedRetained`, or `PendingFenceRelease`).
33 #[get(type(copy))]
34 pub(crate) retention: ResourceRetentionClass,
35 /// GPU fence identifier that must complete before pending release is considered overdue (`0` when immediate).
36 #[get(type(copy))]
37 pub(crate) retire_fence_id: u64,
38}
39
40/// Diagnostic record identifying one resource still alive under a destroyed owner past its fence and grace period.
41#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
42pub struct LeakedResourceEntry {
43 /// Destroyed owner still referenced by this resource.
44 #[get(type(copy))]
45 pub(crate) owner: ResourceOwnerId,
46 /// Leaked resource category.
47 #[get(type(copy))]
48 pub(crate) kind: TrackedResourceKind,
49 /// Resource handle identifier.
50 #[get(type(copy))]
51 pub(crate) handle_id: u64,
52 /// Tracked leaked byte footprint.
53 #[get(type(copy))]
54 pub(crate) byte_size: usize,
55 /// Monotonic timestamp in milliseconds when `owner` was destroyed.
56 #[get(type(copy))]
57 pub(crate) destroyed_at_ms: u64,
58 /// Required GPU retirement fence identifier (`0` for non-GPU resources).
59 #[get(type(copy))]
60 pub(crate) retire_fence_id: u64,
61}
62
63/// Structured framework resource accounting snapshot separating `expected_retained` from `destroyed_owner.live_objects`.
64#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
65pub struct ResourceAccountingSnapshot {
66 /// Live active page count.
67 #[get(type(copy))]
68 pub(crate) pages_active: usize,
69 /// Live frozen page count within retention budget.
70 #[get(type(copy))]
71 pub(crate) pages_frozen: usize,
72 /// Evicted cold page snapshot count.
73 #[get(type(copy))]
74 pub(crate) pages_evicted: usize,
75 /// Cumulative explicitly destroyed page count.
76 #[get(type(copy))]
77 pub(crate) pages_destroyed: u64,
78 /// Live tracked scene node count.
79 #[get(type(copy))]
80 pub(crate) scene_nodes: usize,
81 /// Live tracked reactive effect count.
82 #[get(type(copy))]
83 pub(crate) reactive_effects: usize,
84 /// Live tracked subscription count.
85 #[get(type(copy))]
86 pub(crate) subscriptions: usize,
87 /// Live tracked timer count.
88 #[get(type(copy))]
89 pub(crate) timers: usize,
90 /// Live tracked pending async task count.
91 #[get(type(copy))]
92 pub(crate) pending_async_tasks: usize,
93 /// Live tracked dynamic module instance count.
94 #[get(type(copy))]
95 pub(crate) dynamic_instances: usize,
96 /// Live tracked native OS handle count.
97 #[get(type(copy))]
98 pub(crate) os_handles: usize,
99 /// Live tracked GPU texture handle count.
100 #[get(type(copy))]
101 pub(crate) gpu_textures: usize,
102 /// Live tracked GPU buffer handle count.
103 #[get(type(copy))]
104 pub(crate) gpu_buffers: usize,
105 /// Aggregate live GPU texture + buffer bytes.
106 #[get(type(copy))]
107 pub(crate) gpu_live_bytes: usize,
108 /// Aggregate live bounded cache bytes.
109 #[get(type(copy))]
110 pub(crate) retained_cache_bytes: usize,
111 /// Total intentionally retained objects (`ExpectedRetained` + non-overdue `PendingFenceRelease`).
112 #[get(type(copy))]
113 pub(crate) expected_retained_objects: usize,
114 /// Total intentionally retained bytes (`ExpectedRetained` + non-overdue `PendingFenceRelease`).
115 #[get(type(copy))]
116 pub(crate) expected_retained_bytes: usize,
117 /// Count of objects still live under a destroyed owner past its fence and grace period (`destroyed_owner.live_objects`).
118 #[get(type(copy))]
119 pub(crate) destroyed_owner_live_objects: usize,
120 /// Total bytes still live under a destroyed owner past its fence and grace period.
121 #[get(type(copy))]
122 pub(crate) destroyed_owner_live_bytes: usize,
123 /// Detailed owner-attributed leak entries for every object counted in `destroyed_owner_live_objects`.
124 pub(crate) leaks: Vec<LeakedResourceEntry>,
125}
126
127/// Low-overhead single-owner framework resource ownership accountant.
128#[derive(Clone, Data, Debug, Default)]
129pub struct ResourceAccountant {
130 /// Single-owner registry mapping `(TrackedResourceKind, handle_id)` to its live record.
131 #[get(pub(crate))]
132 #[get_mut(pub(crate))]
133 #[set(skip)]
134 pub(crate) live_resources: HashMap<(TrackedResourceKind, u64), TrackedResourceRecord>,
135 /// Destroyed owners mapped to `(destroyed_at_ms, retire_fence_id)` for leak attribution.
136 #[get(pub(crate))]
137 #[get_mut(pub(crate))]
138 #[set(skip)]
139 pub(crate) destroyed_owners: HashMap<ResourceOwnerId, (u64, u64)>,
140 /// Highest completed GPU submission fence identifier.
141 #[get(type(copy))]
142 #[get_mut(skip)]
143 #[set(skip)]
144 pub(crate) completed_gpu_fence_id: u64,
145 /// Last synced active page count.
146 #[get(type(copy))]
147 pub(crate) pages_active: usize,
148 /// Last synced frozen page count.
149 #[get(type(copy))]
150 pub(crate) pages_frozen: usize,
151 /// Last synced evicted page count.
152 #[get(type(copy))]
153 pub(crate) pages_evicted: usize,
154 /// Cumulative explicitly destroyed page count.
155 #[get(type(copy))]
156 pub(crate) pages_destroyed: u64,
157 /// Cumulative resource registrations accepted.
158 #[get(type(copy))]
159 #[get_mut(skip)]
160 #[set(skip)]
161 pub(crate) total_registrations: u64,
162 /// Cumulative resource releases completed.
163 #[get(type(copy))]
164 #[get_mut(skip)]
165 #[set(skip)]
166 pub(crate) total_releases: u64,
167}