1use std::str::FromStr;
14
15#[cfg(feature = "diagnostics")]
16use crate::debug_toggles::DebugToggle;
17
18#[cfg(feature = "diagnostics")]
20pub struct Diagnostic(DebugToggle);
21
22#[cfg(not(feature = "diagnostics"))]
25pub struct Diagnostic(());
26
27impl Diagnostic {
28 #[cfg(feature = "diagnostics")]
29 const fn new(name: &'static str) -> Self {
30 Self(DebugToggle::new(name))
31 }
32
33 #[cfg(not(feature = "diagnostics"))]
34 const fn new(_name: &'static str) -> Self {
35 Self(())
36 }
37
38 pub fn with<R>(&self, read: impl FnOnce(Option<&str>) -> R) -> R {
40 #[cfg(feature = "diagnostics")]
41 {
42 self.0.with(read)
43 }
44 #[cfg(not(feature = "diagnostics"))]
45 {
46 read(None)
47 }
48 }
49
50 pub fn is_set(&self) -> bool {
52 self.with(|value| value.is_some())
53 }
54
55 pub fn flag(&self) -> bool {
57 self.with(|value| matches!(value, Some("1" | "true" | "yes")))
58 }
59
60 pub fn equals(&self, expected: &str) -> bool {
62 self.with(|value| value == Some(expected))
63 }
64
65 pub fn parse<T: FromStr>(&self) -> Option<T> {
67 self.with(|value| value.and_then(|value| value.trim().parse().ok()))
68 }
69
70 pub fn threshold_ms(&self) -> Option<f64> {
73 self.parse::<f64>()
74 .filter(|threshold| threshold.is_finite() && *threshold >= 0.0)
75 }
76}
77
78pub struct Diagnostics {
81 pub a11y_sync: Diagnostic,
84 pub ablate: Diagnostic,
86 pub adpf: Diagnostic,
88 pub assert_state_chain: Diagnostic,
90 pub async_haptics: Diagnostic,
93 pub background_pipelines: Diagnostic,
96 pub compose_debug_modifiers: Diagnostic,
98 pub compose_debug_slot_table: Diagnostic,
100 pub core_pin: Diagnostic,
102 pub debug_scope_labels: Diagnostic,
104 pub desktop_frame_telemetry: Diagnostic,
107 pub desktop_frame_telemetry_ms: Diagnostic,
110 pub disable_nav_snap: Diagnostic,
112 pub disable_scroll_translate: Diagnostic,
115 pub disable_structural_dirt: Diagnostic,
118 pub encode_delay_ms: Diagnostic,
121 pub frame_lead_tenths: Diagnostic,
124 pub frame_stage_telemetry: Diagnostic,
127 pub frame_stage_telemetry_ms: Diagnostic,
130 pub glass_material_folds: Diagnostic,
133 pub gpu_fence_profile: Diagnostic,
135 pub gpu_pass_timing: Diagnostic,
137 pub gpu_shadow_cache_diag: Diagnostic,
139 pub gpu_stage_diag: Diagnostic,
141 pub gpu_stats: Diagnostic,
143 pub layout_invalidation_dispatch_diag: Diagnostic,
146 pub layout_measure_telemetry: Diagnostic,
149 pub layout_measure_telemetry_ms: Diagnostic,
152 pub layout_repass_schedule_diag: Diagnostic,
155 pub lazy_cache_telemetry: Diagnostic,
157 pub lazy_item_telemetry: Diagnostic,
159 pub lazy_measure_telemetry: Diagnostic,
161 pub location_key_diagnostics: Diagnostic,
163 pub native_trace: Diagnostic,
165 pub native_window_timing: Diagnostic,
167 pub no_backdrop_cache: Diagnostic,
169 pub no_effect_domains: Diagnostic,
171 pub no_fill_cache: Diagnostic,
174 pub no_interiors_first: Diagnostic,
176 pub no_shader_flatten: Diagnostic,
178 pub no_shader_fold: Diagnostic,
181 pub no_shader_specialization: Diagnostic,
183 pub pacing_diag: Diagnostic,
185 pub pipeline_disk_cache: Diagnostic,
188 pub present_thread: Diagnostic,
191 pub probe_draw_passes: Diagnostic,
193 pub probe_passes: Diagnostic,
195 pub recompose_scope_telemetry_ms: Diagnostic,
198 pub recomp_diag: Diagnostic,
200 pub render_phase_dirty_diag: Diagnostic,
203 pub robot_button_helper_diag: Diagnostic,
206 pub scene_update_diag: Diagnostic,
208 pub shape_variants: Diagnostic,
211 pub skip_shadows: Diagnostic,
213 pub structural_diag: Diagnostic,
215 pub subcompose_telemetry: Diagnostic,
217 pub survive_gpu_errors: Diagnostic,
219 pub text_atlas_fallback_diag: Diagnostic,
222 pub text_layout_telemetry: Diagnostic,
224 pub update_stage_telemetry_ms: Diagnostic,
227 pub validate_slots: Diagnostic,
230 pub wgpu_render_stage_telemetry: Diagnostic,
233 pub wgpu_render_stage_telemetry_ms: Diagnostic,
236}
237
238pub static DIAGNOSTICS: Diagnostics = Diagnostics {
240 a11y_sync: Diagnostic::new("CRANPOSE_A11Y_SYNC"),
241 ablate: Diagnostic::new("CRANPOSE_ABLATE"),
242 adpf: Diagnostic::new("CRANPOSE_ADPF"),
243 assert_state_chain: Diagnostic::new("CRANPOSE_ASSERT_STATE_CHAIN"),
244 async_haptics: Diagnostic::new("CRANPOSE_ASYNC_HAPTICS"),
245 background_pipelines: Diagnostic::new("CRANPOSE_BACKGROUND_PIPELINES"),
246 compose_debug_modifiers: Diagnostic::new("COMPOSE_DEBUG_MODIFIERS"),
247 compose_debug_slot_table: Diagnostic::new("COMPOSE_DEBUG_SLOT_TABLE"),
248 core_pin: Diagnostic::new("CRANPOSE_CORE_PIN"),
249 debug_scope_labels: Diagnostic::new("CRANPOSE_DEBUG_SCOPE_LABELS"),
250 desktop_frame_telemetry: Diagnostic::new("CRANPOSE_DESKTOP_FRAME_TELEMETRY"),
251 desktop_frame_telemetry_ms: Diagnostic::new("CRANPOSE_DESKTOP_FRAME_TELEMETRY_MS"),
252 disable_nav_snap: Diagnostic::new("CRANPOSE_DISABLE_NAV_SNAP"),
253 disable_scroll_translate: Diagnostic::new("CRANPOSE_DISABLE_SCROLL_TRANSLATE"),
254 disable_structural_dirt: Diagnostic::new("CRANPOSE_DISABLE_STRUCTURAL_DIRT"),
255 encode_delay_ms: Diagnostic::new("CRANPOSE_ENCODE_DELAY_MS"),
256 frame_lead_tenths: Diagnostic::new("CRANPOSE_FRAME_LEAD_TENTHS"),
257 frame_stage_telemetry: Diagnostic::new("CRANPOSE_FRAME_STAGE_TELEMETRY"),
258 frame_stage_telemetry_ms: Diagnostic::new("CRANPOSE_FRAME_STAGE_TELEMETRY_MS"),
259 glass_material_folds: Diagnostic::new("CRANPOSE_GLASS_MATERIAL_FOLDS"),
260 gpu_fence_profile: Diagnostic::new("CRANPOSE_GPU_FENCE_PROFILE"),
261 gpu_pass_timing: Diagnostic::new("CRANPOSE_GPU_PASS_TIMING"),
262 gpu_shadow_cache_diag: Diagnostic::new("CRANPOSE_GPU_SHADOW_CACHE_DIAG"),
263 gpu_stage_diag: Diagnostic::new("CRANPOSE_GPU_STAGE_DIAG"),
264 gpu_stats: Diagnostic::new("CRANPOSE_GPU_STATS"),
265 layout_invalidation_dispatch_diag: Diagnostic::new(
266 "CRANPOSE_LAYOUT_INVALIDATION_DISPATCH_DIAG",
267 ),
268 layout_measure_telemetry: Diagnostic::new("CRANPOSE_LAYOUT_MEASURE_TELEMETRY"),
269 layout_measure_telemetry_ms: Diagnostic::new("CRANPOSE_LAYOUT_MEASURE_TELEMETRY_MS"),
270 layout_repass_schedule_diag: Diagnostic::new("CRANPOSE_LAYOUT_REPASS_SCHEDULE_DIAG"),
271 lazy_cache_telemetry: Diagnostic::new("CRANPOSE_LAZY_CACHE_TELEMETRY"),
272 lazy_item_telemetry: Diagnostic::new("CRANPOSE_LAZY_ITEM_TELEMETRY"),
273 lazy_measure_telemetry: Diagnostic::new("CRANPOSE_LAZY_MEASURE_TELEMETRY"),
274 location_key_diagnostics: Diagnostic::new("CRANPOSE_LOCATION_KEY_DIAGNOSTICS"),
275 native_trace: Diagnostic::new("CRANPOSE_NATIVE_TRACE"),
276 native_window_timing: Diagnostic::new("CRANPOSE_NATIVE_WINDOW_TIMING"),
277 no_backdrop_cache: Diagnostic::new("CRANPOSE_NO_BACKDROP_CACHE"),
278 no_effect_domains: Diagnostic::new("CRANPOSE_NO_EFFECT_DOMAINS"),
279 no_fill_cache: Diagnostic::new("CRANPOSE_NO_FILL_CACHE"),
280 no_interiors_first: Diagnostic::new("CRANPOSE_NO_INTERIORS_FIRST"),
281 no_shader_flatten: Diagnostic::new("CRANPOSE_NO_SHADER_FLATTEN"),
282 no_shader_fold: Diagnostic::new("CRANPOSE_NO_SHADER_FOLD"),
283 no_shader_specialization: Diagnostic::new("CRANPOSE_NO_SHADER_SPECIALIZATION"),
284 pacing_diag: Diagnostic::new("CRANPOSE_PACING_DIAG"),
285 pipeline_disk_cache: Diagnostic::new("CRANPOSE_PIPELINE_DISK_CACHE"),
286 present_thread: Diagnostic::new("CRANPOSE_PRESENT_THREAD"),
287 probe_draw_passes: Diagnostic::new("CRANPOSE_PROBE_DRAW_PASSES"),
288 probe_passes: Diagnostic::new("CRANPOSE_PROBE_PASSES"),
289 recompose_scope_telemetry_ms: Diagnostic::new("CRANPOSE_RECOMPOSE_SCOPE_TELEMETRY_MS"),
290 recomp_diag: Diagnostic::new("CRANPOSE_RECOMP_DIAG"),
291 render_phase_dirty_diag: Diagnostic::new("CRANPOSE_RENDER_PHASE_DIRTY_DIAG"),
292 robot_button_helper_diag: Diagnostic::new("CRANPOSE_ROBOT_BUTTON_HELPER_DIAG"),
293 scene_update_diag: Diagnostic::new("CRANPOSE_SCENE_UPDATE_DIAG"),
294 shape_variants: Diagnostic::new("CRANPOSE_SHAPE_VARIANTS"),
295 skip_shadows: Diagnostic::new("CRANPOSE_SKIP_SHADOWS"),
296 structural_diag: Diagnostic::new("CRANPOSE_STRUCTURAL_DIAG"),
297 subcompose_telemetry: Diagnostic::new("CRANPOSE_SUBCOMPOSE_TELEMETRY"),
298 survive_gpu_errors: Diagnostic::new("CRANPOSE_SURVIVE_GPU_ERRORS"),
299 text_atlas_fallback_diag: Diagnostic::new("CRANPOSE_TEXT_ATLAS_FALLBACK_DIAG"),
300 text_layout_telemetry: Diagnostic::new("CRANPOSE_TEXT_LAYOUT_TELEMETRY"),
301 update_stage_telemetry_ms: Diagnostic::new("CRANPOSE_UPDATE_STAGE_TELEMETRY_MS"),
302 validate_slots: Diagnostic::new("CRANPOSE_VALIDATE_SLOTS"),
303 wgpu_render_stage_telemetry: Diagnostic::new("CRANPOSE_WGPU_RENDER_STAGE_TELEMETRY"),
304 wgpu_render_stage_telemetry_ms: Diagnostic::new("CRANPOSE_WGPU_RENDER_STAGE_TELEMETRY_MS"),
305};