Skip to main content

lgui_diagnostics/
model.rs

1use std::time::Instant;
2
3#[cfg_attr(feature = "serde", derive(serde::Serialize))]
4#[derive(Clone, Debug, Default)]
5pub struct SystemUsageSnapshot {
6    pub schema: &'static str,
7    pub sample_interval_ms: u64,
8    pub sample_age_ms: u64,
9    pub process: ProcessUsageSnapshot,
10    pub system: MachineUsageSnapshot,
11    pub gpu: GpuUsageSnapshot,
12}
13
14#[cfg_attr(feature = "serde", derive(serde::Serialize))]
15#[derive(Clone, Debug, Default)]
16pub struct ProcessUsageSnapshot {
17    pub cpu_percent: Option<f32>,
18    pub working_set_mb: Option<f32>,
19    pub private_mb: Option<f32>,
20}
21
22#[cfg_attr(feature = "serde", derive(serde::Serialize))]
23#[derive(Clone, Debug, Default)]
24pub struct MachineUsageSnapshot {
25    pub memory_load_percent: Option<u32>,
26    pub total_memory_mb: Option<f32>,
27    pub available_memory_mb: Option<f32>,
28}
29
30#[cfg_attr(feature = "serde", derive(serde::Serialize))]
31#[derive(Clone, Debug)]
32pub struct GpuUsageSnapshot {
33    pub usage_percent: Option<f32>,
34    pub memory_mb: Option<f32>,
35    pub status: &'static str,
36}
37
38impl Default for GpuUsageSnapshot {
39    fn default() -> Self {
40        Self {
41            usage_percent: None,
42            memory_mb: None,
43            status: "not-sampled",
44        }
45    }
46}
47
48#[cfg_attr(feature = "serde", derive(serde::Serialize))]
49#[derive(Clone, Copy, Debug, PartialEq, Eq)]
50pub enum DiagnosticPresentMode {
51    Full,
52    Dirty,
53    Skipped,
54}
55
56#[cfg_attr(feature = "serde", derive(serde::Serialize))]
57#[derive(Clone, Copy, Debug, Default)]
58pub struct FrameRenderMetrics {
59    pub build_host_tree_ms: f32,
60    pub pending_updates_ms: f32,
61    pub prepare_render_ms: f32,
62    pub retained_snapshot_ms: f32,
63    pub declarative_mount_ms: f32,
64    pub focus_animation_sync_ms: f32,
65    pub focus_sync_ms: f32,
66    pub focus_rebuild_ms: f32,
67    pub animation_target_sync_ms: f32,
68    pub animation_rebuild_ms: f32,
69    pub runtime_reconcile_ms: f32,
70    pub layout_ms: f32,
71    pub host_commit_ms: f32,
72    pub host_change_scan_ms: f32,
73    pub host_node_patch_ms: f32,
74    pub host_scene_reconcile_ms: f32,
75    pub host_scene_snapshot_ms: f32,
76    pub host_damage_ms: f32,
77    pub host_finalize_ms: f32,
78    pub host_unattributed_ms: f32,
79    pub scene_ms: f32,
80    pub metadata_ms: f32,
81    pub snapshot_ms: f32,
82    pub render_total_ms: f32,
83    pub node_count: usize,
84    pub command_count: usize,
85    pub component_executed: usize,
86    pub component_dirty: usize,
87    pub projection_visited_nodes: usize,
88    pub projection_reused_component_roots: usize,
89    pub animation_sync_nodes: usize,
90    pub focus_sync_needed: bool,
91    pub layout_visited_nodes: usize,
92    pub layout_laid_out_nodes: usize,
93    pub layout_reused_nodes: usize,
94    pub host_visited_nodes: usize,
95    pub scene_compiled_nodes: usize,
96    pub host_mutations: usize,
97    pub scene_mutations: usize,
98    pub reused_scene_nodes: usize,
99}
100
101#[cfg_attr(feature = "serde", derive(serde::Serialize))]
102#[derive(Clone, Copy, Debug, Default)]
103pub struct FrameBlitSourceMetrics {
104    pub blit_count: usize,
105    pub bitblt_count: usize,
106    pub alphablend_count: usize,
107    pub fallback_count: usize,
108    pub pixels: u64,
109}
110
111#[cfg_attr(feature = "serde", derive(serde::Serialize))]
112#[derive(Clone, Copy, Debug, Default)]
113pub struct FramePresentMetrics {
114    pub acquire_ms: f32,
115    pub get_dc_ms: f32,
116    pub clear_ms: f32,
117    pub draw_commands_ms: f32,
118    pub flush_ms: f32,
119    pub submit_ms: f32,
120    pub present_ms: f32,
121    pub release_dc_ms: f32,
122    pub submitted_pixels: u64,
123    pub blit_count: usize,
124    pub bitblt_count: usize,
125    pub alphablend_count: usize,
126    pub fallback_count: usize,
127    pub cache_budget_bytes: usize,
128    pub cache_resident_bytes: usize,
129    pub cache_entries: usize,
130    pub cache_hits: u64,
131    pub cache_misses: u64,
132    pub cache_evictions: u64,
133    pub text_cache_resident_bytes: usize,
134    pub text_cache_entries: usize,
135    pub text_cache_hits: u64,
136    pub text_cache_misses: u64,
137    pub text_cache_evictions: u64,
138    pub largest_cache_entry_bytes: usize,
139    pub largest_text_cache_entry_bytes: usize,
140    pub blit_pixels: u64,
141    pub static_layer_blits: FrameBlitSourceMetrics,
142    pub overlay_blits: FrameBlitSourceMetrics,
143    pub backdrop_blits: FrameBlitSourceMetrics,
144    pub custom_blits: FrameBlitSourceMetrics,
145    pub other_blits: FrameBlitSourceMetrics,
146}
147
148#[cfg_attr(feature = "serde", derive(serde::Serialize))]
149#[derive(Clone, Debug, Default, PartialEq, Eq)]
150pub struct RendererDeviceInfo {
151    pub adapter_name: Option<String>,
152    pub api: String,
153    pub api_version: Option<String>,
154    pub color_format: String,
155    pub present_mode: String,
156}
157
158#[derive(Clone, Debug)]
159pub struct FrameSample {
160    pub frame_index: u64,
161    pub recorded_at: Instant,
162    pub backend: &'static str,
163    pub renderer: RendererDeviceInfo,
164    pub mode: DiagnosticPresentMode,
165    pub frame_build_ms: f32,
166    pub diff_ms: f32,
167    pub draw_present_ms: f32,
168    pub total_ms: f32,
169    pub dirty_rect_count: usize,
170    pub dirty_area_ratio: f32,
171    pub submit_scope: &'static str,
172    pub fallback_reason: Option<&'static str>,
173    pub primary_reason: Option<&'static str>,
174    pub recovery_state: &'static str,
175    pub recovery_attempt: u8,
176    pub render: FrameRenderMetrics,
177    pub present: FramePresentMetrics,
178}
179
180#[derive(Clone, Debug, Default)]
181pub struct FrameDiagnosticsSnapshot {
182    pub fps: f32,
183    pub average_frame_ms: f32,
184    pub p95_frame_ms: f32,
185    pub sample_count: usize,
186    pub latest: Option<FrameSample>,
187}
188
189#[derive(Clone, Copy, Debug, PartialEq, Eq)]
190pub struct DiagnosticsQuery {
191    pub recent_limit: usize,
192}
193
194impl DiagnosticsQuery {
195    pub const fn recent(recent_limit: usize) -> Self {
196        Self { recent_limit }
197    }
198}