lurq 0.65.1

A Rust UI toolkit with typed components, retained state, reactive signals, GPU rendering, and DevTools.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
use std::{collections::BTreeMap, sync::Arc, time::Duration};

use serde_json::Value;

use super::*;

const MS: u64 = 1_000_000;

fn span(phase: Phase, depth: u8, start_ms: u64, end_ms: u64) -> PhaseSpan {
  PhaseSpan {
    phase,
    depth,
    start_ns: start_ms * MS,
    end_ns: end_ms * MS,
    component: None,
  }
}

/// pass at..at+10: layout_update +1..+7 holds ui_rebuild +1..+3 (holding
/// ui_commit +2..+3) and layout_compute +4..+6; render +7..+9. Presented with
/// `memory_bytes` when given.
fn pass(sequence: u64, window: &str, at_ms: u64, memory_bytes: Option<usize>) -> Arc<ProfileSample> {
  Arc::new(ProfileSample {
    sequence,
    window: window.into(),
    started_ms: at_ms as f64,
    completed_ms: (at_ms + 10) as f64,
    data: SampleData::Pass(PassSample {
      frame_id: memory_bytes.map(|_| sequence),
      rendered: memory_bytes.is_some(),
      cached_render_list: false,
      total: Duration::from_millis(10),
      layout_update: Duration::from_millis(6),
      layout_compute: Duration::from_millis(2),
      component_after_layout: Duration::ZERO,
      layout_recalculated: true,
      canvas_recording: Duration::ZERO,
      canvas_preparation: Duration::ZERO,
      canvas_text: None,
      backend: "none",
      frame: memory_bytes.map(|total_bytes| FrameProfile {
        memory: RuntimeMemoryProfile {
          total_bytes,
          ..RuntimeMemoryProfile::default()
        },
        ..FrameProfile::default()
      }),
      spans: vec![
        span(Phase::PassSetup, 0, at_ms, at_ms + 10),
        span(Phase::LayoutUpdate, 1, at_ms + 1, at_ms + 7),
        span(Phase::Rebuild, 2, at_ms + 1, at_ms + 3),
        span(Phase::Commit, 3, at_ms + 2, at_ms + 3),
        span(Phase::LayoutCompute, 2, at_ms + 4, at_ms + 6),
        span(Phase::Render, 1, at_ms + 7, at_ms + 9),
      ],
      dropped_spans: 0,
      reasons: crate::app::PassReasons::default(),
      present: None,
      counters: None,
      gpu: None,
      component_layouts: Vec::new(),
      screenshot: false,
    }),
  })
}

fn marker_sample(sequence: u64, at_ms: f64, data: SampleData) -> Arc<ProfileSample> {
  Arc::new(ProfileSample {
    sequence,
    window: "main".into(),
    started_ms: at_ms,
    completed_ms: at_ms + 1.0,
    data,
  })
}

fn scope(
  id: u64,
  parent: Option<u64>,
  label: &'static str,
  lane: ApplicationLane,
  start_ms: u64,
  wall_ms: u64,
) -> Arc<ApplicationScopeSample> {
  Arc::new(ApplicationScopeSample {
    scope: ApplicationScopeInfo {
      id: ApplicationScopeId(id),
      parent_id: parent.map(ApplicationScopeId),
      depth: u32::from(parent.is_some()),
      window: "main".into(),
      label,
      lane,
      started_ms: start_ms as f64,
    },
    completed_ms: (start_ms + wall_ms) as f64,
    wall: Duration::from_millis(wall_ms),
  })
}

fn report(samples: Vec<Arc<ProfileSample>>, scopes: Vec<Arc<ApplicationScopeSample>>) -> ProfileReport {
  ProfileReport {
    id: SessionId(1),
    finalized: true,
    started_ms: 50.0,
    ended_ms: Some(400.0),
    observed_ms: 400.0,
    build: BuildAvailability::default(),
    max_samples: 0,
    completed_samples: samples.len() as u64,
    dropped_samples: 0,
    boundary_excluded_samples: 0,
    untracked_windows: 0,
    windows: Vec::new(),
    in_flight: Vec::new(),
    samples,
    application_scopes: Some(ApplicationScopeReport {
      available: true,
      max_live_scopes: MAX_APPLICATION_LIVE_SCOPES,
      max_samples: MAX_APPLICATION_SCOPES_PER_SESSION,
      started_scopes: scopes.len() as u64,
      completed_scopes: scopes.len() as u64,
      dropped_scopes: 0,
      boundary_excluded_scopes: 0,
      abandoned_window_closed: 0,
      abandoned_producer_closed: 0,
      refused: ApplicationRefusals::default(),
      in_flight: Vec::new(),
      samples: scopes,
    }),
    recording: None,
    screenshots: Vec::new(),
  }
}

/// Two presented passes, one that presented nothing, an input dispatch and a
/// UI update; a UI-lane scope with a child and two overlapping worker scopes.
pub(super) fn full_report() -> ProfileReport {
  report(
    vec![
      pass(1, "main", 100, Some(4096)),
      marker_sample(
        2,
        120.0,
        SampleData::InputDispatch(InputDispatchSample {
          frame_id: None,
          kind: InputKind::Pointer,
          total: Duration::from_millis(1),
          interaction_id: 1,
          queue_delay: Duration::from_micros(500),
          presented_frame_id: Some(4),
          input_to_present: Some(Duration::from_millis(90)),
        }),
      ),
      marker_sample(
        3,
        125.0,
        SampleData::UiUpdate(UiUpdateSample {
          frame_id: None,
          kind: UiUpdateKind::SubtreeRefresh,
          total: Duration::from_millis(1),
          commit: Duration::from_micros(250),
          causes: Vec::new(),
        }),
      ),
      pass(4, "main", 200, Some(6144)),
      pass(5, "main", 300, None),
    ],
    vec![
      scope(1, None, "load_document", ApplicationLane::Ui, 130, 20),
      scope(2, Some(1), "parse", ApplicationLane::Ui, 135, 5),
      scope(3, None, "decode_image", ApplicationLane::Worker, 140, 30),
      scope(4, None, "decode_image", ApplicationLane::Worker, 150, 30),
    ],
  )
}

fn profile(report: &ProfileReport) -> Value {
  serde_json::from_str(&report.to_firefox_profile()).expect("the converter writes JSON")
}

fn thread<'a>(profile: &'a Value, name: &str) -> &'a Value {
  profile["threads"]
    .as_array()
    .unwrap()
    .iter()
    .find(|thread| thread["name"] == name)
    .unwrap_or_else(|| panic!("no thread {name}"))
}

fn strings(thread: &Value) -> Vec<&str> {
  thread["stringArray"]
    .as_array()
    .unwrap()
    .iter()
    .map(|string| string.as_str().unwrap())
    .collect()
}

/// Per stack path, root first, the weight of the samples whose innermost
/// frame it is: what the profiler's call tree shows as self time.
fn self_ms_by_path(thread: &Value) -> BTreeMap<Vec<String>, f64> {
  let strings = strings(thread);
  let column = |table: &str, key: &str| thread[table][key].as_array().unwrap().clone();
  let (prefixes, frames) = (column("stackTable", "prefix"), column("stackTable", "frame"));
  let (frame_funcs, func_names) = (column("frameTable", "func"), column("funcTable", "name"));
  let samples = &thread["samples"];
  let mut by_path = BTreeMap::new();
  for (stack, weight) in samples["stack"]
    .as_array()
    .unwrap()
    .iter()
    .zip(samples["weight"].as_array().unwrap())
  {
    let Some(mut stack) = stack.as_u64() else {
      continue;
    };
    let mut path = Vec::new();
    loop {
      let func = frame_funcs[frames[stack as usize].as_u64().unwrap() as usize]
        .as_u64()
        .unwrap();
      path.push(strings[func_names[func as usize].as_u64().unwrap() as usize].to_owned());
      match prefixes[stack as usize].as_u64() {
        Some(prefix) => stack = prefix,
        None => break,
      }
    }
    path.reverse();
    *by_path.entry(path).or_insert(0.0) += weight.as_f64().unwrap();
  }
  by_path
}

fn path(names: &[&str]) -> Vec<String> {
  names.iter().map(|name| (*name).to_owned()).collect()
}

fn close(a: f64, b: f64) -> bool {
  (a - b).abs() < 1e-9
}

#[test]
fn the_profile_is_a_processed_profile_with_a_thread_per_lane() {
  let profile = profile(&full_report());
  let meta = &profile["meta"];
  assert_eq!(meta["preprocessedProfileVersion"], FIREFOX_PROCESSED_PROFILE_VERSION);
  assert_eq!(meta["product"], "lurq");
  assert_eq!(
    meta["categories"][0]["color"], "grey",
    "the default category comes first"
  );
  for key in ["libs", "pages", "profilerOverhead"] {
    assert_eq!(profile[key], Value::Array(Vec::new()), "{key}");
  }
  let names: Vec<_> = profile["threads"]
    .as_array()
    .unwrap()
    .iter()
    .map(|thread| thread["name"].as_str().unwrap())
    .collect();
  // The overlapping worker scopes go to a second worker thread.
  assert_eq!(names, vec!["UI", "UI scopes", "Worker", "Worker 2"]);
  for (index, thread) in profile["threads"].as_array().unwrap().iter().enumerate() {
    assert_eq!(thread["isMainThread"], index == 0);
    assert_eq!(thread["processStartupTime"], 50.0);
    assert_eq!(thread["processShutdownTime"], 400.0);
    // Every column of a table is as long as the table says.
    for table in [
      "frameTable",
      "funcTable",
      "stackTable",
      "samples",
      "markers",
      "nativeSymbols",
      "resourceTable",
    ] {
      let table_value = &thread[table];
      let length = table_value["length"].as_u64().unwrap();
      for (key, column) in table_value.as_object().unwrap() {
        if let Some(column) = column.as_array() {
          assert_eq!(column.len() as u64, length, "{} {table}.{key}", names[index]);
        }
      }
    }
    assert_eq!(thread["samples"]["weightType"], "tracing-ms");
    // Indices stay inside the tables they point into.
    let strings = strings(thread).len() as u64;
    let len = |table: &str| thread[table]["length"].as_u64().unwrap();
    let all_below = |table: &str, key: &str, bound: u64| {
      thread[table][key]
        .as_array()
        .unwrap()
        .iter()
        .filter_map(Value::as_u64)
        .all(|index| index < bound)
    };
    assert!(all_below("funcTable", "name", strings));
    assert!(all_below("frameTable", "func", len("funcTable")));
    assert!(all_below("frameTable", "category", 4));
    assert!(all_below("stackTable", "frame", len("frameTable")));
    assert!(all_below("stackTable", "prefix", len("stackTable")));
    assert!(all_below("samples", "stack", len("stackTable")));
    assert!(all_below("markers", "name", strings));
  }
}

#[test]
fn sample_weights_make_the_call_tree_of_the_spans() {
  let profile = profile(&full_report());
  let ui = self_ms_by_path(thread(&profile, "UI"));
  // Self time of each of the three passes.
  let expected = [
    (&["pass"][..], 2.0),
    (&["pass", "layout_update"], 2.0),
    (&["pass", "layout_update", "ui_rebuild"], 1.0),
    (&["pass", "layout_update", "ui_rebuild", "ui_commit"], 1.0),
    (&["pass", "layout_update", "layout_compute"], 2.0),
    (&["pass", "render"], 2.0),
  ];
  for (names, per_pass_ms) in expected {
    let self_ms = ui[&path(names)];
    assert!(close(self_ms, per_pass_ms * 3.0), "{names:?}: {self_ms}");
  }
  assert_eq!(ui.len(), expected.len());
  let total: f64 = ui.values().sum();
  assert!(close(total, 30.0), "the passes' time once: {total}");

  let scopes = self_ms_by_path(thread(&profile, "UI scopes"));
  assert!(close(scopes[&path(&["load_document"])], 15.0));
  assert!(close(scopes[&path(&["load_document", "parse"])], 5.0));
  for worker in ["Worker", "Worker 2"] {
    let lane = self_ms_by_path(thread(&profile, worker));
    assert!(close(lane[&path(&["decode_image"])], 30.0), "{worker}");
  }
}

#[test]
fn samples_follow_the_spans_on_the_time_axis() {
  let profile = profile(&full_report());
  let ui = thread(&profile, "UI");
  let samples = &ui["samples"];
  let mut at_ms = 0.0;
  let times: Vec<f64> = samples["timeDeltas"]
    .as_array()
    .unwrap()
    .iter()
    .map(|delta| {
      at_ms += delta.as_f64().unwrap();
      at_ms
    })
    .collect();
  let stacks = samples["stack"].as_array().unwrap();
  // The first pass: its own time from 100, then layout_update, ...
  assert!(close(times[0], 100.0));
  assert!(times.windows(2).all(|pair| pair[1] > pair[0]), "{times:?}");
  // Each pass ends in a sample of no stack until the next one starts.
  let idle: Vec<f64> = times
    .iter()
    .zip(stacks)
    .filter(|(_, stack)| stack.is_null())
    .map(|(at, _)| *at)
    .collect();
  assert_eq!(idle.len(), 3);
  for (at, end) in idle.iter().zip([110.0, 210.0, 310.0]) {
    assert!(close(*at, end), "{idle:?}");
  }
}

#[test]
fn frames_input_and_ui_updates_are_markers_on_the_ui_thread() {
  let profile = profile(&full_report());
  let ui = thread(&profile, "UI");
  let strings = strings(ui);
  let markers = &ui["markers"];
  let names: Vec<&str> = markers["name"]
    .as_array()
    .unwrap()
    .iter()
    .map(|name| strings[name.as_u64().unwrap() as usize])
    .collect();
  assert_eq!(names, vec!["Frame", "Input", "UI update", "Frame", "Pass"]);
  let types: Vec<&str> = markers["data"]
    .as_array()
    .unwrap()
    .iter()
    .map(|data| data["type"].as_str().unwrap())
    .collect();
  assert_eq!(
    types,
    vec!["LurqPass", "LurqInput", "LurqUiUpdate", "LurqPass", "LurqPass"]
  );
  let schema_names: Vec<&str> = profile["meta"]["markerSchema"]
    .as_array()
    .unwrap()
    .iter()
    .map(|schema| schema["name"].as_str().unwrap())
    .collect();
  for marker_type in &types {
    assert!(schema_names.contains(marker_type), "{marker_type} has no schema");
  }
  assert_eq!(markers["phase"][0], 1);
  assert_eq!(markers["startTime"][0], 100.0);
  assert_eq!(markers["endTime"][0], 110.0);
  let input = &markers["data"][1];
  assert_eq!(strings[input["kind"].as_u64().unwrap() as usize], "pointer");
  assert_eq!(strings[input["window"].as_u64().unwrap() as usize], "main");
  assert_eq!(input["interactionId"], 1);
  assert!(close(input["queueDelay"].as_f64().unwrap(), 0.5));
  assert!(close(input["dispatch"].as_f64().unwrap(), 1.0));
  assert_eq!(input["presentedFrameId"], 4);
  assert!(close(input["inputToPresent"].as_f64().unwrap(), 90.0));
  assert_eq!(markers["data"][0]["frameId"], 1);
  assert!(
    markers["data"][4].get("frameId").is_none(),
    "a pass that presented nothing has no frame id"
  );
  assert!(close(markers["data"][2]["commit"].as_f64().unwrap(), 0.25));
  // An update without causes (not a detailed recording) has no causes field.
  assert!(markers["data"][2].get("causes").is_none());
  // Only the UI thread holds markers.
  assert_eq!(thread(&profile, "Worker")["markers"]["length"], 0);
}

fn recording_status(detailed: bool) -> RecordingStatus {
  RecordingStatus {
    max_bytes: DEFAULT_RECORDING_MAX_BYTES,
    size_bytes: 0,
    stopped_at_limit: false,
    stopped_ms: None,
    detailed,
    screenshots: 0,
    screenshot_bytes: 0,
  }
}

#[test]
fn a_detailed_recording_names_components_in_the_call_tree_and_causes_on_its_updates() {
  let mut report = full_report();
  report.recording = Some(recording_status(true));
  let SampleData::Pass(pass) = &mut Arc::make_mut(&mut report.samples[0]).data else {
    unreachable!("the first sample is a pass")
  };
  // A component render inside ui_rebuild +1..+3, before its commit.
  let at_ms = pass.spans[0].start_ns / MS;
  pass.spans.insert(
    3,
    PhaseSpan {
      component: Some("Counter"),
      ..span(Phase::Rebuild, 3, at_ms + 1, at_ms + 2)
    },
  );
  let SampleData::UiUpdate(update) = &mut Arc::make_mut(&mut report.samples[2]).data else {
    unreachable!("the third sample is a UI update")
  };
  update.causes = vec![
    RenderCause {
      component: "Counter",
      source: RenderSource {
        trigger: RenderTrigger::Signal,
        value_type: Some("u32"),
      },
      via: None,
    },
    RenderCause {
      component: "Total",
      source: RenderSource {
        trigger: RenderTrigger::Memo,
        value_type: Some("u64"),
      },
      via: Some(RenderSource {
        trigger: RenderTrigger::Signal,
        value_type: Some("u32"),
      }),
    },
  ];
  let profile = profile(&report);
  let ui = thread(&profile, "UI");
  assert!(
    strings(ui).contains(&"Counter"),
    "the component is a function of the call tree"
  );
  assert_eq!(
    ui["markers"]["data"][2]["causes"],
    "Counter: signal u32; Total: memo u64 via signal u32"
  );
}

fn counts(counter: &Value) -> Vec<f64> {
  counter["samples"]["count"]
    .as_array()
    .unwrap()
    .iter()
    .map(|count| count.as_f64().unwrap())
    .collect()
}

#[test]
fn the_memory_counter_adds_up_to_each_presented_estimate() {
  let profile = profile(&full_report());
  let counters = profile["counters"].as_array().unwrap();
  assert_eq!(counters.len(), 1);
  let counter = &counters[0];
  assert_eq!(counter["category"], "Memory");
  assert_eq!(counter["name"], "Runtime memory");
  assert_eq!(counter["mainThreadIndex"], 0);
  let samples = &counter["samples"];
  assert_eq!(samples["length"], 2);
  assert_eq!(counts(counter), vec![4096.0, 2048.0]);
  assert_eq!(samples["timeDeltas"][0], 110.0);
  assert_eq!(samples["timeDeltas"][1], 100.0);

  // Without a frame profile or pass counters there is nothing to count.
  let unpresented = profile_of_samples(vec![pass(1, "main", 100, None)]);
  assert_eq!(unpresented["counters"], Value::Array(Vec::new()));
}

/// `pass` with counters taken at its end, and allocations when `live_bytes`.
fn counted_pass(
  sequence: u64,
  at_ms: u64,
  frame_memory: Option<usize>,
  memory_bytes: usize,
  live_bytes: Option<u64>,
) -> Arc<ProfileSample> {
  let mut sample = Arc::unwrap_or_clone(pass(sequence, "main", at_ms, frame_memory));
  let SampleData::Pass(pass) = &mut sample.data else {
    unreachable!()
  };
  pass.counters = Some(PassCounters {
    nodes: 12,
    memory_bytes,
    caches: CacheSizes::default(),
    allocations: live_bytes.map(|live_bytes| PassAllocations {
      live_bytes,
      ..PassAllocations::default()
    }),
  });
  Arc::new(sample)
}

#[test]
fn pass_counters_feed_the_memory_and_live_heap_counters() {
  let profile = profile_of_samples(vec![
    // The pass's own estimate wins over the frame's cached one.
    counted_pass(1, 100, Some(1), 1000, Some(5000)),
    // Counted without a presented frame, and without an allocator.
    counted_pass(2, 200, None, 1500, None),
    counted_pass(3, 300, None, 1200, Some(4000)),
  ]);
  let counters = profile["counters"].as_array().unwrap();
  let names: Vec<_> = counters
    .iter()
    .map(|counter| counter["name"].as_str().unwrap())
    .collect();
  assert_eq!(names, vec!["Runtime memory", "Live heap"]);
  assert_eq!(counts(&counters[0]), vec![1000.0, 500.0, -300.0]);
  assert_eq!(counts(&counters[1]), vec![5000.0, -1000.0]);
  assert_eq!(counters[1]["samples"]["timeDeltas"][1], 200.0);
}

fn profile_of_samples(samples: Vec<Arc<ProfileSample>>) -> Value {
  profile(&report(samples, Vec::new()))
}

#[test]
fn an_empty_recording_is_one_empty_ui_thread() {
  let mut empty = report(Vec::new(), Vec::new());
  empty.application_scopes = None;
  let profile = profile(&empty);
  let threads = profile["threads"].as_array().unwrap();
  assert_eq!(threads.len(), 1);
  assert_eq!(threads[0]["name"], "UI");
  assert_eq!(threads[0]["samples"]["length"], 0);
  assert_eq!(threads[0]["markers"]["length"], 0);
}

#[test]
fn passes_of_two_windows_that_overlap_get_a_ui_thread_each() {
  let profile = profile_of_samples(vec![pass(1, "main", 100, None), pass(2, "w1", 105, None)]);
  let names: Vec<_> = profile["threads"]
    .as_array()
    .unwrap()
    .iter()
    .map(|thread| thread["name"].as_str().unwrap().to_owned())
    .collect();
  assert_eq!(names, vec!["UI", "UI 2"]);
  for name in ["UI", "UI 2"] {
    let total: f64 = self_ms_by_path(thread(&profile, name)).values().sum();
    assert!(close(total, 10.0), "{name}: {total}");
  }
}

#[test]
fn the_profile_holds_only_names_of_the_toolkit_and_the_recording() {
  let profile = profile(&full_report());
  let mut all = Vec::new();
  for thread in profile["threads"].as_array().unwrap() {
    all.extend(strings(thread).into_iter().map(str::to_owned));
  }
  let phases: Vec<&str> = phase_slot::PHASES.iter().map(|phase| phase.name()).collect();
  for string in all {
    let known = phases.contains(&string.as_str())
      || [
        "pass",
        "main",
        "pointer",
        "subtree_refresh",
        "Frame",
        "Pass",
        "Input",
        "UI update",
        "load_document",
        "parse",
        "decode_image",
      ]
      .contains(&string.as_str());
    assert!(known, "unexpected string {string:?}");
  }
}

#[test]
fn a_report_that_is_not_a_detailed_recording_shows_no_components_or_causes() {
  // A bounded session shares its samples with a detailed recording beside it.
  let mut report = full_report();
  let SampleData::Pass(pass) = &mut Arc::make_mut(&mut report.samples[0]).data else {
    unreachable!("the first sample is a pass")
  };
  let at_ms = pass.spans[0].start_ns / MS;
  pass.spans.insert(
    3,
    PhaseSpan {
      component: Some("Counter"),
      ..span(Phase::Rebuild, 3, at_ms + 1, at_ms + 2)
    },
  );
  let SampleData::UiUpdate(update) = &mut Arc::make_mut(&mut report.samples[2]).data else {
    unreachable!("the third sample is a UI update")
  };
  update.causes = vec![RenderCause {
    component: "Counter",
    source: RenderSource {
      trigger: RenderTrigger::Signal,
      value_type: Some("u32"),
    },
    via: None,
  }];
  for recording in [None, Some(recording_status(false))] {
    report.recording = recording;
    let file = report.to_firefox_profile();
    assert!(!file.contains("Counter"), "{recording:?}");
    assert!(!file.contains("u32"), "{recording:?}");
  }
}