xs/chunk.xs

filter: Statementstmt 95.0% 174 / 183 Branchbran 70.5% 120 / 170 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.2% 294 / 353 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk_observe/po_target.h ↑ Summary xs/wal.xs »
1 MODULE = Punk::Observe PACKAGE = Punk::Observe::Cache PREFIX = poc_
2  
3 # The bucket width a query asks for, or undef when it must be run whole.
4 SV *
5 poc_bucket_ns(SV *q)
6 CODE:
7 {
8 po_query pq;
9 17 STRLEN ql = 0;
10 34 ▶ const char *qp = SvOK(q) ? SvPV(q, ql) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *qp = SvOK(q) ? SvPV(q, ql) : ""; 17 0 17
11 17 po_u64 b = 0;
12 17 ▶ if (ql && po_parse(&pq, qp, (size_t)ql)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ql && po_parse(&pq, qp, (size_t)ql)) { 17 0 17
if (ql && po_parse(&pq, qp, (size_t)ql)) { 16 1 17
13 16 b = po_chunk_bucket_ns(&pq);
14 16 po_query_free(&pq);
15 }
16 17 ▶ RETVAL = b ? po_u64_to_sv(b) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = b ? po_u64_to_sv(b) : newSV(0); 6 11 17
17 }
18 OUTPUT:
19 RETVAL
20  
21 SV *
22 poc_chunk_ns(SV *b)
23 CODE:
24 {
25 9 po_u64 x = 0;
26 9 (void)po_sv_to_u64(aTHX_ b, &x);
27 9 RETVAL = po_u64_to_sv(po_chunk_width(x));
28 }
29 OUTPUT:
30 RETVAL
31  
32 # query($store, $q, from => ..., to => ..., cache => ..., ...)
33 #
34 # The same contract `$store->query` has, with the settled part of the window
35 # served from the cache. Falls back to one plain query whenever splitting
36 # would not be sound - no cache, no bucket, a whole-window stage, a window
37 # with no settled part, or a key too long to store - so a caller never has to
38 # ask which it is getting.
39 SV *
40 poc_query(SV *store, SV *q, ...)
41 CODE:
42 {
43 po_query pq;
44 27 STRLEN ql = 0;
45 54 ▶ const char *qp = SvOK(q) ? SvPV(q, ql) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *qp = SvOK(q) ? SvPV(q, ql) : ""; 27 0 27
46 27 SV *cache = NULL;
47 27 po_u64 from = 0, to = 0, now = 0, lag = PO_CHUNK_LAG_NS;
48 27 int have_from = 0, have_to = 0, have_now = 0;
49 27 IV ttl = 3600, ai;
50 27 po_u64 b = 0, width, settled, stable_end, first, s;
51 po_cres acc;
52 27 int chunks = 0, parsed = 0;
53 27 SV *tenant = NULL;
54 27 SV **extra = NULL;
55 27 int nextra = 0;
56  
57 /* The caller's own options, kept aside to travel with every chunk.
58 * Matched on the key alone rather than on the key having a usable
59 * value, or `from => undef` would be forwarded as an option and
60 * quietly overrule the window this file is splitting. */
61 27 Newx(extra, items > 2 ? items : 2, SV *);
62 144 ▶ for (ai = 2; ai + 1 < items; ai += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 2; ai + 1 < items; ai += 2) { 117 27 144
63 117 const char *k = SvPV_nolen(ST(ai));
64 117 SV *v = ST(ai + 1);
65 117 ▶ if (!poc_consumed(k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!poc_consumed(k)) { 16 101 117
66 16 extra[nextra++] = ST(ai);
67 16 extra[nextra++] = v;
68 }
69 101 ▶ else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from); 27 74 101
else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from); 26 1 27
70 75 ▶ else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to); 27 48 75
else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to); 27 0 27
71 48 ▶ else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now); 21 27 48
else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now); 21 0 21
72 27 ▶ else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag); 0 27 27
else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag); 0 0 0
73 27 ▶ else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v); 0 27 27
else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v); 0 0 0
74 27 ▶ else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL;
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL; 26 1 27
else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL; 26 0 26
75 1 ▶ else if (strEQ(k, "tenant") && SvOK(v)) tenant = v;
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "tenant") && SvOK(v)) tenant = v; 0 1 1
else if (strEQ(k, "tenant") && SvOK(v)) tenant = v; 0 0 0
76 }
77  
78 27 ▶ if (ql && po_parse(&pq, qp, (size_t)ql)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ql && po_parse(&pq, qp, (size_t)ql)) { 27 0 27
if (ql && po_parse(&pq, qp, (size_t)ql)) { 27 0 27
79 27 parsed = 1;
80 27 b = po_chunk_bucket_ns(&pq);
81 27 po_query_free(&pq);
82 }
83 (void)parsed;
84  
85 27 ▶ if (!cache || !have_from || !have_to || !b) {
Branch: 4 branches
BranchTrueFalseTotal
if (!cache || !have_from || !have_to || !b) { 26 1 27
if (!cache || !have_from || !have_to || !b) { 25 1 26
if (!cache || !have_from || !have_to || !b) { 25 0 25
if (!cache || !have_from || !have_to || !b) { 4 21 25
86 6 RETVAL = poc_plain(aTHX_ store, q, from, to, extra, nextra);
87 6 goto done;
88 }
89  
90 21 width = po_chunk_width(b);
91 21 ▶ if (!have_now) now = po_now_ns();
Branch: 1 branch
BranchTrueFalseTotal
if (!have_now) now = po_now_ns(); 2 19 21
92 21 settled = po_ns_sub(now, lag);
93 21 ▶ if (settled > to) settled = to;
Branch: 1 branch
BranchTrueFalseTotal
if (settled > to) settled = to; 18 3 21
94 21 stable_end = po_chunk_floor(settled, width);
95 21 first = po_chunk_floor(from, width);
96  
97 /* Nothing has settled inside the window: one plain query is both the
98 * correct answer and the cheaper one. */
99 21 ▶ if (stable_end <= first) {
Branch: 1 branch
BranchTrueFalseTotal
if (stable_end <= first) { 0 21 21
100 0 RETVAL = poc_plain(aTHX_ store, q, from, to, extra, nextra);
101 0 goto done;
102 }
103  
104 21 po_cres_init(&acc);
105 21 acc.bucket_ns = b;
106  
107 134 ▶ for (s = first; s < stable_end; s += width) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = first; s < stable_end; s += width) { 113 21 134
108 113 po_u64 end = s + width;
109 113 SV *key = poc_key(aTHX_ store, q, s, width, tenant);
110 113 SV *blob = NULL;
111 113 int got = 0;
112  
113 113 ▶ if (!key) { /* too long to key on: run it whole */
Branch: 1 branch
BranchTrueFalseTotal
if (!key) { /* too long to key on: run it whole */ 0 113 113
114 0 po_cres_free(&acc);
115 0 RETVAL = poc_plain(aTHX_ store, q, from, to, extra, nextra);
116 0 goto done;
117 }
118  
119 113 blob = poc_cache_get(aTHX_ cache, key);
120 113 ▶ if (blob) {
Branch: 1 branch
BranchTrueFalseTotal
if (blob) { 33 80 113
121 33 STRLEN bl = 0;
122 33 const unsigned char *bp = (const unsigned char *)SvPV(blob, bl);
123 33 got = po_chunk_decode(&acc, bp, (size_t)bl);
124 33 SvREFCNT_dec(blob);
125 /* Present and unreadable. To `compute` that is a hit, so the
126 * entry has to go or it stands in the way of its own
127 * replacement for the whole of its life. */
128 33 ▶ if (!got) poc_cache_del(aTHX_ cache, key);
Branch: 1 branch
BranchTrueFalseTotal
if (!got) poc_cache_del(aTHX_ cache, key); 1 32 33
129 }
130  
131 113 ▶ if (!got) {
Branch: 1 branch
BranchTrueFalseTotal
if (!got) { 81 32 113
132 /* A MISS, A BAD BLOB AND A CACHE THAT THREW ARE ONE CASE:
133 * compute the chunk, once across the pool where the cache
134 * offers that. A cache is an optimisation, so every way it
135 * can fail has to come out as a slower answer rather than a
136 * broken panel. */
137 81 SV *filled = poc_fill(aTHX_ cache, key, ttl, store, q,
138 s, po_ns_sub(end, 1), b, extra, nextra);
139 81 ▶ if (filled) {
Branch: 1 branch
BranchTrueFalseTotal
if (filled) { 63 18 81
140 63 STRLEN fl = 0;
141 const unsigned char *fp =
142 63 (const unsigned char *)SvPV(filled, fl);
143 63 got = po_chunk_decode(&acc, fp, (size_t)fl);
144 63 SvREFCNT_dec(filled);
145 }
146 }
147  
148 113 ▶ if (!got) {
Branch: 1 branch
BranchTrueFalseTotal
if (!got) { 18 95 113
149 /* Nothing worth storing came back - the scan died, or it
150 * truncated and `_blob` refused to hand a short answer to the
151 * cache. Either way this call still owes an answer, so the
152 * chunk is computed plainly and kept out of the cache. */
153 18 SV *r = poc_plain(aTHX_ store, q, s, po_ns_sub(end, 1),
154 extra, nextra);
155 18 (void)poc_ingest(aTHX_ &acc, r);
156 18 ▶ if (r) SvREFCNT_dec(r);
Branch: 1 branch
BranchTrueFalseTotal
if (r) SvREFCNT_dec(r); 18 0 18
157 }
158 113 SvREFCNT_dec(key);
159 113 chunks++;
160 }
161  
162 { /* The live tail, always computed: it is the part still moving. */
163 21 SV *r = poc_plain(aTHX_ store, q, stable_end, to, extra, nextra);
164 21 (void)poc_ingest(aTHX_ &acc, r);
165 21 ▶ if (r) SvREFCNT_dec(r);
Branch: 1 branch
BranchTrueFalseTotal
if (r) SvREFCNT_dec(r); 21 0 21
166 }
167  
168 21 po_cres_sort(&acc);
169 21 RETVAL = poc_emit(aTHX_ &acc, po_chunk_floor(from, b), chunks);
170 21 po_cres_free(&acc);
171  
172 27 done:
173 27 Safefree(extra);
174 }
175 OUTPUT:
176 RETVAL
177  
178 # warm($store, $q, from => ..., to => ..., cache => ..., ...)
179 #
180 # THE SETTLED CHUNKS, COMPUTED WHERE NOBODY IS WAITING. `query` fills the
181 # cache as a side effect of answering, which means the first person to open a
182 # dashboard after a restart pays for the whole window. This is the same walk
183 # with the answer thrown away: no live tail, no merge, nothing built that a
184 # chart would read - only the entries, so that the request that follows finds
185 # them already there.
186 #
187 # NEWEST FIRST, because that is the end of the range people look at, and a pass
188 # that runs out of budget should have spent it on the hours somebody is about
189 # to ask for.
190 #
191 # A BUDGET AND A DEADLINE, BOTH. A pass that can run for ever is a pass that
192 # can hold a queue worker for ever, and the work here is unbounded by nature -
193 # one chunk of a busy store is a real scan. Neither can interrupt a scan
194 # already started, so both are checked before one begins.
195 SV *
196 poc_warm(SV *store, SV *q, ...)
197 CODE:
198 {
199 po_query pq;
200 17 STRLEN ql = 0;
201 34 ▶ const char *qp = SvOK(q) ? SvPV(q, ql) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *qp = SvOK(q) ? SvPV(q, ql) : ""; 17 0 17
202 17 SV *cache = NULL, *tenant = NULL;
203 17 po_u64 from = 0, to = 0, now = 0, lag = PO_CHUNK_LAG_NS, refresh = 0;
204 17 int have_from = 0, have_to = 0, have_now = 0;
205 17 IV ttl = 3600, ai, budget = 0;
206 17 NV deadline = 0;
207 17 po_u64 b = 0, width = 0, settled, stable_end, first, s, refresh_edge;
208 17 po_u64 t0 = po_tick_ns(), limit_ns = 0;
209 17 SV **extra = NULL;
210 17 int nextra = 0;
211 17 IV n_chunks = 0, n_computed = 0, n_hits = 0, n_failed = 0;
212 17 IV n_unstorable = 0;
213 17 const char *stopped = "";
214 17 HV *out = newHV();
215  
216 17 Newx(extra, items > 2 ? items : 2, SV *);
217 112 ▶ for (ai = 2; ai + 1 < items; ai += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 2; ai + 1 < items; ai += 2) { 95 17 112
218 95 const char *k = SvPV_nolen(ST(ai));
219 95 SV *v = ST(ai + 1);
220 95 ▶ if (!poc_consumed(k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!poc_consumed(k)) { 0 95 95
221 0 extra[nextra++] = ST(ai);
222 0 extra[nextra++] = v;
223 }
224 95 ▶ else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from); 17 78 95
else if (strEQ(k, "from") && SvOK(v)) have_from = po_sv_to_u64(aTHX_ v, &from); 17 0 17
225 78 ▶ else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to); 17 61 78
else if (strEQ(k, "to") && SvOK(v)) have_to = po_sv_to_u64(aTHX_ v, &to); 17 0 17
226 61 ▶ else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now); 18 43 61
else if (strEQ(k, "now") && SvOK(v)) have_now = po_sv_to_u64(aTHX_ v, &now); 18 0 18
227 43 ▶ else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag); 0 43 43
else if (strEQ(k, "lag_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &lag); 0 0 0
228 43 ▶ else if (strEQ(k, "refresh_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &refresh);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "refresh_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &refresh); 6 37 43
else if (strEQ(k, "refresh_ns") && SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &refresh); 6 0 6
229 37 ▶ else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v); 10 27 37
else if (strEQ(k, "ttl") && SvOK(v)) ttl = SvIV(v); 10 0 10
230 27 ▶ else if (strEQ(k, "budget") && SvOK(v)) budget = SvIV(v);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "budget") && SvOK(v)) budget = SvIV(v); 5 22 27
else if (strEQ(k, "budget") && SvOK(v)) budget = SvIV(v); 5 0 5
231 22 ▶ else if (strEQ(k, "deadline") && SvOK(v)) deadline = SvNV(v);
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "deadline") && SvOK(v)) deadline = SvNV(v); 6 16 22
else if (strEQ(k, "deadline") && SvOK(v)) deadline = SvNV(v); 6 0 6
232 16 ▶ else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL;
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL; 16 0 16
else if (strEQ(k, "cache")) cache = SvTRUE(v) ? v : NULL; 16 0 16
233 0 ▶ else if (strEQ(k, "tenant") && SvOK(v)) tenant = v;
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(k, "tenant") && SvOK(v)) tenant = v; 0 0 0
else if (strEQ(k, "tenant") && SvOK(v)) tenant = v; 0 0 0
234 }
235  
236 17 ▶ if (ql && po_parse(&pq, qp, (size_t)ql)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ql && po_parse(&pq, qp, (size_t)ql)) { 17 0 17
if (ql && po_parse(&pq, qp, (size_t)ql)) { 17 0 17
237 17 b = po_chunk_bucket_ns(&pq);
238 17 po_query_free(&pq);
239 }
240  
241 /* THE REFUSALS ARE NAMED. A warmer walks queries it was handed rather
242 * than ones it chose, so "nothing was warmed" has to say which of the
243 * several harmless reasons it was. */
244 17 ▶ if (!cache) { stopped = "no cache"; goto emit; }
Branch: 1 branch
BranchTrueFalseTotal
if (!cache) { stopped = "no cache"; goto emit; } 1 16 17
245 16 ▶ if (!have_from || !have_to) { stopped = "no window"; goto emit; }
Branch: 2 branches
BranchTrueFalseTotal
if (!have_from || !have_to) { stopped = "no window"; goto emit; } 16 0 16
if (!have_from || !have_to) { stopped = "no window"; goto emit; } 0 16 16
246 16 ▶ if (!b) { stopped = "unbucketed"; goto emit; }
Branch: 1 branch
BranchTrueFalseTotal
if (!b) { stopped = "unbucketed"; goto emit; } 2 14 16
247  
248 14 width = po_chunk_width(b);
249 14 ▶ if (!have_now) now = po_now_ns();
Branch: 1 branch
BranchTrueFalseTotal
if (!have_now) now = po_now_ns(); 0 14 14
250 14 settled = po_ns_sub(now, lag);
251 14 ▶ if (settled > to) settled = to;
Branch: 1 branch
BranchTrueFalseTotal
if (settled > to) settled = to; 0 14 14
252 14 stable_end = po_chunk_floor(settled, width);
253 14 first = po_chunk_floor(from, width);
254 14 refresh_edge = po_ns_sub(settled, refresh);
255 14 ▶ if (deadline > 0) limit_ns = (po_u64)(deadline * 1000000000.0);
Branch: 1 branch
BranchTrueFalseTotal
if (deadline > 0) limit_ns = (po_u64)(deadline * 1000000000.0); 6 8 14
256  
257 14 ▶ if (stable_end <= first) { stopped = "nothing settled"; goto emit; }
Branch: 1 branch
BranchTrueFalseTotal
if (stable_end <= first) { stopped = "nothing settled"; goto emit; } 1 13 14
258  
259 85 ▶ for (s = stable_end; s > first; ) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = stable_end; s > first; ) { 76 9 85
260 po_u64 end;
261 SV *key;
262 int force;
263  
264 76 s -= width;
265 76 end = s + width;
266 /* Telemetry arrives late, so the newest settled chunks are the
267 * ones that can still have gained records since they were last
268 * computed. They are recomputed rather than left; everything
269 * older is filled only where it is missing. */
270 76 ▶ force = refresh && end > refresh_edge;
Branch: 2 branches
BranchTrueFalseTotal
force = refresh && end > refresh_edge; 31 45 76
force = refresh && end > refresh_edge; 9 22 31
271  
272 76 key = poc_key(aTHX_ store, q, s, width, tenant);
273 76 ▶ if (!key) { stopped = "key too long"; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (!key) { stopped = "key too long"; break; } 0 76 76
274 76 n_chunks++;
275  
276 76 ▶ if (!force) {
Branch: 1 branch
BranchTrueFalseTotal
if (!force) { 67 9 76
277 67 SV *blob = poc_cache_get(aTHX_ cache, key);
278 67 ▶ if (blob) {
Branch: 1 branch
BranchTrueFalseTotal
if (blob) { 21 46 67
279 21 STRLEN bl = 0;
280 const unsigned char *bp =
281 21 (const unsigned char *)SvPV(blob, bl);
282 21 int usable = po_chunk_valid(bp, (size_t)bl);
283 21 SvREFCNT_dec(blob);
284 21 ▶ if (usable) {
Branch: 1 branch
BranchTrueFalseTotal
if (usable) { 21 0 21
285 21 SvREFCNT_dec(key);
286 21 n_hits++;
287 21 continue;
288 }
289 }
290 }
291  
292 /* Checked here, before a scan that cannot be interrupted once it
293 * has begun, and BEFORE THE ENTRY IS TOUCHED. Deleting first and
294 * stopping second would leave the chunk colder than this pass
295 * found it, and a warmer that keeps running out of budget on the
296 * same chunk would keep emptying it. A pass that stops says so,
297 * and the next one resumes by walking the same way and finding
298 * what this one left. */
299 55 ▶ if (budget && n_computed >= budget) {
Branch: 2 branches
BranchTrueFalseTotal
if (budget && n_computed >= budget) { 27 28 55
if (budget && n_computed >= budget) { 2 25 27
300 2 SvREFCNT_dec(key);
301 2 stopped = "budget";
302 2 break;
303 }
304 53 ▶ if (limit_ns && po_duration(t0, po_tick_ns()) >= limit_ns) {
Branch: 2 branches
BranchTrueFalseTotal
if (limit_ns && po_duration(t0, po_tick_ns()) >= limit_ns) { 25 28 53
if (limit_ns && po_duration(t0, po_tick_ns()) >= limit_ns) { 2 23 25
305 2 SvREFCNT_dec(key);
306 2 stopped = "deadline";
307 2 break;
308 }
309  
310 /* Whatever is there is either stale by policy or unreadable, and
311 * `compute` runs its code on a miss - so it has to go, or it
312 * stands in the way of its own replacement. */
313 51 poc_cache_del(aTHX_ cache, key);
314  
315 {
316 51 SV *filled = poc_fill(aTHX_ cache, key, ttl, store, q,
317 s, po_ns_sub(end, 1), b, extra, nextra);
318 51 ▶ if (!filled) n_failed++;
Branch: 1 branch
BranchTrueFalseTotal
if (!filled) n_failed++; 0 51 51
319 else {
320 SV *back;
321 51 SvREFCNT_dec(filled);
322 51 n_computed++;
323 /* DID IT LAND. A value past the cache's own budget is
324 * refused rather than stored, and a chunk quietly
325 * recomputed on every pass for ever is worth a number
326 * somebody can see rather than a cost nobody can find. */
327 51 back = poc_cache_get(aTHX_ cache, key);
328 51 ▶ if (back) SvREFCNT_dec(back);
Branch: 1 branch
BranchTrueFalseTotal
if (back) SvREFCNT_dec(back); 51 0 51
329 0 else n_unstorable++;
330 }
331 }
332 51 SvREFCNT_dec(key);
333 }
334  
335 9 emit:
336 17 hv_stores(out, "chunks", newSViv(n_chunks));
337 17 hv_stores(out, "computed", newSViv(n_computed));
338 17 hv_stores(out, "hits", newSViv(n_hits));
339 17 hv_stores(out, "failed", newSViv(n_failed));
340 17 hv_stores(out, "unstorable", newSViv(n_unstorable));
341 17 hv_stores(out, "stopped", newSVpv(stopped, 0));
342 17 hv_stores(out, "bucket_ns", po_u64_to_sv(b));
343 17 hv_stores(out, "chunk_ns", po_u64_to_sv(width));
344 17 Safefree(extra);
345 17 RETVAL = newRV_noinc((SV *)out);
346 }
347 OUTPUT:
348 RETVAL
« include/punk_observe/po_target.h ↑ Summary xs/wal.xs »