Skip to main content

argui_inspect/
memory.rs

1use crate::InspectorHandle;
2
3/// Known allocated capacities, sampled independently from the frame history.
4/// These are allocator payload sizes, not resident pages; do not subtract them
5/// from RSS or include them again in a combined process/GPU total.
6#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
7pub struct MemorySnapshot {
8    pub ui_nodes: usize,
9    pub layout_nodes: usize,
10    pub ui_index_bytes: usize,
11    pub layout_metadata_bytes: usize,
12    pub layout_cache_bytes: usize,
13    pub layout_geometry_bytes: usize,
14    pub layout_output_bytes: usize,
15    pub paint_command_bytes: usize,
16}
17
18impl InspectorHandle {
19    pub fn request_memory_sample(&self) {
20        let mut state = self.0.borrow_mut();
21        state.memory_requested = state.recording && !state.paused;
22    }
23
24    pub fn take_memory_request(&self) -> bool {
25        let mut state = self.0.borrow_mut();
26        let requested = std::mem::take(&mut state.memory_requested);
27        requested && state.recording && !state.paused
28    }
29
30    pub fn publish_memory(&self, snapshot: MemorySnapshot) {
31        self.0.borrow_mut().memory = Some(snapshot);
32    }
33
34    #[must_use]
35    pub fn memory(&self) -> Option<MemorySnapshot> {
36        self.0.borrow().memory
37    }
38}