|
26 | 26 | //! tests don't construct. There is no per-tab equivalent of them for the |
27 | 27 | //! same reason — see [`TabRenderStats`]. |
28 | 28 |
|
29 | | -use std::sync::atomic::{AtomicU64, Ordering}; |
30 | 29 | use std::time::Duration; |
31 | 30 |
|
32 | | -static REFRESH_CALLS: AtomicU64 = AtomicU64::new(0); |
33 | | -static REFRESH_NANOS: AtomicU64 = AtomicU64::new(0); |
34 | | -static ROWS_REBUILT: AtomicU64 = AtomicU64::new(0); |
35 | | -static CELLS_WALKED: AtomicU64 = AtomicU64::new(0); |
36 | | -static DRAW_CALLS: AtomicU64 = AtomicU64::new(0); |
37 | | -static DRAW_NANOS: AtomicU64 = AtomicU64::new(0); |
38 | | -static FILL_TEXT_CALLS: AtomicU64 = AtomicU64::new(0); |
| 31 | +/// `RenderStats` + `TabRenderStats` + the atomic aggregate machinery moved |
| 32 | +/// to `roost-ui-model::render_stats` once GTK needed the identical shape |
| 33 | +/// (plan 018 D4); re-exported here so every call site in this crate keeps |
| 34 | +/// compiling unchanged. |
| 35 | +pub use roost_ui_model::render_stats::{RenderStats, TabRenderStats}; |
39 | 36 |
|
40 | | -/// A read of the process-global aggregate at one instant. Every field is a |
41 | | -/// running total since process start (or the last [`reset`]). |
42 | | -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
43 | | -pub struct RenderStats { |
44 | | - pub refresh_calls: u64, |
45 | | - pub refresh_nanos: u64, |
46 | | - pub rows_rebuilt: u64, |
47 | | - pub cells_walked: u64, |
48 | | - pub draw_calls: u64, |
49 | | - pub draw_nanos: u64, |
50 | | - pub fill_text_calls: u64, |
51 | | -} |
52 | | - |
53 | | -/// Per-tab counters, folded into the global aggregate on every refresh. |
54 | | -/// There is deliberately no per-tab equivalent of `draw_calls` / |
55 | | -/// `draw_nanos` / `fill_text_calls`: `TerminalWidget::draw` renders from a |
56 | | -/// `TerminalSnapshot` clone handed to it by iced and has no way back to the |
57 | | -/// `TerminalTab` that produced it, so those three counters only exist in |
58 | | -/// the global aggregate. |
59 | | -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
60 | | -pub struct TabRenderStats { |
61 | | - pub refresh_calls: u64, |
62 | | - pub refresh_nanos: u64, |
63 | | - pub rows_rebuilt: u64, |
64 | | - pub cells_walked: u64, |
65 | | -} |
| 37 | +use roost_ui_model::render_stats::RenderStatsAggregate; |
66 | 38 |
|
67 | | -impl TabRenderStats { |
68 | | - pub(crate) fn record_refresh( |
69 | | - &mut self, |
70 | | - elapsed: Duration, |
71 | | - rows_rebuilt: u64, |
72 | | - cells_walked: u64, |
73 | | - ) { |
74 | | - self.refresh_calls += 1; |
75 | | - self.refresh_nanos += elapsed.as_nanos() as u64; |
76 | | - self.rows_rebuilt += rows_rebuilt; |
77 | | - self.cells_walked += cells_walked; |
78 | | - } |
79 | | -} |
| 39 | +/// This UI's process-global aggregate. GTK holds its own in |
| 40 | +/// `roost-linux::perf`; the two never mix. |
| 41 | +static AGGREGATE: RenderStatsAggregate = RenderStatsAggregate::new(); |
80 | 42 |
|
81 | 43 | /// Read the global aggregate. Backs the `app.render_stats` IPC op. |
82 | 44 | pub fn snapshot() -> RenderStats { |
83 | | - RenderStats { |
84 | | - refresh_calls: REFRESH_CALLS.load(Ordering::Relaxed), |
85 | | - refresh_nanos: REFRESH_NANOS.load(Ordering::Relaxed), |
86 | | - rows_rebuilt: ROWS_REBUILT.load(Ordering::Relaxed), |
87 | | - cells_walked: CELLS_WALKED.load(Ordering::Relaxed), |
88 | | - draw_calls: DRAW_CALLS.load(Ordering::Relaxed), |
89 | | - draw_nanos: DRAW_NANOS.load(Ordering::Relaxed), |
90 | | - fill_text_calls: FILL_TEXT_CALLS.load(Ordering::Relaxed), |
91 | | - } |
| 45 | + AGGREGATE.snapshot() |
92 | 46 | } |
93 | 47 |
|
94 | 48 | /// Zero the global aggregate. Useful before an operation known to skew it |
95 | 49 | /// (see the screenshot trap above) so the next read is uncontaminated. |
96 | 50 | /// Exposed over IPC as `app.render_stats` with `reset: true`. |
97 | 51 | pub fn reset() { |
98 | | - REFRESH_CALLS.store(0, Ordering::Relaxed); |
99 | | - REFRESH_NANOS.store(0, Ordering::Relaxed); |
100 | | - ROWS_REBUILT.store(0, Ordering::Relaxed); |
101 | | - CELLS_WALKED.store(0, Ordering::Relaxed); |
102 | | - DRAW_CALLS.store(0, Ordering::Relaxed); |
103 | | - DRAW_NANOS.store(0, Ordering::Relaxed); |
104 | | - FILL_TEXT_CALLS.store(0, Ordering::Relaxed); |
| 52 | + AGGREGATE.reset(); |
105 | 53 | } |
106 | 54 |
|
107 | 55 | /// Fold one `refresh_snapshot` call into the global aggregate. |
108 | 56 | pub(crate) fn record_refresh(elapsed: Duration, rows_rebuilt: u64, cells_walked: u64) { |
109 | | - REFRESH_CALLS.fetch_add(1, Ordering::Relaxed); |
110 | | - REFRESH_NANOS.fetch_add(elapsed.as_nanos() as u64, Ordering::Relaxed); |
111 | | - ROWS_REBUILT.fetch_add(rows_rebuilt, Ordering::Relaxed); |
112 | | - CELLS_WALKED.fetch_add(cells_walked, Ordering::Relaxed); |
| 57 | + AGGREGATE.record_refresh(elapsed, rows_rebuilt, cells_walked); |
113 | 58 | } |
114 | 59 |
|
115 | 60 | /// Fold one `TerminalWidget::draw` call into the global aggregate. |
116 | 61 | pub(crate) fn record_draw(elapsed: Duration, fill_text_calls: u64) { |
117 | | - DRAW_CALLS.fetch_add(1, Ordering::Relaxed); |
118 | | - DRAW_NANOS.fetch_add(elapsed.as_nanos() as u64, Ordering::Relaxed); |
119 | | - FILL_TEXT_CALLS.fetch_add(fill_text_calls, Ordering::Relaxed); |
| 62 | + AGGREGATE.record_draw(elapsed, fill_text_calls); |
120 | 63 | } |
0 commit comments