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
//! Per-pool observation of scheduler task churn and capacity waiting.
//!
//! A pool spawns exactly one scheduler task, when the pool is constructed.
//! Every later acquisition is a command to that task, so an acquire/drop burst
//! adds nothing to [`PoolTaskChurn::scheduler_spawns`]. The counter therefore
//! witnesses construction, not slow-path entry; [`PoolTaskChurn::capacity_waits`]
//! is the direct observation that callers genuinely queued for capacity.
//!
//! # Why the counters are per-pool and not process-wide
//!
//! An earlier revision kept these counts in a `static`, which made them
//! process-global. That is unusable from a test binary: every pool in the
//! process — including pools another test is driving concurrently on another
//! thread — contributed to the same number, so a delta read across one
//! workload silently absorbed every other workload's churn. Serializing only
//! the assertion would not have fixed it, because the contamination happens
//! while the *other* workload runs, not while the assertion reads. Moving the
//! counters onto the scheduler makes a delta unambiguous: it can only be
//! attributed to the pool the observer was taken from.
//!
//! The counters live in their own module rather than in `scheduler.rs` so the
//! scheduler module stays inside the workspace's 400-line module limit.
//!
//! # Cost
//!
//! Both counters are relaxed atomic increments on a cache line owned by a
//! single pool. They are written by the scheduler task alone — construction
//! records the spawn, and the acquire handler records a wait — so they add no
//! synchronization to a caller's path. See [`PoolTaskChurnObserver`] for the
//! no-op claim that matters — that observing changes nothing.
use ;
/// Counters describing one pool's scheduler activity.
///
/// A plain struct of integers rather than a handle, so a caller can snapshot
/// it, store it, and subtract one snapshot from another without holding the
/// pool alive.
/// The live counters behind a [`PoolTaskChurnObserver`].
///
/// Atomic so the observer can read them from any thread while the scheduler
/// task writes them from its own.
pub
/// A read-only handle onto one pool's task-churn counters.
///
/// Returned by `WireframeClientPool::task_churn_observer`. Cloning it is cheap
/// and shares the same counters; dropping every clone drops the counters once
/// the pool itself is gone.
///
/// Observing is passive. Taking an observer, snapshotting it, and dropping it
/// performs no acquire, spawns no task, and mutates no counter, so a bracket
/// built from snapshots cannot perturb the pool it measures. That matters
/// because the counts being bracketed are themselves affected by any
/// acquisition the bracket's own instrumentation might perform.
///
/// # Examples
///
/// ```rust,no_run
/// # async fn example(pool: &wireframe::client::WireframeClientPool<
/// # wireframe::serializer::BincodeSerializer, (), (),
/// # >) -> Result<(), String> {
/// let observer = pool.task_churn_observer();
/// let before = observer.snapshot();
/// // ... exercise pooled handles ...
/// let churn = observer.snapshot().since(before);
/// // The pool already owns its scheduler task, so acquiring and releasing
/// // leases spawns nothing.
/// assert_eq!(churn.scheduler_spawns, 0);
/// # Ok(())
/// # }
/// ```