Branch data Line data Source code
1 : : #include "mem.h"
2 : :
3 : : Telemetry telemetry = {0};
4 : :
5 : : #ifndef ROUGH_DEBUG
6 : : #define ROUGH_DEBUG 0
7 : : #endif
8 : :
9 : : /**
10 : : * @brief Update the peak heap usage counter if @p updated_current_bytes exceeds it.
11 : : *
12 : : * @param updated_current_bytes Newly observed heap usage value.
13 : : */
14 : 22305 : static void telemetry_peak_heap_reserved_bytes_update(const size_t updated_current_bytes)
15 : : {
16 : 22305 : size_t observed_peak = __atomic_load_n(&telemetry.peak_heap_reserved_bytes,__ATOMIC_SEQ_CST);
17 : :
18 [ + + ]: 22305 : while(updated_current_bytes > observed_peak)
19 : : {
20 [ + - ]: 1748 : if(__atomic_compare_exchange_n(
21 : : &telemetry.peak_heap_reserved_bytes,
22 : : &observed_peak,
23 : : updated_current_bytes,
24 : : false,
25 : : __ATOMIC_SEQ_CST,
26 : : __ATOMIC_SEQ_CST))
27 : : {
28 : 1748 : break;
29 : : }
30 : : }
31 : 22305 : }
32 : :
33 : : /**
34 : : * @brief Track the maximum block overhead observed at runtime.
35 : : *
36 : : * @param updated_current_overhead Current block-overhead consumption in bytes.
37 : : */
38 : 27726 : static void telemetry_peak_block_overhead_bytes_update(const size_t updated_current_overhead)
39 : : {
40 : 27726 : size_t observed_peak = __atomic_load_n(&telemetry.peak_block_overhead_bytes,__ATOMIC_SEQ_CST);
41 : :
42 [ + + ]: 27726 : while(updated_current_overhead > observed_peak)
43 : : {
44 [ + - ]: 1726 : if(__atomic_compare_exchange_n(
45 : : &telemetry.peak_block_overhead_bytes,
46 : : &observed_peak,
47 : : updated_current_overhead,
48 : : false,
49 : : __ATOMIC_SEQ_CST,
50 : : __ATOMIC_SEQ_CST))
51 : : {
52 : 1726 : break;
53 : : }
54 : : }
55 : 27726 : }
56 : :
57 : : /**
58 : : * @brief Record the highest number of simultaneously active descriptors.
59 : : *
60 : : * @param updated_current_active_descriptors Current count of active descriptors.
61 : : */
62 : 22277 : static void telemetry_peak_active_descriptors_update(const size_t updated_current_active_descriptors)
63 : : {
64 : 22277 : size_t observed_peak = __atomic_load_n(&telemetry.peak_active_descriptors,__ATOMIC_SEQ_CST);
65 : :
66 [ + + ]: 22277 : while(updated_current_active_descriptors > observed_peak)
67 : : {
68 [ + - ]: 1556 : if(__atomic_compare_exchange_n(
69 : : &telemetry.peak_active_descriptors,
70 : : &observed_peak,
71 : : updated_current_active_descriptors,
72 : : false,
73 : : __ATOMIC_SEQ_CST,
74 : : __ATOMIC_SEQ_CST))
75 : : {
76 : 1556 : break;
77 : : }
78 : : }
79 : 22277 : }
80 : :
81 : 50541 : void telemetry_in_place_resizes(void)
82 : : {
83 : 50541 : __atomic_fetch_add(&telemetry.in_place_resizes,1,__ATOMIC_SEQ_CST);
84 : 50541 : }
85 : :
86 : 22277 : void telemetry_fresh_heap_allocations(void)
87 : : {
88 : 22277 : __atomic_fetch_add(&telemetry.fresh_heap_allocations,1,__ATOMIC_SEQ_CST);
89 : 22277 : }
90 : :
91 : 1277 : void telemetry_zero_initialized_payload_growths(void)
92 : : {
93 : 1277 : __atomic_fetch_add(&telemetry.zero_initialized_payload_growths,1,__ATOMIC_SEQ_CST);
94 : 1277 : }
95 : :
96 : 32 : void telemetry_heap_reallocations(void)
97 : : {
98 : 32 : __atomic_fetch_add(&telemetry.heap_reallocations,1,__ATOMIC_SEQ_CST);
99 : : #if ROUGH_DEBUG
100 : : printf("telemetry.heap_reallocations: %zu\n",telemetry.heap_reallocations);
101 : : #endif
102 : 32 : }
103 : :
104 : 1781 : void telemetry_noop_resizes(void)
105 : : {
106 : 1781 : __atomic_fetch_add(&telemetry.noop_resizes,1,__ATOMIC_SEQ_CST);
107 : : #if ROUGH_DEBUG
108 : : printf("telemetry.noop_resizes: %zu\n",telemetry.noop_resizes);
109 : : #endif
110 : 1781 : }
111 : :
112 : 22259 : void telemetry_heap_buffer_releases(void)
113 : : {
114 : 22259 : __atomic_fetch_add(&telemetry.heap_buffer_releases,1,__ATOMIC_SEQ_CST);
115 : : #if ROUGH_DEBUG
116 : : printf("telemetry.heap_buffer_releases: %zu\n",telemetry.heap_buffer_releases);
117 : : #endif
118 : 22259 : }
119 : :
120 : 22263 : void telemetry_total_heap_reserved_bytes_released(const size_t amount_of_bytes)
121 : : {
122 : 22263 : __atomic_fetch_add(&telemetry.total_heap_reserved_bytes_released,amount_of_bytes,__ATOMIC_SEQ_CST);
123 : : #if ROUGH_DEBUG
124 : : printf("telemetry.total_heap_reserved_bytes_released: %zu\n",telemetry.total_heap_reserved_bytes_released);
125 : : #endif
126 : 22263 : }
127 : :
128 : 6 : void telemetry_release_unused_shrinks(void)
129 : : {
130 : 6 : __atomic_fetch_add(&telemetry.release_unused_shrinks,1,__ATOMIC_SEQ_CST);
131 : 6 : }
132 : :
133 : 6 : void telemetry_total_release_unused_heap_reserved_bytes_released(const size_t amount_of_bytes)
134 : : {
135 [ - + ]: 6 : if(amount_of_bytes == 0)
136 : : {
137 : 0 : return;
138 : : }
139 : :
140 : 6 : __atomic_fetch_add(&telemetry.total_release_unused_heap_reserved_bytes_released,amount_of_bytes,__ATOMIC_SEQ_CST);
141 : : }
142 : :
143 : 22305 : void telemetry_heap_reserved_bytes_acquired(const size_t amount_of_bytes)
144 : : {
145 : 22305 : const size_t updated_current_bytes = __atomic_add_fetch(
146 : : &telemetry.current_heap_reserved_bytes,
147 : : amount_of_bytes,
148 : : __ATOMIC_SEQ_CST);
149 : :
150 : 22305 : __atomic_fetch_add(&telemetry.total_heap_reserved_bytes_acquired,amount_of_bytes,__ATOMIC_SEQ_CST);
151 : 22305 : telemetry_peak_heap_reserved_bytes_update(updated_current_bytes);
152 : :
153 : : #if ROUGH_DEBUG
154 : : printf("+%zu\n",amount_of_bytes);
155 : : #endif
156 : 22305 : }
157 : :
158 : 67427 : void telemetry_payload_bytes_added(const size_t amount_of_bytes)
159 : : {
160 : 67427 : __atomic_fetch_add(&telemetry.total_payload_bytes_added,amount_of_bytes,__ATOMIC_SEQ_CST);
161 : 67427 : __atomic_add_fetch(&telemetry.current_payload_bytes,amount_of_bytes,__ATOMIC_SEQ_CST);
162 : :
163 : : #if ROUGH_DEBUG
164 : : printf("+%zu\n",amount_of_bytes);
165 : : #endif
166 : 67427 : }
167 : :
168 : 22263 : void telemetry_current_heap_reserved_bytes_released(const size_t amount_of_bytes)
169 : : {
170 : 22263 : __atomic_sub_fetch(&telemetry.current_heap_reserved_bytes,amount_of_bytes,__ATOMIC_SEQ_CST);
171 : : #if ROUGH_DEBUG
172 : : printf("-%zu\n",amount_of_bytes);
173 : : #endif
174 : 22263 : }
175 : :
176 : 27686 : void telemetry_current_payload_bytes_removed(const size_t amount_of_bytes)
177 : : {
178 : 27686 : __atomic_sub_fetch(&telemetry.current_payload_bytes,amount_of_bytes,__ATOMIC_SEQ_CST);
179 : : #if ROUGH_DEBUG
180 : : printf("-%zu\n",amount_of_bytes);
181 : : #endif
182 : 27686 : }
183 : :
184 : 1 : void telemetry_heap_allocation_failures(void)
185 : : {
186 : 1 : __atomic_fetch_add(&telemetry.heap_allocation_failures,1,__ATOMIC_SEQ_CST);
187 : 1 : }
188 : :
189 : 1 : void telemetry_expected_heap_allocation_failures(void)
190 : : {
191 : 1 : __atomic_fetch_add(&telemetry.expected_heap_allocation_failures,1,__ATOMIC_SEQ_CST);
192 : 1 : }
193 : :
194 : 1 : void telemetry_heap_reallocation_failures(void)
195 : : {
196 : 1 : __atomic_fetch_add(&telemetry.heap_reallocation_failures,1,__ATOMIC_SEQ_CST);
197 : 1 : }
198 : :
199 : 1 : void telemetry_expected_heap_reallocation_failures(void)
200 : : {
201 : 1 : __atomic_fetch_add(&telemetry.expected_heap_reallocation_failures,1,__ATOMIC_SEQ_CST);
202 : 1 : }
203 : :
204 : 27726 : void telemetry_block_overhead_bytes_added(const size_t amount_of_bytes)
205 : : {
206 [ - + ]: 27726 : if(amount_of_bytes == 0)
207 : : {
208 : 0 : return;
209 : : }
210 : :
211 : 27726 : const size_t updated_current_overhead = __atomic_add_fetch(
212 : : &telemetry.current_block_overhead_bytes,
213 : : amount_of_bytes,
214 : : __ATOMIC_SEQ_CST);
215 : :
216 : 27726 : __atomic_fetch_add(&telemetry.total_block_overhead_bytes_added,amount_of_bytes,__ATOMIC_SEQ_CST);
217 : 27726 : telemetry_peak_block_overhead_bytes_update(updated_current_overhead);
218 : : }
219 : :
220 : 67387 : void telemetry_current_block_overhead_bytes_removed(const size_t amount_of_bytes)
221 : : {
222 [ - + ]: 67387 : if(amount_of_bytes == 0)
223 : : {
224 : 0 : return;
225 : : }
226 : :
227 : 67387 : __atomic_sub_fetch(&telemetry.current_block_overhead_bytes,amount_of_bytes,__ATOMIC_SEQ_CST);
228 : : }
229 : :
230 : 1781 : void telemetry_consecutive_noop_resizes_advanced(void)
231 : : {
232 : 1781 : const size_t updated_consecutive_noops = __atomic_add_fetch(
233 : : &telemetry.current_consecutive_noop_resizes,
234 : : 1,
235 : : __ATOMIC_SEQ_CST);
236 : :
237 : 1781 : size_t observed_peak = __atomic_load_n(&telemetry.peak_consecutive_noop_resizes,__ATOMIC_SEQ_CST);
238 : :
239 [ + + ]: 1781 : while(updated_consecutive_noops > observed_peak)
240 : : {
241 [ + - ]: 371 : if(__atomic_compare_exchange_n(
242 : : &telemetry.peak_consecutive_noop_resizes,
243 : : &observed_peak,
244 : : updated_consecutive_noops,
245 : : false,
246 : : __ATOMIC_SEQ_CST,
247 : : __ATOMIC_SEQ_CST))
248 : : {
249 : 371 : break;
250 : : }
251 : : }
252 : 1781 : }
253 : :
254 : 72863 : void telemetry_current_consecutive_noop_resizes_reset(void)
255 : : {
256 : 72863 : __atomic_store_n(&telemetry.current_consecutive_noop_resizes,0,__ATOMIC_SEQ_CST);
257 : 72863 : }
258 : :
259 : 38 : void telemetry_data_to_string_conversions(void)
260 : : {
261 : 38 : __atomic_fetch_add(&telemetry.data_to_string_conversions,1,__ATOMIC_SEQ_CST);
262 : 38 : }
263 : :
264 : 4 : void telemetry_string_to_data_conversions(void)
265 : : {
266 : 4 : __atomic_fetch_add(&telemetry.string_to_data_conversions,1,__ATOMIC_SEQ_CST);
267 : 4 : }
268 : :
269 : 23526 : void telemetry_finalize_string_terminator_already_present(void)
270 : : {
271 : 23526 : __atomic_fetch_add(&telemetry.finalize_string_terminator_already_present,1,__ATOMIC_SEQ_CST);
272 : 23526 : }
273 : :
274 : 2 : void telemetry_finalize_string_terminator_written_when_missing(void)
275 : : {
276 : 2 : __atomic_fetch_add(&telemetry.finalize_string_terminator_written_when_missing,1,__ATOMIC_SEQ_CST);
277 : 2 : }
278 : :
279 : 70458 : void telemetry_string_terminator_writes(void)
280 : : {
281 : 70458 : __atomic_fetch_add(&telemetry.string_terminator_writes,1,__ATOMIC_SEQ_CST);
282 : 70458 : }
283 : :
284 : 22277 : void telemetry_active_descriptors_acquired(void)
285 : : {
286 : 22277 : const size_t updated_active = __atomic_add_fetch(
287 : : &telemetry.current_active_descriptors,
288 : : 1,
289 : : __ATOMIC_SEQ_CST);
290 : :
291 : 22277 : telemetry_peak_active_descriptors_update(updated_active);
292 : 22277 : }
293 : :
294 : 22259 : void telemetry_active_descriptors_released(void)
295 : : {
296 : 22259 : __atomic_sub_fetch(&telemetry.current_active_descriptors,1,__ATOMIC_SEQ_CST);
297 : 22259 : }
298 : :
299 : 5 : void telemetry_arithmetic_guard_failures(void)
300 : : {
301 : 5 : __atomic_fetch_add(&telemetry.arithmetic_guard_failures,1,__ATOMIC_SEQ_CST);
302 : 5 : }
303 : :
304 : 5 : void telemetry_expected_arithmetic_guard_failures(void)
305 : : {
306 : 5 : __atomic_fetch_add(&telemetry.expected_arithmetic_guard_failures,1,__ATOMIC_SEQ_CST);
307 : 5 : }
|