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,
192 pub probe_draw_passes: Diagnostic,
194 pub probe_passes: Diagnostic,
196 pub recompose_scope_telemetry_ms: Diagnostic,
199 pub recomp_diag: Diagnostic,
201 pub render_phase_dirty_diag: Diagnostic,
204 pub robot_button_helper_diag: Diagnostic,
207 pub shape_variants: Diagnostic,
210 pub skip_shadows: Diagnostic,
212 pub structural_diag: Diagnostic,
214 pub subcompose_telemetry: Diagnostic,
216 pub survive_gpu_errors: Diagnostic,
218 pub text_atlas_fallback_diag: Diagnostic,
221 pub text_layout_telemetry: Diagnostic,
223 pub update_stage_telemetry_ms: Diagnostic,
226 pub validate_slots: Diagnostic,
229 pub wgpu_render_stage_telemetry: Diagnostic,
232 pub wgpu_render_stage_telemetry_ms: Diagnostic,
235}
236
237pub static DIAGNOSTICS: Diagnostics = Diagnostics {
239 a11y_sync: Diagnostic::new("CRANPOSE_A11Y_SYNC"),
240 ablate: Diagnostic::new("CRANPOSE_ABLATE"),
241 adpf: Diagnostic::new("CRANPOSE_ADPF"),
242 assert_state_chain: Diagnostic::new("CRANPOSE_ASSERT_STATE_CHAIN"),
243 async_haptics: Diagnostic::new("CRANPOSE_ASYNC_HAPTICS"),
244 background_pipelines: Diagnostic::new("CRANPOSE_BACKGROUND_PIPELINES"),
245 compose_debug_modifiers: Diagnostic::new("COMPOSE_DEBUG_MODIFIERS"),
246 compose_debug_slot_table: Diagnostic::new("COMPOSE_DEBUG_SLOT_TABLE"),
247 core_pin: Diagnostic::new("CRANPOSE_CORE_PIN"),
248 debug_scope_labels: Diagnostic::new("CRANPOSE_DEBUG_SCOPE_LABELS"),
249 desktop_frame_telemetry: Diagnostic::new("CRANPOSE_DESKTOP_FRAME_TELEMETRY"),
250 desktop_frame_telemetry_ms: Diagnostic::new("CRANPOSE_DESKTOP_FRAME_TELEMETRY_MS"),
251 disable_nav_snap: Diagnostic::new("CRANPOSE_DISABLE_NAV_SNAP"),
252 disable_scroll_translate: Diagnostic::new("CRANPOSE_DISABLE_SCROLL_TRANSLATE"),
253 disable_structural_dirt: Diagnostic::new("CRANPOSE_DISABLE_STRUCTURAL_DIRT"),
254 encode_delay_ms: Diagnostic::new("CRANPOSE_ENCODE_DELAY_MS"),
255 frame_lead_tenths: Diagnostic::new("CRANPOSE_FRAME_LEAD_TENTHS"),
256 frame_stage_telemetry: Diagnostic::new("CRANPOSE_FRAME_STAGE_TELEMETRY"),
257 frame_stage_telemetry_ms: Diagnostic::new("CRANPOSE_FRAME_STAGE_TELEMETRY_MS"),
258 glass_material_folds: Diagnostic::new("CRANPOSE_GLASS_MATERIAL_FOLDS"),
259 gpu_fence_profile: Diagnostic::new("CRANPOSE_GPU_FENCE_PROFILE"),
260 gpu_pass_timing: Diagnostic::new("CRANPOSE_GPU_PASS_TIMING"),
261 gpu_shadow_cache_diag: Diagnostic::new("CRANPOSE_GPU_SHADOW_CACHE_DIAG"),
262 gpu_stage_diag: Diagnostic::new("CRANPOSE_GPU_STAGE_DIAG"),
263 gpu_stats: Diagnostic::new("CRANPOSE_GPU_STATS"),
264 layout_invalidation_dispatch_diag: Diagnostic::new(
265 "CRANPOSE_LAYOUT_INVALIDATION_DISPATCH_DIAG",
266 ),
267 layout_measure_telemetry: Diagnostic::new("CRANPOSE_LAYOUT_MEASURE_TELEMETRY"),
268 layout_measure_telemetry_ms: Diagnostic::new("CRANPOSE_LAYOUT_MEASURE_TELEMETRY_MS"),
269 layout_repass_schedule_diag: Diagnostic::new("CRANPOSE_LAYOUT_REPASS_SCHEDULE_DIAG"),
270 lazy_cache_telemetry: Diagnostic::new("CRANPOSE_LAZY_CACHE_TELEMETRY"),
271 lazy_item_telemetry: Diagnostic::new("CRANPOSE_LAZY_ITEM_TELEMETRY"),
272 lazy_measure_telemetry: Diagnostic::new("CRANPOSE_LAZY_MEASURE_TELEMETRY"),
273 location_key_diagnostics: Diagnostic::new("CRANPOSE_LOCATION_KEY_DIAGNOSTICS"),
274 native_trace: Diagnostic::new("CRANPOSE_NATIVE_TRACE"),
275 native_window_timing: Diagnostic::new("CRANPOSE_NATIVE_WINDOW_TIMING"),
276 no_backdrop_cache: Diagnostic::new("CRANPOSE_NO_BACKDROP_CACHE"),
277 no_effect_domains: Diagnostic::new("CRANPOSE_NO_EFFECT_DOMAINS"),
278 no_fill_cache: Diagnostic::new("CRANPOSE_NO_FILL_CACHE"),
279 no_interiors_first: Diagnostic::new("CRANPOSE_NO_INTERIORS_FIRST"),
280 no_shader_flatten: Diagnostic::new("CRANPOSE_NO_SHADER_FLATTEN"),
281 no_shader_fold: Diagnostic::new("CRANPOSE_NO_SHADER_FOLD"),
282 no_shader_specialization: Diagnostic::new("CRANPOSE_NO_SHADER_SPECIALIZATION"),
283 pacing_diag: Diagnostic::new("CRANPOSE_PACING_DIAG"),
284 pipeline_disk_cache: Diagnostic::new("CRANPOSE_PIPELINE_DISK_CACHE"),
285 present_thread: Diagnostic::new("CRANPOSE_PRESENT_THREAD"),
286 probe_draw_passes: Diagnostic::new("CRANPOSE_PROBE_DRAW_PASSES"),
287 probe_passes: Diagnostic::new("CRANPOSE_PROBE_PASSES"),
288 recompose_scope_telemetry_ms: Diagnostic::new("CRANPOSE_RECOMPOSE_SCOPE_TELEMETRY_MS"),
289 recomp_diag: Diagnostic::new("CRANPOSE_RECOMP_DIAG"),
290 render_phase_dirty_diag: Diagnostic::new("CRANPOSE_RENDER_PHASE_DIRTY_DIAG"),
291 robot_button_helper_diag: Diagnostic::new("CRANPOSE_ROBOT_BUTTON_HELPER_DIAG"),
292 shape_variants: Diagnostic::new("CRANPOSE_SHAPE_VARIANTS"),
293 skip_shadows: Diagnostic::new("CRANPOSE_SKIP_SHADOWS"),
294 structural_diag: Diagnostic::new("CRANPOSE_STRUCTURAL_DIAG"),
295 subcompose_telemetry: Diagnostic::new("CRANPOSE_SUBCOMPOSE_TELEMETRY"),
296 survive_gpu_errors: Diagnostic::new("CRANPOSE_SURVIVE_GPU_ERRORS"),
297 text_atlas_fallback_diag: Diagnostic::new("CRANPOSE_TEXT_ATLAS_FALLBACK_DIAG"),
298 text_layout_telemetry: Diagnostic::new("CRANPOSE_TEXT_LAYOUT_TELEMETRY"),
299 update_stage_telemetry_ms: Diagnostic::new("CRANPOSE_UPDATE_STAGE_TELEMETRY_MS"),
300 validate_slots: Diagnostic::new("CRANPOSE_VALIDATE_SLOTS"),
301 wgpu_render_stage_telemetry: Diagnostic::new("CRANPOSE_WGPU_RENDER_STAGE_TELEMETRY"),
302 wgpu_render_stage_telemetry_ms: Diagnostic::new("CRANPOSE_WGPU_RENDER_STAGE_TELEMETRY_MS"),
303};