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
//! Timing knobs, profiling counters and the profiling clock.
use std::time::Duration;
use web_time::Instant;
use crate::store::SNAPSHOT_INTERVAL;
/// Timing knobs of a grid.
#[derive(Clone, Copy, Debug)]
pub struct GridTuning {
pub(super) min_rebuild_interval: Duration,
pub(super) pull_interval: Duration,
}
impl Default for GridTuning {
fn default() -> Self {
Self {
min_rebuild_interval: Duration::from_millis(100),
pull_interval: SNAPSHOT_INTERVAL,
}
}
}
impl GridTuning {
/// Rebuilds caused by data start at most this often (user actions
/// rebuild at once). Default 100 ms, like LiveGrid.
pub fn with_min_rebuild_interval(mut self, interval: Duration) -> Self {
self.min_rebuild_interval = interval;
self
}
/// Snapshots are pulled from the store at most this often. Default 8 ms,
/// the store's default publish interval
/// ([`StoreOptions::with_publish_interval`](crate::StoreOptions::with_publish_interval)).
pub fn with_pull_interval(mut self, interval: Duration) -> Self {
self.pull_interval = interval;
self
}
}
/// Counters for profiling a grid.
#[derive(Clone, Copy, Debug, Default)]
pub struct GridStats {
pub(super) frames: u64,
pub(super) rebuilds: u64,
pub(super) last_rebuild: Duration,
pub(super) max_rebuild: Duration,
pub(super) last_prepaint: Duration,
pub(super) last_header_render: Duration,
pub(super) last_pull: Duration,
pub(super) fade_wakeups: u64,
pub(super) visible_cells: usize,
pub(super) icons: usize,
pub(super) snapshots: u64,
pub(super) compactions: u64,
pub(super) tombstones: usize,
pub(super) fading_lines: usize,
pub(super) painted_captions: usize,
pub(super) a11y_rows: usize,
pub(super) a11y_cells: usize,
pub(super) last_a11y_plan: Duration,
// The tree.
pub(super) tree_cycles: usize,
// Elements in the body's rows.
pub(super) cell_hosts: usize,
pub(super) last_hosts_prepaint: Duration,
// Images in cells.
pub(super) images: usize,
// The drop target of the last drag move.
pub(super) last_drop_target: Duration,
}
impl GridStats {
/// Frames painted.
pub fn frames(&self) -> u64 {
self.frames
}
/// Projection rebuilds finished.
pub fn rebuilds(&self) -> u64 {
self.rebuilds
}
/// CPU time of the last rebuild (background thread).
pub fn last_rebuild(&self) -> Duration {
self.last_rebuild
}
/// CPU time of the slowest rebuild.
pub fn max_rebuild(&self) -> Duration {
self.max_rebuild
}
/// CPU time of the last frame plan (prepaint of the body).
pub fn last_prepaint(&self) -> Duration {
self.last_prepaint
}
/// CPU time of the last header build (its elements, in `render`).
pub fn last_header_render(&self) -> Duration {
self.last_header_render
}
/// CPU time of applying the last store snapshot on the UI thread: the
/// pull, with what removals do to the selection and the focus.
pub fn last_pull(&self) -> Duration {
self.last_pull
}
/// Repaints caused only by the highlight fade timer.
pub fn fade_wakeups(&self) -> u64 {
self.fade_wakeups
}
/// Cells planned in the last frame.
pub fn visible_cells(&self) -> usize {
self.visible_cells
}
/// Icons painted in the body in the last frame: change arrows
/// (`CellStyle::set_trend`), icons at the start of cells and icons of
/// `CellValue::Icon` cells.
pub fn icons(&self) -> usize {
self.icons
}
/// Images painted in the body in the last frame: the `CellValue::Image`
/// cells whose image was ready.
pub fn images(&self) -> usize {
self.images
}
/// Store snapshots pulled.
pub fn snapshots(&self) -> u64 {
self.snapshots
}
/// Projections compacted after removals (no sorting).
pub fn compactions(&self) -> u64 {
self.compactions
}
/// Removed rows skipped while painting the last frame, before the
/// projection caught up: rows without a removal fade, and fading rows
/// whose fade ended.
pub fn tombstones(&self) -> usize {
self.tombstones
}
/// Removed rows painted fading out in the last frame
/// ([`HighlightPolicy::with_removal_fade`]).
///
/// [`HighlightPolicy::with_removal_fade`]: crate::HighlightPolicy::with_removal_fade
pub fn fading_lines(&self) -> usize {
self.fading_lines
}
/// Group captions painted in the last frame.
pub fn painted_captions(&self) -> usize {
self.painted_captions
}
/// Row nodes of the accessibility tree planned in the last frame: the
/// painted data and pinned rows, and group captions. Zero while
/// accessibility is off.
pub fn a11y_rows(&self) -> usize {
self.a11y_rows
}
/// Synthetic cell nodes planned in the last frame: the painted cells
/// but the focused one. Zero while accessibility is off.
pub fn a11y_cells(&self) -> usize {
self.a11y_cells
}
/// CPU time of the last frame's accessibility plan, after the cell walk
/// gathered its texts. Zero while accessibility is off. With
/// `LiveGridState::set_a11y_forced` in a window whose accessibility is
/// off (headless tests and benchmarks), it also builds the nodes GPUI
/// would build from the plan, so it times both.
pub fn last_a11y_plan(&self) -> Duration {
self.last_a11y_plan
}
// The tree's cycles.
/// Rows of the tree shown made roots because their parents form a cycle
/// (`Projection::tree_cycles`); 0 for a flat or grouped view. A row
/// that is its own parent is a root but no cycle.
pub fn tree_cycles(&self) -> usize {
self.tree_cycles
}
// Elements in the body's rows.
/// Cell hosts planned in the last frame: real elements in cells, such
/// as the elements of `Element` and `Control` columns and an open
/// editor.
pub fn cell_hosts(&self) -> usize {
self.cell_hosts
}
/// CPU time of the layout and prepaint of the last frame's row
/// elements, when it had cell hosts; zero otherwise.
pub fn last_hosts_prepaint(&self) -> Duration {
self.last_hosts_prepaint
}
/// Main-thread time the last move of a drag over the rows took to place
/// it: the hit test and the drop policy (S38).
pub fn last_drop_target(&self) -> Duration {
self.last_drop_target
}
/// These counters with `tree_cycles` of the projection shown.
pub(super) fn with_tree_cycles(mut self, tree_cycles: usize) -> Self {
self.tree_cycles = tree_cycles;
self
}
}
/// Profiling clock for job and frame durations: `std::time::Instant` on
/// native targets and `performance.now()` in the browser (`web_time`), where
/// `std::time::Instant::now` panics.
pub(super) fn profile_start() -> Option<Instant> {
Some(Instant::now())
}
pub(super) fn profile_elapsed(started: Option<Instant>) -> Duration {
started.map_or(Duration::ZERO, |started| started.elapsed())
}