xs/view.xs

filter: Statementstmt 91.8% 2147 / 2337 Branchbran 54.2% 1470 / 2710 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 71.6% 3617 / 5047 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/plot.xs ↑ Summary include/punk_observe/po_otlp_in.h »
1 MODULE = Punk::Observe PACKAGE = Punk::Observe::View PREFIX = povw_
2  
3 SV *
4 povw_severity_name(SV *n)
5 CODE:
6 0 ▶ RETVAL = newSVpv(po_severity_name(SvOK(n) ? (int)SvIV(n) : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(po_severity_name(SvOK(n) ? (int)SvIV(n) : 0), 0); 0 0 0
7 OUTPUT:
8 RETVAL
9  
10 SV *
11 povw_span_kind_name(SV *k)
12 CODE:
13 0 ▶ RETVAL = newSVpv(po_span_kind_name(SvOK(k) ? (int)SvIV(k) : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(po_span_kind_name(SvOK(k) ? (int)SvIV(k) : 0), 0); 0 0 0
14 OUTPUT:
15 RETVAL
16  
17 SV *
18 povw_fmt_time(SV *ns)
19 ALIAS:
20 fmt_date = 1
21 CODE:
22 {
23 0 STRLEN l = 0;
24 0 ▶ const char *p = SvOK(ns) ? SvPV(ns, l) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const char *p = SvOK(ns) ? SvPV(ns, l) : NULL; 0 0 0
25 char out[40];
26 0 size_t n = p ? (ix ? po_fmt_date(p, (size_t)l, out)
27 0 ▶ : po_fmt_time(p, (size_t)l, out))
Branch: 1 branch
BranchTrueFalseTotal
: po_fmt_time(p, (size_t)l, out)) 0 0 0
28 0 ▶ : (out[0] = '\0', 0);
Branch: 1 branch
BranchTrueFalseTotal
: (out[0] = '\0', 0); 0 0 0
29 0 RETVAL = newSVpvn(out, n);
30 }
31 OUTPUT:
32 RETVAL
33  
34 SV *
35 povw_fmt_dur(SV *ns)
36 CODE:
37 {
38 0 po_u64 v = 0;
39 char out[32];
40 size_t n;
41 0 ▶ if (SvOK(ns)) (void)po_sv_to_u64(aTHX_ ns, &v);
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(ns)) (void)po_sv_to_u64(aTHX_ ns, &v); 0 0 0
42 0 n = po_fmt_dur(v, out);
43 0 RETVAL = newSVpvn(out, n);
44 }
45 OUTPUT:
46 RETVAL
47  
48 SV *
49 povw_fmt_count(SV *n)
50 CODE:
51 {
52 0 STRLEN l = 0;
53 0 ▶ const char *p = SvOK(n) ? SvPV(n, l) : "0";
Branch: 1 branch
BranchTrueFalseTotal
const char *p = SvOK(n) ? SvPV(n, l) : "0"; 0 0 0
54 char out[64];
55 size_t k;
56 0 ▶ if (!SvOK(n)) l = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(n)) l = 1; 0 0 0
57 0 k = po_fmt_count(p, (size_t)l, out, sizeof(out));
58 0 RETVAL = newSVpvn(out, k);
59 }
60 OUTPUT:
61 RETVAL
62  
63 SV *
64 povw_url_esc(SV *s)
65 CODE:
66 {
67 0 STRLEN l = 0;
68 0 ▶ const char *p = SvOK(s) ? SvPV(s, l) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *p = SvOK(s) ? SvPV(s, l) : ""; 0 0 0
69 char *out;
70 size_t n;
71 /* Three bytes per input byte is the worst case, and it is reached by
72 * anything non-ASCII - which a log body routinely is. */
73 0 Newx(out, (size_t)l * 3 + 1, char);
74 0 n = po_url_esc(p, (size_t)l, out, (size_t)l * 3 + 1);
75 0 RETVAL = newSVpvn(out, n);
76 0 Safefree(out);
77 }
78 OUTPUT:
79 RETVAL
80  
81 # A stable identifier for one record.
82 #
83 # THERE IS NO ROW ID IN THE DATA AND THERE SHOULD NOT BE ONE: a record is
84 # whatever the exporter sent. So the id is derived from the record - its
85 # timestamp and a hash of what it says - which makes the detail page a LOOKUP
86 # rather than an offset into a file that compaction may have moved.
87 SV *
88 povw_record_id(SV *rec)
89 CODE:
90 0 RETVAL = povw_record_id_sv(aTHX_ rec);
91 OUTPUT:
92 RETVAL
93  
94 int
95 povw_record_matches(SV *rec, SV *id)
96 CODE:
97 0 RETVAL = povw_record_matches_c(aTHX_ rec, id);
98 OUTPUT:
99 RETVAL
100  
101 NV
102 povw__pct(SV *v, SV *total)
103 CODE:
104 {
105 0 po_u64 a = 0, b = 0;
106 0 ▶ if (SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &a);
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(v)) (void)po_sv_to_u64(aTHX_ v, &a); 0 0 0
107 0 ▶ if (SvOK(total)) (void)po_sv_to_u64(aTHX_ total, &b);
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(total)) (void)po_sv_to_u64(aTHX_ total, &b); 0 0 0
108 0 RETVAL = po_pct(a, b);
109 }
110 OUTPUT:
111 RETVAL
112  
113 SV *
114 povw_fmt_bytes(SV *n)
115 CODE:
116 {
117 0 po_u64 v = 0;
118 char out[48];
119 size_t k;
120 0 ▶ if (SvOK(n)) (void)po_sv_to_u64(aTHX_ n, &v);
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n)) (void)po_sv_to_u64(aTHX_ n, &v); 0 0 0
121 0 k = po_fmt_bytes(v, out);
122 0 RETVAL = newSVpvn(out, k);
123 }
124 OUTPUT:
125 RETVAL
126  
127 # An SVG path from two coordinate arrays.
128 #
129 # The formatting is po_svg.h's, which is hand-rolled for the reason stated
130 # there: `%f` in a Perl-flavoured formatter reads an NV, and a path attribute
131 # containing `1e-05` is not a path - the chart silently does not draw, on one
132 # platform, with no error.
133 SV *
134 povw__path(SV *xs_sv, SV *ys_sv)
135 CODE:
136 {
137 AV *ax, *ay;
138 SSize_t i, n;
139 double *xb, *yb;
140  
141 0 ▶ if (!SvROK(xs_sv) || !SvROK(ys_sv)) croak("arrayrefs required");
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(xs_sv) || !SvROK(ys_sv)) croak("arrayrefs required"); 0 0 0
if (!SvROK(xs_sv) || !SvROK(ys_sv)) croak("arrayrefs required"); 0 0 0
142 0 ax = (AV *)SvRV(xs_sv);
143 0 ay = (AV *)SvRV(ys_sv);
144 0 n = av_len(ax) + 1;
145 0 ▶ Newx(xb, n ? n : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newx(xb, n ? n : 1, double); 0 0 0
Newx(xb, n ? n : 1, double); 0 0 0
Newx(xb, n ? n : 1, double); 0 0 0
146 0 ▶ Newx(yb, n ? n : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newx(yb, n ? n : 1, double); 0 0 0
Newx(yb, n ? n : 1, double); 0 0 0
Newx(yb, n ? n : 1, double); 0 0 0
147 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
148 0 SV **a = av_fetch(ax, i, 0);
149 0 SV **b = av_fetch(ay, i, 0);
150 0 ▶ xb[i] = a ? (double)SvNV(*a) : 0;
Branch: 1 branch
BranchTrueFalseTotal
xb[i] = a ? (double)SvNV(*a) : 0; 0 0 0
151 0 ▶ yb[i] = b ? (double)SvNV(*b) : 0;
Branch: 1 branch
BranchTrueFalseTotal
yb[i] = b ? (double)SvNV(*b) : 0; 0 0 0
152 }
153 0 RETVAL = povw_path_sv(aTHX_ xb, yb, (size_t)n);
154 0 Safefree(xb); Safefree(yb);
155 }
156 OUTPUT:
157 RETVAL
158  
159 NV
160 povw__max(NV a, NV b)
161 ALIAS:
162 _maxf = 1
163 CODE:
164 PERL_UNUSED_VAR(ix);
165 0 ▶ RETVAL = a > b ? a : b;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = a > b ? a : b; 0 0 0
RETVAL = a > b ? a : b; 0 0 0
166 OUTPUT:
167 RETVAL
168  
169 # The x of a point as a fraction of the window, and the y of a value flipped
170 # for SVG. Both take the instants as they are, so the subtraction happens in
171 # the type that holds them.
172 NV
173 povw_chart_x(SV *t, SV *t0, SV *t1, NV width)
174 CODE:
175 {
176 0 po_u64 a = 0, b = 0, c = 0;
177 0 (void)po_sv_to_u64(aTHX_ t, &a);
178 0 (void)po_sv_to_u64(aTHX_ t0, &b);
179 0 (void)po_sv_to_u64(aTHX_ t1, &c);
180 0 RETVAL = po_chart_x(a, b, c, (double)width);
181 }
182 OUTPUT:
183 RETVAL
184  
185 NV
186 povw_chart_y(NV v, NV lo, NV hi, NV height)
187 CODE:
188 0 RETVAL = po_chart_y((double)v, (double)lo, (double)hi, (double)height);
189 OUTPUT:
190 RETVAL
191  
192 # A trace identifier out of whatever somebody pasted, or nothing.
193 #
194 # TWO SPELLINGS ARE IN CIRCULATION and a search box has to take both. The UI's
195 # own links carry `<hi>-<lo>` in decimal, because that is what the record
196 # holds; every other tool in the ecosystem - a `traceparent` header, a log
197 # line from another vendor, the OTLP wire - spells the same id as 32 hex
198 # characters. Somebody pasting the second into a box that only understood the
199 # first gets "no traces", which reads as "that trace is gone".
200 #
201 # Returns (hi, lo), or an empty list when the text is not an identifier at
202 # all - which is the signal to treat it as a search term instead.
203 void
204 povw_trace_id(SV *text)
205 PPCODE:
206 {
207 4 po_u64 hi = 0, lo = 0;
208 4 ▶ if (!povw_trace_id_c(aTHX_ text, &hi, &lo)) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!povw_trace_id_c(aTHX_ text, &hi, &lo)) XSRETURN_EMPTY; 2 2 4
209 2 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 2 2
210 2 mPUSHs(po_u64_to_sv(hi));
211 2 mPUSHs(po_u64_to_sv(lo));
212 2 XSRETURN(2);
213 }
214  
215 # The time range a page reads, most specific source first: an explicit
216 # from/to (what the brush writes into the URL when a chart is dragged), then
217 # a named range, then the default.
218 void
219 povw_window(SV *req, ...)
220 PPCODE:
221 {
222 149 HV *h = NULL;
223 SV **f;
224 149 const char *dflt = "1h";
225 149 STRLEN dlen = 2;
226 const po_range *r;
227 IV ai;
228  
229 149 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) h = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) h = (HV *)SvRV(req); 149 0 149
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) h = (HV *)SvRV(req); 149 0 149
230 149 ▶ for (ai = 1; ai + 1 < items; ai += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 1; ai + 1 < items; ai += 2) 0 149 149
231 0 ▶ if (strEQ(SvPV_nolen(ST(ai)), "default") && SvOK(ST(ai + 1)))
Branch: 2 branches
BranchTrueFalseTotal
if (strEQ(SvPV_nolen(ST(ai)), "default") && SvOK(ST(ai + 1))) 0 0 0
if (strEQ(SvPV_nolen(ST(ai)), "default") && SvOK(ST(ai + 1))) 0 0 0
232 0 dflt = SvPV(ST(ai + 1), dlen);
233  
234 149 ▶ if (h) {
Branch: 1 branch
BranchTrueFalseTotal
if (h) { 149 0 149
235 149 SV **fs = hv_fetchs(h, "from", 0);
236 149 SV **ts = hv_fetchs(h, "to", 0);
237 149 ▶ if (fs && ts && SvOK(*fs) && SvOK(*ts)) {
Branch: 4 branches
BranchTrueFalseTotal
if (fs && ts && SvOK(*fs) && SvOK(*ts)) { 62 87 149
if (fs && ts && SvOK(*fs) && SvOK(*ts)) { 62 0 62
if (fs && ts && SvOK(*fs) && SvOK(*ts)) { 62 0 62
if (fs && ts && SvOK(*fs) && SvOK(*ts)) { 62 0 62
238 STRLEN fl, tl;
239 62 const char *fp = SvPV(*fs, fl);
240 62 ▶ const char *tp = SvPV(*ts, tl);
Branch: 1 branch
BranchTrueFalseTotal
const char *tp = SvPV(*ts, tl); 2 60 62
241 62 ▶ if (po_ns_plausible(fp, (size_t)fl)
Branch: 1 branch
BranchTrueFalseTotal
if (po_ns_plausible(fp, (size_t)fl) 62 0 62
242 62 ▶ && po_ns_plausible(tp, (size_t)tl)) {
Branch: 1 branch
BranchTrueFalseTotal
&& po_ns_plausible(tp, (size_t)tl)) { 62 0 62
243 62 ▶ mXPUSHs(newSVpvn(fp, fl));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvn(fp, fl)); 0 62 62
244 62 ▶ mXPUSHs(newSVpvn(tp, tl));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvn(tp, tl)); 0 62 62
245 62 ▶ mXPUSHs(newSVpvs("custom"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("custom")); 0 62 62
246 62 XSRETURN(3);
247 }
248 }
249 }
250  
251 87 r = NULL;
252 87 ▶ if (h && (f = hv_fetchs(h, "range", 0)) && SvOK(*f)) {
Branch: 3 branches
BranchTrueFalseTotal
if (h && (f = hv_fetchs(h, "range", 0)) && SvOK(*f)) { 87 0 87
if (h && (f = hv_fetchs(h, "range", 0)) && SvOK(*f)) { 38 49 87
if (h && (f = hv_fetchs(h, "range", 0)) && SvOK(*f)) { 38 0 38
253 STRLEN kl;
254 38 const char *kp = SvPV(*f, kl);
255 38 r = po_range_find(kp, (size_t)kl);
256 }
257 87 ▶ if (!r) r = po_range_find(dflt, (size_t)dlen);
Branch: 1 branch
BranchTrueFalseTotal
if (!r) r = po_range_find(dflt, (size_t)dlen); 50 37 87
258 87 ▶ if (!r) r = po_range_find("1h", 2);
Branch: 1 branch
BranchTrueFalseTotal
if (!r) r = po_range_find("1h", 2); 0 87 87
259  
260 87 ▶ if (!r->secs) {
Branch: 1 branch
BranchTrueFalseTotal
if (!r->secs) { 7 80 87
261 /* `all`: two undefs, and the caller passes them straight through
262 * to the store, where an absent bound means no limit. */
263 7 ▶ mXPUSHs(newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSV(0)); 0 7 7
264 7 ▶ mXPUSHs(newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSV(0)); 0 7 7
265 7 ▶ mXPUSHs(newSVpvs("all"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("all")); 0 7 7
266 7 XSRETURN(3);
267 }
268 {
269 80 po_u64 now = (po_u64)time(NULL);
270 80 ▶ mXPUSHs(po_u64_to_sv((now - r->secs) * 1000000000ULL));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(po_u64_to_sv((now - r->secs) * 1000000000ULL)); 0 80 80
271 80 ▶ mXPUSHs(po_u64_to_sv((now + 1) * 1000000000ULL));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(po_u64_to_sv((now + 1) * 1000000000ULL)); 0 80 80
272 80 ▶ mXPUSHs(newSVpv(r->key, 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpv(r->key, 0)); 0 80 80
273 }
274 }
275  
276 # The duration box, as a number of nanoseconds and the end it bounds.
277 #
278 # Three answers, not two: a duration, nothing at all, and TEXT THAT IS NOT A
279 # DURATION. The third used to be indistinguishable from the second, so a
280 # filter that could not be read was a filter that was not applied and not
281 # mentioned - and an unfiltered table is the one result that looks like an
282 # answer rather than like a mistake.
283 #
284 # Returns (ns, "min"|"max") for a duration, () for an empty box, and (undef)
285 # for text that was meant to be one. The caller says so on the page.
286 void
287 povw_min_duration(SV *text)
288 PPCODE:
289 {
290 67 STRLEN len = 0;
291 133 ▶ const char *p = SvOK(text) ? SvPV(text, len) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const char *p = SvOK(text) ? SvPV(text, len) : NULL; 66 1 67
292 67 po_u64 ns = 0;
293 67 int is_max = 0;
294 67 int r = po_min_duration(p, (size_t)len, &ns, &is_max);
295 67 ▶ if (r == 0) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (r == 0) XSRETURN_EMPTY; 3 64 67
296 64 ▶ if (r < 0) { mXPUSHs(newSV(0)); XSRETURN(1); }
Branch: 2 branches
BranchTrueFalseTotal
if (r < 0) { mXPUSHs(newSV(0)); XSRETURN(1); } 11 53 64
if (r < 0) { mXPUSHs(newSV(0)); XSRETURN(1); } 0 11 11
297 53 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 53 53
298 53 mPUSHs(po_u64_to_sv(ns));
299 53 ▶ mPUSHs(newSVpv(is_max ? "max" : "min", 0));
Branch: 1 branch
BranchTrueFalseTotal
mPUSHs(newSVpv(is_max ? "max" : "min", 0)); 4 49 53
300 53 XSRETURN(2);
301 }
302  
303 # The range control's own variables, so every screen that reads a window can
304 # offer the same way of changing it.
305 void
306 povw_range_vars(SV *req, SV *active)
307 PPCODE:
308 {
309 140 STRLEN al = 0;
310 280 ▶ const char *ap = SvOK(active) ? SvPV(active, al) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *ap = SvOK(active) ? SvPV(active, al) : ""; 140 0 140
311 140 AV *ranges = newAV();
312 int i;
313 140 ▶ int is_all = (al == 3 && memcmp(ap, "all", 3) == 0);
Branch: 2 branches
BranchTrueFalseTotal
int is_all = (al == 3 && memcmp(ap, "all", 3) == 0); 9 131 140
int is_all = (al == 3 && memcmp(ap, "all", 3) == 0); 7 2 9
314  
315 PERL_UNUSED_VAR(req);
316 1120 ▶ for (i = 0; i < PO_NRANGES; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < PO_NRANGES; i++) { 980 140 1120
317 980 HV *e = newHV();
318 980 size_t kl = strlen(PO_RANGES[i].key);
319 980 hv_stores(e, "key", newSVpv(PO_RANGES[i].key, 0));
320 980 hv_stores(e, "label", newSVpv(PO_RANGES[i].label, 0));
321 980 ▶ hv_stores(e, "current",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(e, "current", 249 731 980
hv_stores(e, "current", 80 169 249
322 newSViv(kl == (size_t)al && memcmp(PO_RANGES[i].key, ap, kl) == 0));
323 980 av_push(ranges, newRV_noinc((SV *)e));
324 }
325  
326 140 ▶ mXPUSHs(newSVpvs("range"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("range")); 0 140 140
327 140 ▶ mXPUSHs(newSVpvn(ap, al));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvn(ap, al)); 0 140 140
328 /* The `all` case reads differently in an empty state: there is no
329 * wider range to suggest, so the message must not suggest one. */
330 140 ▶ mXPUSHs(newSVpvs("range_all"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("range_all")); 0 140 140
331 140 ▶ mXPUSHs(newSViv(is_all));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv(is_all)); 0 140 140
332 /* A CUSTOM WINDOW HAS NO KEY, so the form carries the pair instead.
333 * Without this the hidden field says "custom" and the two instants
334 * that gave it meaning are gone by the next submit - which is a
335 * dragged selection on a chart lasting exactly until the next thing
336 * anybody types. */
337 140 ▶ mXPUSHs(newSVpvs("range_custom"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("range_custom")); 0 140 140
338 140 ▶ mXPUSHs(newSViv(al == 6 && memcmp(ap, "custom", 6) == 0));
Branch: 3 branches
BranchTrueFalseTotal
mXPUSHs(newSViv(al == 6 && memcmp(ap, "custom", 6) == 0)); 0 140 140
mXPUSHs(newSViv(al == 6 && memcmp(ap, "custom", 6) == 0)); 60 80 140
mXPUSHs(newSViv(al == 6 && memcmp(ap, "custom", 6) == 0)); 60 0 60
339 140 ▶ mXPUSHs(newSVpvs("ranges"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("ranges")); 0 140 140
340 140 ▶ mXPUSHs(newRV_noinc((SV *)ranges));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_noinc((SV *)ranges)); 0 140 140
341 /* A page that was given a range control needs the calendar's assets.
342 * This is set HERE rather than per screen for the same reason the
343 * button list is built here: the two would be one edit apart, and the
344 * screen that got the flag without the vars, or the vars without the
345 * flag, is the one nobody notices until it is in front of somebody. */
346 140 ▶ mXPUSHs(newSVpvs("wants_range"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("wants_range")); 0 140 140
347 140 ▶ mXPUSHs(newSViv(1));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv(1)); 0 140 140
348 }
349  
350 # Dispatch, and the nav highlight.
351 #
352 # The nav highlights itself from the PAGE NAME rather than from the path,
353 # because a mount can be anywhere and the path is not the page.
354 void
355 povw_page(SV *class, SV *store, SV *name, SV *req)
356 PPCODE:
357 {
358 STRLEN nl;
359 304 ▶ const char *np = SvOK(name) ? SvPV(name, nl) : (nl = 0, "");
Branch: 1 branch
BranchTrueFalseTotal
const char *np = SvOK(name) ? SvPV(name, nl) : (nl = 0, ""); 152 0 152
360 char sub[64];
361 152 SV *vars = NULL;
362 HV *vh;
363 GV *gv;
364  
365 152 ▶ if (nl + 7 >= sizeof(sub)) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (nl + 7 >= sizeof(sub)) XSRETURN_UNDEF; 0 152 152
366 152 memcpy(sub, "_page_", 6);
367 152 memcpy(sub + 6, np, nl);
368 152 sub[6 + nl] = '\0';
369  
370 152 gv = gv_fetchmethod_autoload(gv_stashsv(class, 0), sub, 0);
371 152 ▶ if (!gv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gv) { 0 152 152
372 0 HV *e = newHV();
373 char up[64];
374 0 memcpy(up, np, nl); up[nl] = '\0';
375 0 ▶ if (nl && up[0] >= 'a' && up[0] <= 'z') up[0] = (char)(up[0] - 32);
Branch: 3 branches
BranchTrueFalseTotal
if (nl && up[0] >= 'a' && up[0] <= 'z') up[0] = (char)(up[0] - 32); 0 0 0
if (nl && up[0] >= 'a' && up[0] <= 'z') up[0] = (char)(up[0] - 32); 0 0 0
if (nl && up[0] >= 'a' && up[0] <= 'z') up[0] = (char)(up[0] - 32); 0 0 0
376 0 hv_stores(e, "heading", newSVpvn(up, nl));
377 0 ▶ mXPUSHs(newRV_noinc((SV *)e));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_noinc((SV *)e)); 0 0 0
378 0 XSRETURN(1);
379 }
380  
381 {
382 int n;
383 152 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 152 152
384 152 ▶ XPUSHs(class);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(class); 0 152 152
385 152 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 152 152
386 152 ▶ XPUSHs(SvOK(req) && SvROK(req) ? req
Branch: 3 branches
BranchTrueFalseTotal
XPUSHs(SvOK(req) && SvROK(req) ? req 0 152 152
XPUSHs(SvOK(req) && SvROK(req) ? req 152 0 152
XPUSHs(SvOK(req) && SvROK(req) ? req 0 152 152
387 : sv_2mortal(newRV_noinc((SV *)newHV())));
388 152 PUTBACK;
389 152 n = call_sv((SV *)GvCV(gv), G_SCALAR);
390 152 SPAGAIN;
391 152 ▶ vars = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
vars = n ? SvREFCNT_inc(POPs) : NULL; 152 0 152
392 152 PUTBACK;
393 152 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 152 0 152
394 152 SPAGAIN;
395 }
396  
397 152 ▶ if (!vars || !SvROK(vars) || SvTYPE(SvRV(vars)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!vars || !SvROK(vars) || SvTYPE(SvRV(vars)) != SVt_PVHV) { 152 0 152
if (!vars || !SvROK(vars) || SvTYPE(SvRV(vars)) != SVt_PVHV) { 152 0 152
if (!vars || !SvROK(vars) || SvTYPE(SvRV(vars)) != SVt_PVHV) { 0 152 152
398 0 ▶ if (vars) SvREFCNT_dec(vars);
Branch: 1 branch
BranchTrueFalseTotal
if (vars) SvREFCNT_dec(vars); 0 0 0
399 0 vars = newRV_noinc((SV *)newHV());
400 }
401 152 vh = (HV *)SvRV(vars);
402  
403 {
404 char key[80];
405 152 memcpy(key, "here_", 5);
406 152 memcpy(key + 5, np, nl);
407 152 hv_store(vh, key, (I32)(5 + nl), newSViv(1), 0);
408 }
409 152 ▶ if (nl == 6 && memcmp(np, "status", 6) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (nl == 6 && memcmp(np, "status", 6) == 0) 19 133 152
if (nl == 6 && memcmp(np, "status", 6) == 0) 11 8 19
410 11 hv_stores(vh, "here_home", newSViv(1));
411 152 ▶ if (nl == 5 && memcmp(np, "trace", 5) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (nl == 5 && memcmp(np, "trace", 5) == 0) 40 112 152
if (nl == 5 && memcmp(np, "trace", 5) == 0) 40 0 40
412 40 hv_stores(vh, "here_traces", newSViv(1));
413  
414 152 ▶ mXPUSHs(vars);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(vars); 0 152 152
415 }
416  
417 # ---- the pages ------------------------------------------------------------
418  
419 SV *
420 povw__page_status(SV *class, SV *store, SV *req)
421 CODE:
422 {
423 11 HV *out = newHV();
424 HV *s;
425 11 SV *stats = NULL;
426  
427 PERL_UNUSED_VAR(class);
428 PERL_UNUSED_VAR(req);
429  
430 11 ▶ if (SvOK(store) && SvROK(store)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(store) && SvROK(store)) { 11 0 11
if (SvOK(store) && SvROK(store)) { 11 0 11
431 int n;
432 11 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 11 11
433 11 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 11 11
434 11 PUTBACK;
435 11 n = call_method("stats", G_SCALAR);
436 11 SPAGAIN;
437 11 ▶ stats = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
stats = n ? SvREFCNT_inc(POPs) : NULL; 11 0 11
438 11 PUTBACK;
439 11 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 11 0 11
440 }
441 11 ▶ s = (stats && SvROK(stats) && SvTYPE(SvRV(stats)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
s = (stats && SvROK(stats) && SvTYPE(SvRV(stats)) == SVt_PVHV) 11 0 11
s = (stats && SvROK(stats) && SvTYPE(SvRV(stats)) == SVt_PVHV) 11 0 11
442 22 ▶ ? (HV *)SvRV(stats) : newHV();
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(stats) : newHV(); 11 0 11
443  
444 /* THE RAW ANSWER RIDES ALONG, so the plugin does not ask again.
445 *
446 * _page needs the unformatted bytes for the storage gauge and used to
447 * call $store->stats a second time to get them - the same directory
448 * walk, every sidecar read twice, on every load of this page. The
449 * underscore prefix is the convention for "not a template variable":
450 * the plugin consumes it and deletes it before render. */
451 11 ▶ if (stats)
Branch: 1 branch
BranchTrueFalseTotal
if (stats) 11 0 11
452 11 hv_stores(out, "_stats", SvREFCNT_inc(stats));
453  
454 11 hv_stores(out, "heading", newSVpvs("Overview"));
455 11 hv_stores(out, "title", newSVpvs("Overview"));
456  
457 11 povw_set_iv(aTHX_ out, "orphan_index", s, "orphan_index");
458 11 povw_set_iv(aTHX_ out, "wal_depth", s, "wal_depth");
459 11 povw_set_iv(aTHX_ out, "segments", s, "segments");
460 11 povw_set_iv(aTHX_ out, "compaction_lag", s, "unindexed");
461  
462 11 povw_set_count(aTHX_ out, "ingest_rate", s, "records");
463 11 povw_set_count(aTHX_ out, "logs", s, "logs");
464 11 povw_set_count(aTHX_ out, "spans", s, "spans");
465 11 povw_set_count(aTHX_ out, "metrics", s, "metrics");
466 11 povw_set_count(aTHX_ out, "traces", s, "traces");
467 11 povw_set_count(aTHX_ out, "errors", s, "errors");
468  
469 {
470 11 SV **f = hv_fetchs(s, "bytes", 0);
471 11 po_u64 b = 0;
472 char buf[48];
473 size_t n;
474 11 ▶ if (f && SvOK(*f)) (void)po_sv_to_u64(aTHX_ *f, &b);
Branch: 2 branches
BranchTrueFalseTotal
if (f && SvOK(*f)) (void)po_sv_to_u64(aTHX_ *f, &b); 8 3 11
if (f && SvOK(*f)) (void)po_sv_to_u64(aTHX_ *f, &b); 8 0 8
475 11 n = po_fmt_bytes(b, buf);
476 11 hv_stores(out, "store_bytes", newSVpvn(buf, n));
477 }
478  
479 /* `series` is the COUNT and `services` the list, and they are two
480 * different template variables with names one letter apart. Kept as
481 * they were rather than tidied, because the templates read them. */
482 {
483 11 SV **f = hv_fetchs(s, "services", 0);
484 11 ▶ hv_stores(out, "series", newSViv(f && SvOK(*f) ? SvIV(*f) : 0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(out, "series", newSViv(f && SvOK(*f) ? SvIV(*f) : 0)); 8 3 11
hv_stores(out, "series", newSViv(f && SvOK(*f) ? SvIV(*f) : 0)); 8 0 8
485 }
486 {
487 11 AV *list = newAV();
488 11 SV **f = hv_fetchs(s, "service", 0);
489 11 ▶ if (f && SvROK(*f) && SvTYPE(SvRV(*f)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (f && SvROK(*f) && SvTYPE(SvRV(*f)) == SVt_PVHV) { 8 3 11
if (f && SvROK(*f) && SvTYPE(SvRV(*f)) == SVt_PVHV) { 8 0 8
if (f && SvROK(*f) && SvTYPE(SvRV(*f)) == SVt_PVHV) { 8 0 8
490 8 HV *svc = (HV *)SvRV(*f);
491 8 AV *keys = newAV();
492 po_sortpair *pairs;
493 HE *he;
494 SSize_t i, n;
495  
496 8 hv_iterinit(svc);
497 19 ▶ while ((he = hv_iternext(svc)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(svc))) 11 8 19
498 11 av_push(keys, newSVsv(hv_iterkeysv(he)));
499 8 n = av_len(keys) + 1;
500  
501 /* BUSIEST FIRST, so the eye lands on the traffic rather than
502 * on whatever order the hash happened to be in. */
503 8 ▶ Newx(pairs, n ? n : 1, po_sortpair);
Branch: 3 branches
BranchTrueFalseTotal
Newx(pairs, n ? n : 1, po_sortpair); 8 0 8
Newx(pairs, n ? n : 1, po_sortpair); 0 8 8
Newx(pairs, n ? n : 1, po_sortpair); 8 0 8
504 19 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 11 8 19
505 11 SV **k = av_fetch(keys, i, 0);
506 STRLEN kl;
507 11 const char *kp = SvPV(*k, kl);
508 11 SV **v = hv_fetch(svc, kp, (I32)kl, 0);
509 11 ▶ pairs[i].key = (v && SvOK(*v)) ? (po_u64)SvUV(*v) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pairs[i].key = (v && SvOK(*v)) ? (po_u64)SvUV(*v) : 0; 11 0 11
pairs[i].key = (v && SvOK(*v)) ? (po_u64)SvUV(*v) : 0; 11 0 11
510 11 pairs[i].sv = *k;
511 }
512 8 ▶ if (n > 1) qsort(pairs, (size_t)n, sizeof(po_sortpair),
Branch: 1 branch
BranchTrueFalseTotal
if (n > 1) qsort(pairs, (size_t)n, sizeof(po_sortpair), 3 5 8
513 po_sortpair_desc);
514 19 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 11 8 19
515 11 HV *e = newHV();
516 STRLEN kl;
517 11 const char *kp = SvPV(pairs[i].sv, kl);
518 11 SV **v = hv_fetch(svc, kp, (I32)kl, 0);
519 char buf[64];
520 11 STRLEN vl = 0;
521 22 ▶ const char *vp = (v && SvOK(*v)) ? SvPV(*v, vl) : "0";
Branch: 2 branches
BranchTrueFalseTotal
const char *vp = (v && SvOK(*v)) ? SvPV(*v, vl) : "0"; 11 0 11
const char *vp = (v && SvOK(*v)) ? SvPV(*v, vl) : "0"; 11 0 11
522 size_t cn;
523 11 ▶ if (!v || !SvOK(*v)) vl = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (!v || !SvOK(*v)) vl = 1; 11 0 11
if (!v || !SvOK(*v)) vl = 1; 0 11 11
524 11 cn = po_fmt_count(vp, (size_t)vl, buf, sizeof(buf));
525 11 hv_stores(e, "name", newSVpvn(kp, kl));
526 11 hv_stores(e, "count", newSVpvn(buf, cn));
527 11 av_push(list, newRV_noinc((SV *)e));
528 }
529 8 Safefree(pairs);
530 8 SvREFCNT_dec((SV *)keys);
531 }
532 11 hv_stores(out, "services", newRV_noinc((SV *)list));
533 }
534  
535 11 ▶ if (stats) SvREFCNT_dec(stats);
Branch: 1 branch
BranchTrueFalseTotal
if (stats) SvREFCNT_dec(stats); 11 0 11
536 11 RETVAL = newRV_noinc((SV *)out);
537 }
538 OUTPUT:
539 RETVAL
540  
541 SV *
542 povw__page_logs(SV *class, SV *store, SV *req)
543 CODE:
544 {
545 28 HV *v = newHV();
546 28 SV *from = NULL, *to = NULL, *res = NULL;
547 28 HV *r = NULL;
548 SV **f;
549 28 const char *q = "log";
550 28 STRLEN ql = 3;
551 char *esc;
552  
553 PERL_UNUSED_VAR(class);
554  
555 28 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) { 28 0 28
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) { 28 0 28
556 28 f = hv_fetchs((HV *)SvRV(req), "q", 0);
557 28 ▶ if (f && SvOK(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (f && SvOK(*f)) { 10 18 28
if (f && SvOK(*f)) { 10 0 10
558 STRLEN l;
559 10 const char *p = SvPV(*f, l);
560 size_t i;
561 10 ▶ for (i = 0; i < (size_t)l; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (size_t)l; i++) 10 0 10
562 10 ▶ if (p[i] != ' ' && p[i] != '\t' && p[i] != '\n') { q = p; ql = l; break; }
Branch: 3 branches
BranchTrueFalseTotal
if (p[i] != ' ' && p[i] != '\t' && p[i] != '\n') { q = p; ql = l; break; } 10 0 10
if (p[i] != ' ' && p[i] != '\t' && p[i] != '\n') { q = p; ql = l; break; } 10 0 10
if (p[i] != ' ' && p[i] != '\t' && p[i] != '\n') { q = p; ql = l; break; } 10 0 10
563 }
564 }
565  
566 28 hv_stores(v, "heading", newSVpvs("Logs"));
567 28 hv_stores(v, "title", newSVpvs("Logs"));
568 28 hv_stores(v, "query", newSVpvn(q, ql));
569 28 hv_stores(v, "tail", newSViv(1));
570 28 hv_stores(v, "rows", newRV_noinc((SV *)newAV()));
571 28 Newx(esc, (size_t)ql * 3 + 1, char);
572 {
573 28 size_t en = po_url_esc(q, (size_t)ql, esc, (size_t)ql * 3 + 1);
574 28 hv_stores(v, "query_esc", newSVpvn(esc, en));
575 }
576 28 Safefree(esc);
577  
578 28 povw_window_vars(aTHX_ v, req, &from, &to);
579  
580 /* THE CURSOR IS AN INSTANT, so it is stable while new lines arrive -
581 * an offset is not: five hundred new lines shift every offset by five
582 * hundred, and page two repeats page one. `before` narrows the top of
583 * the window to just under the oldest line of the previous page; the
584 * range, the query and everything else stay exactly as they were, so
585 * a page of results is still a link.
586 *
587 * Exclusive by one nanosecond via nsub, because the boundary line was
588 * already shown. Two lines sharing an instant across a page boundary
589 * would be the one loss; at nanosecond resolution that is accepted
590 * and recorded rather than solved with a composite cursor. */
591 {
592 28 SV **bf = NULL;
593 28 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) 28 0 28
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) 28 0 28
594 28 bf = hv_fetchs((HV *)SvRV(req), "before", 0);
595 28 ▶ if (bf && SvOK(*bf)) {
Branch: 2 branches
BranchTrueFalseTotal
if (bf && SvOK(*bf)) { 3 25 28
if (bf && SvOK(*bf)) { 3 0 3
596 STRLEN bl;
597 3 const char *bp = SvPV(*bf, bl);
598 3 ▶ if (po_ns_plausible(bp, (size_t)bl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (po_ns_plausible(bp, (size_t)bl)) { 3 0 3
599 3 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 3 3
600 3 ▶ XPUSHs(*bf);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*bf); 0 3 3
601 3 ▶ XPUSHs(sv_2mortal(newSVpvs("1")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("1"))); 0 3 3
602 3 PUTBACK;
603 3 ▶ if (call_pv("Punk::Observe::Store::nsub", G_SCALAR) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_pv("Punk::Observe::Store::nsub", G_SCALAR) == 1) { 3 0 3
604 3 SPAGAIN;
605 3 SvREFCNT_dec(to);
606 3 to = SvREFCNT_inc(POPs);
607 3 PUTBACK;
608 }
609 3 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 3 0 3
610 3 SPAGAIN;
611 3 hv_stores(v, "paged", newSViv(1));
612 }
613 }
614 }
615  
616 28 ▶ if (!SvOK(store) || !SvROK(store)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(store) || !SvROK(store)) { 28 0 28
if (!SvOK(store) || !SvROK(store)) { 0 28 28
617 0 SvREFCNT_dec(from); SvREFCNT_dec(to);
618 0 goto done;
619 }
620  
621 {
622 int n;
623 28 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 28 28
624 28 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 28 28
625 28 ▶ XPUSHs(sv_2mortal(newSVpvn(q, ql)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(q, ql))); 0 28 28
626 28 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 28 28
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 28 28
627 28 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 28 28
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 28 28
628 /* A PAGE OF LOG LINES, NOT ALL OF THEM.
629 *
630 * Unbounded, this asked for every line in the window and got
631 * them: a busy hour is six figures of rows, and the screen came
632 * back as forty-four megabytes of HTML that no browser is going
633 * to lay out. The store hands rows over newest first, so a bound
634 * here is the most recent N - which is what a log viewer is for -
635 * and it sets `truncated`, so the page says it is partial rather
636 * than looking complete. */
637 28 ▶ XPUSHs(sv_2mortal(newSVpvs("limit")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("limit"))); 0 28 28
638 28 ▶ XPUSHs(sv_2mortal(newSViv(POVW_LOG_PAGE)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(POVW_LOG_PAGE))); 0 28 28
639 28 PUTBACK;
640 28 n = call_method("query", G_SCALAR);
641 28 SPAGAIN;
642 28 ▶ res = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
res = n ? SvREFCNT_inc(POPs) : NULL; 28 0 28
643 28 PUTBACK;
644 28 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 28 0 28
645 28 SPAGAIN;
646 }
647 28 SvREFCNT_dec(from); SvREFCNT_dec(to);
648  
649 28 ▶ if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 28 0 28
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 28 0 28
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 0 28 28
650 0 ▶ if (res) SvREFCNT_dec(res);
Branch: 1 branch
BranchTrueFalseTotal
if (res) SvREFCNT_dec(res); 0 0 0
651 0 goto done;
652 }
653 28 r = (HV *)SvRV(res);
654  
655 28 f = hv_fetchs(r, "ok", 0);
656 28 ▶ if (!f || !SvTRUE(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!f || !SvTRUE(*f)) { 28 0 28
if (!f || !SvTRUE(*f)) { 1 27 28
657 1 SV **e = hv_fetchs(r, "error", 0);
658 1 SV **st = hv_fetchs(r, "stage", 0);
659 2 ▶ int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse");
Branch: 3 branches
BranchTrueFalseTotal
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 1 0 1
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 1 0 1
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 1 0 1
660 1 ▶ hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 1 0 1
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 1 0 1
661 : newSVpvs("that query could not be run"));
662 /* The hint names the NEXT THING TO TRY. The store's own is the
663 * most specific one there is - a refused join says "narrow the
664 * range, or aggregate before the jump" - and swallowing it for
665 * a generic line threw the guidance away. */
666 {
667 1 SV **ht = hv_fetchs(r, "hint", 0);
668 1 ▶ hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht))
Branch: 4 branches
BranchTrueFalseTotal
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 1 1
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 1 0 1
669 ? newSVsv(*ht)
670 : parse
671 ? newSVpvs("Check the stage after the pipe.")
672 : newSVpvs("Narrow the range or add a filter."));
673 }
674 1 SvREFCNT_dec(res);
675 1 goto done;
676 }
677  
678 {
679 27 SV **shape = hv_fetchs(r, "shape", 0);
680 27 ▶ int is_rows = !shape || !SvOK(*shape)
Branch: 1 branch
BranchTrueFalseTotal
int is_rows = !shape || !SvOK(*shape) 27 0 27
681 81 ▶ || strEQ(SvPV_nolen(*shape), "rows");
Branch: 2 branches
BranchTrueFalseTotal
|| strEQ(SvPV_nolen(*shape), "rows"); 27 0 27
|| strEQ(SvPV_nolen(*shape), "rows"); 22 5 27
682 27 ▶ int is_buckets = shape && SvOK(*shape)
Branch: 1 branch
BranchTrueFalseTotal
int is_buckets = shape && SvOK(*shape) 27 0 27
683 81 ▶ && strEQ(SvPV_nolen(*shape), "buckets");
Branch: 2 branches
BranchTrueFalseTotal
&& strEQ(SvPV_nolen(*shape), "buckets"); 27 0 27
&& strEQ(SvPV_nolen(*shape), "buckets"); 1 26 27
684 27 SV **mv = hv_fetchs(r, "meta", 0);
685  
686 /* `| viz` works here exactly as it does in the explorer - same
687 * function, same refusals - and the bucketed fill comes with it,
688 * so `log | bucket(30s) count` draws instead of heading an empty
689 * panel. */
690 27 povw_apply_viz(aTHX_ v, r, res, q, (size_t)ql,
691 is_rows, is_buckets);
692  
693 /* THE VOLUME CHART AND THE TABLE ANSWER THE SAME QUESTION.
694 *
695 * It is the reader's own query with a bucket stage added, so a
696 * filter typed into the box narrows both. A chart of everything
697 * above a table of errors is two answers on one screen, and
698 * nothing on it says which one is being looked at.
699 *
700 * Only where they asked for rows: appending an aggregate to a
701 * query that already has one is a different question, and usually
702 * a parse error. */
703 27 ▶ if (is_rows)
Branch: 1 branch
BranchTrueFalseTotal
if (is_rows) 22 5 27
704 22 povw_add_figure(aTHX_ v, "Punk::Observe::Plot::volume_figure",
705 store, q, ql, "volume_plot");
706  
707 27 ▶ HV *meta = (mv && SvROK(*mv) && SvTYPE(SvRV(*mv)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *meta = (mv && SvROK(*mv) && SvTYPE(SvRV(*mv)) == SVt_PVHV) 27 0 27
HV *meta = (mv && SvROK(*mv) && SvTYPE(SvRV(*mv)) == SVt_PVHV) 27 0 27
708 54 ▶ ? (HV *)SvRV(*mv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*mv) : NULL; 27 0 27
709  
710 27 ▶ if (!is_rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (!is_rows) { 5 22 27
711 /* An aggregate over logs is a table of numbers and is
712 * rendered as one. Drawing it as a log list would be
713 * inventing rows. */
714 5 AV *groups = newAV();
715 5 SV **gv = hv_fetchs(r, "groups", 0);
716 5 ▶ if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 4 1 5
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 4 0 4
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 4 0 4
717 4 AV *ga = (AV *)SvRV(*gv);
718 4 SSize_t i, n = av_len(ga) + 1;
719 12 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 8 4 12
720 8 SV **e = av_fetch(ga, i, 0);
721 HV *g, *o;
722 SV **x;
723 8 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 8 0 8
if (!e || !SvROK(*e)) continue; 0 8 8
724 8 g = (HV *)SvRV(*e);
725 8 o = newHV();
726 8 x = hv_fetchs(g, "key", 0);
727 8 ▶ hv_stores(o, "key", x ? newSVsv(*x) : newSVpvs(""));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "key", x ? newSVsv(*x) : newSVpvs("")); 8 0 8
728 8 x = hv_fetchs(g, "value", 0);
729 8 ▶ hv_stores(o, "value",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "value", 8 0 8
730 x ? povw_fmt_value(aTHX_ (double)SvNV(*x))
731 : newSVpvs("0"));
732 8 povw_set_count(aTHX_ o, "count", g, "count");
733 8 av_push(groups, newRV_noinc((SV *)o));
734 }
735 }
736 5 hv_stores(v, "groups", newRV_noinc((SV *)groups));
737 }
738 else {
739 22 AV *rows = newAV();
740 22 SV **rv = hv_fetchs(r, "rows", 0);
741 22 ▶ if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 22 0 22
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 22 0 22
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 22 0 22
742 22 AV *ra = (AV *)SvRV(*rv);
743 22 SSize_t i, n = av_len(ra) + 1;
744 1440 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 1418 22 1440
745 1418 SV **e = av_fetch(ra, i, 0);
746 HV *row, *o;
747 SV **x;
748 int sev;
749 const char *sname;
750 char tb[40];
751 size_t tn;
752 1418 STRLEN tl = 0;
753 const char *tp;
754  
755 1418 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 1418 0 1418
if (!e || !SvROK(*e)) continue; 0 1418 1418
756 1418 row = (HV *)SvRV(*e);
757 1418 o = newHV();
758  
759 1418 x = hv_fetchs(row, "severity", 0);
760 1418 ▶ sev = (x && SvOK(*x)) ? (int)SvIV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
sev = (x && SvOK(*x)) ? (int)SvIV(*x) : 0; 1418 0 1418
sev = (x && SvOK(*x)) ? (int)SvIV(*x) : 0; 1418 0 1418
761 1418 sname = po_severity_name(sev);
762  
763 1418 x = hv_fetchs(row, "t", 0);
764 2836 ▶ tp = (x && SvOK(*x)) ? SvPV(*x, tl) : "";
Branch: 2 branches
BranchTrueFalseTotal
tp = (x && SvOK(*x)) ? SvPV(*x, tl) : ""; 1418 0 1418
tp = (x && SvOK(*x)) ? SvPV(*x, tl) : ""; 1418 0 1418
765 1418 tn = po_fmt_time(tp, (size_t)tl, tb);
766 1418 hv_stores(o, "time", newSVpvn(tb, tn));
767 1418 tn = po_fmt_date(tp, (size_t)tl, tb);
768 1418 hv_stores(o, "date", newSVpvn(tb, tn));
769  
770 1418 hv_stores(o, "sev_name", newSVpv(sname, 0));
771 1418 hv_stores(o, "severity", newSViv(sev));
772  
773 1418 x = hv_fetchs(row, "service", 0);
774 1418 ▶ hv_stores(o, "service", (x && SvOK(*x) && SvCUR(*x))
Branch: 3 branches
BranchTrueFalseTotal
hv_stores(o, "service", (x && SvOK(*x) && SvCUR(*x)) 1418 0 1418
hv_stores(o, "service", (x && SvOK(*x) && SvCUR(*x)) 1418 0 1418
hv_stores(o, "service", (x && SvOK(*x) && SvCUR(*x)) 1418 0 1418
775 ? newSVsv(*x) : newSVpvs("unknown"));
776 1418 x = hv_fetchs(row, "body", 0);
777 1418 ▶ hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 1418 0 1418
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 1418 0 1418
778 : newSVpvs(""));
779 /* Colour is never the only signal: the row carries a
780 * class that adds weight and a marker too. */
781 1418 ▶ hv_stores(o, "row_class",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "row_class", 1407 11 1418
hv_stores(o, "row_class", 0 1407 1407
782 (strEQ(sname, "error") || strEQ(sname, "fatal"))
783 ? newSVpvs("row-error") : newSVpvs(""));
784  
785 { /* THE CANONICAL SPELLING, the same one every
786 * link in this UI carries and the same one a
787 * `traceparent` header does. The decimal pair is
788 * what the record holds; it is not what anybody
789 * reads, pastes or recognises. */
790 1418 SV **hi = hv_fetchs(row, "trace_hi", 0);
791 1418 SV **lo = hv_fetchs(row, "trace_lo", 0);
792 17 ▶ int any = (hi && SvOK(*hi) && SvTRUE(*hi))
Branch: 2 branches
BranchTrueFalseTotal
int any = (hi && SvOK(*hi) && SvTRUE(*hi)) 17 0 17
int any = (hi && SvOK(*hi) && SvTRUE(*hi)) 0 17 17
793 1435 ▶ || (lo && SvOK(*lo) && SvTRUE(*lo));
Branch: 4 branches
BranchTrueFalseTotal
|| (lo && SvOK(*lo) && SvTRUE(*lo)); 17 1401 1418
|| (lo && SvOK(*lo) && SvTRUE(*lo)); 0 1401 1401
|| (lo && SvOK(*lo) && SvTRUE(*lo)); 0 0 0
|| (lo && SvOK(*lo) && SvTRUE(*lo)); 0 0 0
794 1418 ▶ if (any)
Branch: 1 branch
BranchTrueFalseTotal
if (any) 17 1401 1418
795 17 ▶ hv_stores(o, "trace",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "trace", 17 0 17
hv_stores(o, "trace", 17 0 17
796 povw_trace_hex_sv(aTHX_
797 hi ? *hi : &PL_sv_no,
798 lo ? *lo : &PL_sv_no));
799 1401 else hv_stores(o, "trace", newSVpvs(""));
800 }
801  
802 1418 hv_stores(o, "id", povw_record_id_sv(aTHX_ *e));
803 1418 av_push(rows, newRV_noinc((SV *)o));
804 }
805  
806 /* THE WAY TO THE 501st LINE. Rows are newest first, so
807 * when the page is full the oldest line shown is the
808 * cursor for the next one: `before=<its instant>` narrows
809 * the window's top and everything else in the URL stays.
810 * Only when full - a short page IS the end, and an
811 * "older" link there would page into nothing. */
812 22 ▶ if (n >= POVW_LOG_PAGE && n > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (n >= POVW_LOG_PAGE && n > 0) { 2 20 22
if (n >= POVW_LOG_PAGE && n > 0) { 2 0 2
813 2 SV **le = av_fetch(ra, n - 1, 0);
814 2 ▶ SV **lt = (le && SvROK(*le))
Branch: 1 branch
BranchTrueFalseTotal
SV **lt = (le && SvROK(*le)) 2 0 2
815 4 ▶ ? hv_fetchs((HV *)SvRV(*le), "t", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*le), "t", 0) : NULL; 2 0 2
816 2 ▶ if (lt && SvOK(*lt))
Branch: 2 branches
BranchTrueFalseTotal
if (lt && SvOK(*lt)) 2 0 2
if (lt && SvOK(*lt)) 2 0 2
817 2 hv_stores(v, "older_cursor", newSVsv(*lt));
818 }
819 }
820 22 hv_stores(v, "rows", newRV_noinc((SV *)rows));
821 22 ▶ if (meta) povw_set_iv(aTHX_ v, "degraded", meta, "degraded");
Branch: 1 branch
BranchTrueFalseTotal
if (meta) povw_set_iv(aTHX_ v, "degraded", meta, "degraded"); 22 0 22
822 }
823  
824 27 ▶ if (meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (meta) { 27 0 27
825 27 povw_set_count(aTHX_ v, "scanned", meta, "scanned_rows");
826 27 povw_set_iv(aTHX_ v, "truncated", meta, "truncated");
827 }
828 }
829 27 SvREFCNT_dec(res);
830  
831 /* ONE EXIT.
832 *
833 * An early XSRETURN in a CODE:/OUTPUT: body returns before the generated
834 * OUTPUT block has pushed RETVAL, so the caller gets whatever happened to
835 * be on the stack - which for the error path here was an empty page with
836 * no error on it, exactly when there was something to say. */
837 28 done:
838 28 RETVAL = newRV_noinc((SV *)v);
839 }
840 OUTPUT:
841 RETVAL
842  
843 SV *
844 povw__parent_id(SV *tree, SV *span)
845 CODE:
846 0 RETVAL = povw_parent_id_sv(aTHX_ tree, span);
847 OUTPUT:
848 RETVAL
849  
850 # One dashboard, its panels each run through the same query path the explorer
851 # uses - so a chart on a dashboard and the same chart in the explorer are the
852 # same code and cannot disagree.
853 SV *
854 povw__page_dashboard(SV *class, SV *store, SV *req)
855 CODE:
856 {
857 34 HV *v = newHV();
858 34 HV *rq = NULL;
859 34 SV *from = NULL, *to = NULL;
860 SV **f;
861 34 SV *src = NULL, *d = NULL;
862 34 HV *dh = NULL;
863 34 const char *slug = "";
864 34 STRLEN sl = 0;
865  
866 PERL_UNUSED_VAR(class);
867 34 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 34 0 34
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 34 0 34
868 44 ▶ if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) slug = SvPV(*f, sl);
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) slug = SvPV(*f, sl); 34 0 34
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) slug = SvPV(*f, sl); 10 24 34
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) slug = SvPV(*f, sl); 10 0 10
869  
870 34 hv_stores(v, "heading", newSVpvs("Dashboard"));
871 34 hv_stores(v, "title", newSVpvs("Dashboard"));
872 34 hv_stores(v, "panels", newRV_noinc((SV *)newAV()));
873 34 hv_stores(v, "cols", newSViv(2));
874 34 hv_stores(v, "slug", newSVpvn(slug, sl));
875 34 hv_stores(v, "can_edit", newSViv(0));
876 34 hv_stores(v, "configured", newSViv(0));
877 34 povw_window_vars(aTHX_ v, req, &from, &to);
878 /* The window variables INCLUDE the range control, and the page shows
879 * it: every panel already runs over the reader's window, and hiding
880 * the picker made the dashboard the one screen where narrowing to
881 * the incident meant editing the URL by hand. */
882  
883 34 ▶ if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) ? *f : NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) ? *f : NULL; 34 0 34
if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) ? *f : NULL; 34 0 34
if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) ? *f : NULL; 34 0 34
884 34 ▶ if (!src) goto done;
Branch: 1 branch
BranchTrueFalseTotal
if (!src) goto done; 0 34 34
885 34 hv_stores(v, "configured", newSViv(1));
886  
887 /* A coderef is how a host supplies one dashboard at a time; a plain
888 * hashref is how a test supplies the only one there is. */
889 41 ▶ if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 34 0 34
if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 7 27 34
890 int n;
891 7 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 7 7
892 7 ▶ XPUSHs(sv_2mortal(newSVpvn(slug, sl)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(slug, sl))); 0 7 7
893 7 ▶ XPUSHs(req);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(req); 0 7 7
894 7 PUTBACK;
895 7 n = call_sv(src, G_SCALAR | G_EVAL);
896 7 SPAGAIN;
897 7 ▶ d = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
d = n ? SvREFCNT_inc(POPs) : NULL; 7 0 7
898 7 PUTBACK;
899 7 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 7 0 7
900 7 SPAGAIN;
901 7 ▶ if (povw_seam_died(aTHX_ v, "dashboard")) {
Branch: 1 branch
BranchTrueFalseTotal
if (povw_seam_died(aTHX_ v, "dashboard")) { 0 7 7
902 0 ▶ if (d) SvREFCNT_dec(d);
Branch: 1 branch
BranchTrueFalseTotal
if (d) SvREFCNT_dec(d); 0 0 0
903 0 d = NULL;
904 }
905 }
906 27 else d = SvREFCNT_inc(src);
907  
908 34 ▶ if (!d || !SvROK(d) || SvTYPE(SvRV(d)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!d || !SvROK(d) || SvTYPE(SvRV(d)) != SVt_PVHV) { 34 0 34
if (!d || !SvROK(d) || SvTYPE(SvRV(d)) != SVt_PVHV) { 34 0 34
if (!d || !SvROK(d) || SvTYPE(SvRV(d)) != SVt_PVHV) { 0 34 34
909 0 ▶ if (d) SvREFCNT_dec(d);
Branch: 1 branch
BranchTrueFalseTotal
if (d) SvREFCNT_dec(d); 0 0 0
910 0 goto done;
911 }
912 34 dh = (HV *)SvRV(d);
913  
914 {
915 34 SV **t = hv_fetchs(dh, "title", 0);
916 34 ▶ SV *title = (t && SvOK(*t) && SvCUR(*t)) ? newSVsv(*t)
Branch: 2 branches
BranchTrueFalseTotal
SV *title = (t && SvOK(*t) && SvCUR(*t)) ? newSVsv(*t) 34 0 34
SV *title = (t && SvOK(*t) && SvCUR(*t)) ? newSVsv(*t) 34 0 34
917 34 ▶ : (sl ? newSVpvn(slug, sl) : newSVpvs("Dashboard"));
Branch: 2 branches
BranchTrueFalseTotal
: (sl ? newSVpvn(slug, sl) : newSVpvs("Dashboard")); 34 0 34
: (sl ? newSVpvn(slug, sl) : newSVpvs("Dashboard")); 0 0 0
918 34 hv_stores(v, "title", newSVsv(title));
919 34 hv_stores(v, "heading", title);
920 }
921 {
922 34 SV **c = hv_fetchs(dh, "cols", 0);
923 34 ▶ hv_stores(v, "cols",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "cols", 13 21 34
hv_stores(v, "cols", 13 0 13
924 newSViv(povw_grid((c && SvOK(*c)) ? SvIV(*c) : 0, 2)));
925 }
926 {
927 34 SV **e = hv_fetchs(dh, "can_edit", 0);
928 34 ▶ hv_stores(v, "can_edit", newSViv(e && SvTRUE(*e) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "can_edit", newSViv(e && SvTRUE(*e) ? 1 : 0)); 2 32 34
hv_stores(v, "can_edit", newSViv(e && SvTRUE(*e) ? 1 : 0)); 2 0 2
929 }
930 {
931 /* THE RESOLVED SLUG, when the reader supplies one: with no slug
932 * in the URL the reader falls back to the first dashboard, and
933 * every per-panel fragment URL, the range form and the edit
934 * button must name the dashboard actually shown - an empty
935 * segment in the middle of a deferred URL is a panel that
936 * never loads, on exactly the page a bookmark lands on. */
937 34 SV **s2 = hv_fetchs(dh, "slug", 0);
938 34 ▶ if (s2 && SvOK(*s2) && SvCUR(*s2))
Branch: 3 branches
BranchTrueFalseTotal
if (s2 && SvOK(*s2) && SvCUR(*s2)) 9 25 34
if (s2 && SvOK(*s2) && SvCUR(*s2)) 9 0 9
if (s2 && SvOK(*s2) && SvCUR(*s2)) 9 0 9
939 9 hv_stores(v, "slug", newSVsv(*s2));
940 }
941 {
942 34 AV *list = newAV();
943 34 SV **lv = hv_fetchs(dh, "list", 0);
944 34 ▶ if (lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVAV) { 2 32 34
if (lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVAV) { 2 0 2
if (lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVAV) { 2 0 2
945 2 AV *la = (AV *)SvRV(*lv);
946 2 SSize_t i, n = av_len(la) + 1;
947 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 2 2 4
948 2 SV **e = av_fetch(la, i, 0);
949 HV *o, *s;
950 SV **x;
951 2 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 2 0 2
if (!e || !SvROK(*e)) continue; 0 2 2
952 2 s = (HV *)SvRV(*e);
953 2 o = newHV();
954 2 x = hv_fetchs(s, "slug", 0);
955 2 ▶ hv_stores(o, "slug", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "slug", x ? newSVsv(*x) : newSV(0)); 2 0 2
956 2 x = hv_fetchs(s, "title", 0);
957 2 ▶ hv_stores(o, "title", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "title", x ? newSVsv(*x) : newSV(0)); 2 0 2
958 2 av_push(list, newRV_noinc((SV *)o));
959 }
960 }
961 34 hv_stores(v, "list", newRV_noinc((SV *)list));
962 }
963  
964 {
965 34 AV *panels = newAV();
966 34 SV **pv = hv_fetchs(dh, "panels", 0);
967 34 ▶ if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 34 0 34
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 34 0 34
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 34 0 34
968 34 AV *pa = (AV *)SvRV(*pv);
969 34 SSize_t i, n = av_len(pa) + 1;
970 po_sortpair *ord;
971  
972 /* Panel ORDER is a number and layout is a column count, and
973 * the absence of a drag grid is the deliberate subtraction it
974 * looks like. */
975 34 ▶ Newx(ord, n ? n : 1, po_sortpair);
Branch: 3 branches
BranchTrueFalseTotal
Newx(ord, n ? n : 1, po_sortpair); 34 0 34
Newx(ord, n ? n : 1, po_sortpair); 0 34 34
Newx(ord, n ? n : 1, po_sortpair); 34 0 34
976 83 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 49 34 83
977 49 SV **e = av_fetch(pa, i, 0);
978 /* `position`, which is the SQL column name. The
979 * renderer read `order`, check_panel read `position` and
980 * `cols`, and the schema had `position` and `span`:
981 * three names for two things, inert only while nothing
982 * wrote a row. Settled on the names with a schema behind
983 * them. */
984 49 ▶ SV **o = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **o = (e && SvROK(*e)) 49 0 49
985 98 ▶ ? hv_fetchs((HV *)SvRV(*e), "position", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "position", 0) : NULL; 49 0 49
986 /* Descending sort, so the key is negated to get
987 * ascending order out of it. */
988 49 ▶ ord[i].key = (po_u64)(1000000 - ((o && SvOK(*o)) ? SvIV(*o) : 0));
Branch: 2 branches
BranchTrueFalseTotal
ord[i].key = (po_u64)(1000000 - ((o && SvOK(*o)) ? SvIV(*o) : 0)); 21 28 49
ord[i].key = (po_u64)(1000000 - ((o && SvOK(*o)) ? SvIV(*o) : 0)); 21 0 21
989 49 ▶ ord[i].sv = e ? *e : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ord[i].sv = e ? *e : &PL_sv_undef; 49 0 49
990 }
991 34 ▶ if (n > 1) qsort(ord, (size_t)n, sizeof(po_sortpair),
Branch: 1 branch
BranchTrueFalseTotal
if (n > 1) qsort(ord, (size_t)n, sizeof(po_sortpair), 11 23 34
992 po_sortpair_desc);
993  
994 83 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 49 34 83
995 HV *p, *panel;
996 SV **x;
997  
998 49 ▶ if (!SvROK(ord[i].sv)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(ord[i].sv)) continue; 0 49 49
999 49 p = (HV *)SvRV(ord[i].sv);
1000 49 panel = povw_panel_meta(aTHX_ p, i);
1001  
1002 /* THE BODY IS BUILT ONLY WHEN ASKED FOR. The shell
1003 * ships metadata and a deferred placeholder per panel;
1004 * ?full=1 sets `panels_inline` and pays for the queries
1005 * with the page; the editor never sets it - it renders
1006 * forms, and used to run every panel's query for
1007 * nothing. */
1008 49 ▶ if (rq && (x = hv_fetchs(rq, "panels_inline", 0))
Branch: 2 branches
BranchTrueFalseTotal
if (rq && (x = hv_fetchs(rq, "panels_inline", 0)) 49 0 49
if (rq && (x = hv_fetchs(rq, "panels_inline", 0)) 31 18 49
1009 31 ▶ && SvTRUE(*x))
Branch: 1 branch
BranchTrueFalseTotal
&& SvTRUE(*x)) 31 0 31
1010 31 povw_panel_fill(aTHX_ panel, ord[i].sv, store,
1011 from, to);
1012  
1013 49 av_push(panels, newRV_noinc((SV *)panel));
1014 }
1015 34 Safefree(ord);
1016 }
1017 34 hv_stores(v, "panels", newRV_noinc((SV *)panels));
1018 }
1019 34 SvREFCNT_dec(d);
1020  
1021 34 done:
1022 34 ▶ if (from) SvREFCNT_dec(from);
Branch: 1 branch
BranchTrueFalseTotal
if (from) SvREFCNT_dec(from); 34 0 34
1023 34 ▶ if (to) SvREFCNT_dec(to);
Branch: 1 branch
BranchTrueFalseTotal
if (to) SvREFCNT_dec(to); 34 0 34
1024 34 RETVAL = newRV_noinc((SV *)v);
1025 }
1026 OUTPUT:
1027 RETVAL
1028  
1029 # One dashboard panel, body and all, for the deferred-fragment route.
1030 #
1031 # Resolves the dashboard through the SAME reader seam as the page, sorts
1032 # the panels the same way (the index fallback key depends on it), finds the
1033 # one the key names, and builds meta + body. Returns undef when the
1034 # dashboard or the panel is not there - a deleted panel is a 404, not a
1035 # broken page.
1036 SV *
1037 povw__panel(SV *class, SV *store, SV *req)
1038 CODE:
1039 {
1040 7 HV *rq = NULL;
1041 7 HV *scratch = newHV();
1042 7 SV *from = NULL, *to = NULL;
1043 SV **f;
1044 7 SV *src = NULL, *d = NULL;
1045 7 HV *dh = NULL;
1046 7 HV *out = NULL;
1047 7 const char *slug = "";
1048 7 STRLEN sl = 0;
1049 7 const char *key = "";
1050 7 STRLEN kl = 0;
1051  
1052 PERL_UNUSED_VAR(class);
1053 7 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) 7 0 7
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) 7 0 7
1054 7 rq = (HV *)SvRV(req);
1055 7 ▶ if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f))
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) 7 0 7
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) 6 1 7
if (rq && (f = hv_fetchs(rq, "slug", 0)) && SvOK(*f)) 6 0 6
1056 12 slug = SvPV(*f, sl);
1057 7 ▶ if (rq && (f = hv_fetchs(rq, "panel", 0)) && SvOK(*f))
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "panel", 0)) && SvOK(*f)) 7 0 7
if (rq && (f = hv_fetchs(rq, "panel", 0)) && SvOK(*f)) 7 0 7
if (rq && (f = hv_fetchs(rq, "panel", 0)) && SvOK(*f)) 7 0 7
1058 14 key = SvPV(*f, kl);
1059 7 povw_window_vars(aTHX_ scratch, req, &from, &to);
1060  
1061 21 ▶ if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f)
Branch: 2 branches
BranchTrueFalseTotal
if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) 7 0 7
if (rq) src = (f = hv_fetchs(rq, "dashboards", 0)) && SvOK(*f) 7 0 7
1062 14 ▶ ? *f : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? *f : NULL; 7 0 7
1063 10 ▶ if (src && SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) {
Branch: 3 branches
BranchTrueFalseTotal
if (src && SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 7 0 7
if (src && SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 7 0 7
if (src && SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 3 4 7
1064 int n;
1065 3 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 3 3
1066 3 ▶ XPUSHs(sv_2mortal(newSVpvn(slug, sl)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(slug, sl))); 0 3 3
1067 3 ▶ XPUSHs(req);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(req); 0 3 3
1068 3 PUTBACK;
1069 3 n = call_sv(src, G_SCALAR | G_EVAL);
1070 3 SPAGAIN;
1071 3 ▶ d = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
d = n ? SvREFCNT_inc(POPs) : NULL; 3 0 3
1072 3 PUTBACK;
1073 3 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 3 0 3
1074 3 SPAGAIN;
1075 3 ▶ if (SvTRUE(ERRSV)) { if (d) SvREFCNT_dec(d); d = NULL; }
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { if (d) SvREFCNT_dec(d); d = NULL; } 3 0 3
if (SvTRUE(ERRSV)) { if (d) SvREFCNT_dec(d); d = NULL; } 0 3 3
if (SvTRUE(ERRSV)) { if (d) SvREFCNT_dec(d); d = NULL; } 0 0 0
1076 }
1077 4 ▶ else if (src) d = SvREFCNT_inc(src);
Branch: 1 branch
BranchTrueFalseTotal
else if (src) d = SvREFCNT_inc(src); 4 0 4
1078  
1079 7 ▶ if (d && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (d && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) 7 0 7
if (d && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) 7 0 7
if (d && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) 7 0 7
1080 7 dh = (HV *)SvRV(d);
1081  
1082 7 ▶ if (dh && kl) {
Branch: 2 branches
BranchTrueFalseTotal
if (dh && kl) { 7 0 7
if (dh && kl) { 7 0 7
1083 7 SV **pv = hv_fetchs(dh, "panels", 0);
1084 7 ▶ if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 7 0 7
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 7 0 7
if (pv && SvROK(*pv) && SvTYPE(SvRV(*pv)) == SVt_PVAV) { 7 0 7
1085 7 AV *pa = (AV *)SvRV(*pv);
1086 7 SSize_t i, n = av_len(pa) + 1;
1087 po_sortpair *ord;
1088  
1089 /* The page's own ordering, exactly: an index key handed
1090 * out by the shell must land on the same panel here. */
1091 7 ▶ Newx(ord, n ? n : 1, po_sortpair);
Branch: 3 branches
BranchTrueFalseTotal
Newx(ord, n ? n : 1, po_sortpair); 7 0 7
Newx(ord, n ? n : 1, po_sortpair); 0 7 7
Newx(ord, n ? n : 1, po_sortpair); 7 0 7
1092 20 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 13 7 20
1093 13 SV **e = av_fetch(pa, i, 0);
1094 13 ▶ SV **o = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **o = (e && SvROK(*e)) 13 0 13
1095 26 ▶ ? hv_fetchs((HV *)SvRV(*e), "position", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "position", 0) : NULL; 13 0 13
1096 13 ▶ ord[i].key = (po_u64)(1000000
Branch: 1 branch
BranchTrueFalseTotal
ord[i].key = (po_u64)(1000000 12 1 13
1097 12 ▶ - ((o && SvOK(*o)) ? SvIV(*o) : 0));
Branch: 1 branch
BranchTrueFalseTotal
- ((o && SvOK(*o)) ? SvIV(*o) : 0)); 12 0 12
1098 13 ▶ ord[i].sv = e ? *e : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ord[i].sv = e ? *e : &PL_sv_undef; 13 0 13
1099 }
1100 7 ▶ if (n > 1) qsort(ord, (size_t)n, sizeof(po_sortpair),
Branch: 1 branch
BranchTrueFalseTotal
if (n > 1) qsort(ord, (size_t)n, sizeof(po_sortpair), 6 1 7
1101 po_sortpair_desc);
1102  
1103 20 ▶ for (i = 0; i < n && !out; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n && !out; i++) { 13 7 20
for (i = 0; i < n && !out; i++) { 13 0 13
1104 HV *p, *panel;
1105 SV **kv;
1106 STRLEN pkl;
1107 const char *pk;
1108 13 ▶ if (!SvROK(ord[i].sv)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(ord[i].sv)) continue; 0 13 13
1109 13 p = (HV *)SvRV(ord[i].sv);
1110 13 panel = povw_panel_meta(aTHX_ p, i);
1111 13 kv = hv_fetchs(panel, "key", 0);
1112 26 ▶ pk = (kv && SvOK(*kv)) ? SvPV(*kv, pkl) : "";
Branch: 2 branches
BranchTrueFalseTotal
pk = (kv && SvOK(*kv)) ? SvPV(*kv, pkl) : ""; 13 0 13
pk = (kv && SvOK(*kv)) ? SvPV(*kv, pkl) : ""; 13 0 13
1113 13 ▶ if (pkl == (STRLEN)kl && memcmp(pk, key, kl) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (pkl == (STRLEN)kl && memcmp(pk, key, kl) == 0) { 8 5 13
if (pkl == (STRLEN)kl && memcmp(pk, key, kl) == 0) { 5 3 8
1114 5 povw_panel_fill(aTHX_ panel, ord[i].sv, store,
1115 from, to);
1116 5 out = panel;
1117 }
1118 8 else SvREFCNT_dec((SV *)panel);
1119 }
1120 7 Safefree(ord);
1121 }
1122 }
1123  
1124 7 ▶ if (d) SvREFCNT_dec(d);
Branch: 1 branch
BranchTrueFalseTotal
if (d) SvREFCNT_dec(d); 7 0 7
1125 7 SvREFCNT_dec((SV *)scratch);
1126 7 ▶ if (from) SvREFCNT_dec(from);
Branch: 1 branch
BranchTrueFalseTotal
if (from) SvREFCNT_dec(from); 7 0 7
1127 7 ▶ if (to) SvREFCNT_dec(to);
Branch: 1 branch
BranchTrueFalseTotal
if (to) SvREFCNT_dec(to); 7 0 7
1128 7 ▶ RETVAL = out ? newRV_noinc((SV *)out) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out ? newRV_noinc((SV *)out) : newSV(0); 5 2 7
1129 }
1130 OUTPUT:
1131 RETVAL
1132  
1133 # A trace identifier as the 32 hex characters everybody else spells it with.
1134 #
1135 # THE ID IN THE URL AND THE ID ON THE SCREEN MUST BE THE SAME ID. The list
1136 # showed eight hex characters derived from the high half by a modulo, and
1137 # linked to `<hi>-<lo>` in decimal - so the thing you read was not a prefix of
1138 # the thing you clicked, was not what a `traceparent` header would show, and
1139 # could not be pasted anywhere. Two spellings of one identifier, neither of
1140 # them canonical.
1141 SV *
1142 povw_trace_hex(SV *hi_sv, SV *lo_sv)
1143 CODE:
1144 0 RETVAL = povw_trace_hex_sv(aTHX_ hi_sv, lo_sv);
1145 OUTPUT:
1146 RETVAL
1147  
1148 SV *
1149 povw__page_alerts(SV *class, SV *store, SV *req)
1150 CODE:
1151 {
1152 4 HV *v = newHV();
1153 4 HV *rq = NULL;
1154 SV **f;
1155 4 SV *src = NULL, *r = NULL;
1156 4 HV *rh = NULL;
1157 4 const char *filter = NULL;
1158 4 STRLEN flen = 0;
1159 4 AV *rules = newAV();
1160 4 IV broken = 0;
1161  
1162 PERL_UNUSED_VAR(class);
1163 PERL_UNUSED_VAR(store);
1164 4 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 4 0 4
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 4 0 4
1165  
1166 4 hv_stores(v, "heading", newSVpvs("Alerts"));
1167 4 hv_stores(v, "title", newSVpvs("Alerts"));
1168 4 hv_stores(v, "silences", newRV_noinc((SV *)newAV()));
1169 4 hv_stores(v, "broken", newSViv(0));
1170 4 hv_stores(v, "can_edit", newSViv(0));
1171 4 hv_stores(v, "configured", newSViv(0));
1172 4 ▶ if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) {
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 4 0 4
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 1 3 4
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 1 0 1
1173 1 hv_stores(v, "query", newSVsv(*f));
1174 2 filter = SvPV(*f, flen);
1175 }
1176 3 else hv_stores(v, "query", newSVpvs(""));
1177  
1178 4 ▶ if (rq) { f = hv_fetchs(rq, "alerts", 0); src = (f && SvTRUE(*f)) ? *f : NULL; }
Branch: 3 branches
BranchTrueFalseTotal
if (rq) { f = hv_fetchs(rq, "alerts", 0); src = (f && SvTRUE(*f)) ? *f : NULL; } 4 0 4
if (rq) { f = hv_fetchs(rq, "alerts", 0); src = (f && SvTRUE(*f)) ? *f : NULL; } 3 1 4
if (rq) { f = hv_fetchs(rq, "alerts", 0); src = (f && SvTRUE(*f)) ? *f : NULL; } 3 0 3
1179 4 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 1 3 4
1180 1 hv_stores(v, "rules", newRV_noinc((SV *)rules));
1181 1 hv_stores(v, "empty", newSViv(1));
1182 1 goto done;
1183 }
1184 3 hv_stores(v, "configured", newSViv(1));
1185  
1186 4 ▶ if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 3 0 3
if (SvROK(src) && SvTYPE(SvRV(src)) == SVt_PVCV) { 1 2 3
1187 int n;
1188 1 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 1 1
1189 1 ▶ XPUSHs(req);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(req); 0 1 1
1190 1 PUTBACK;
1191 1 n = call_sv(src, G_SCALAR | G_EVAL);
1192 1 SPAGAIN;
1193 1 ▶ r = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
r = n ? SvREFCNT_inc(POPs) : NULL; 1 0 1
1194 1 PUTBACK;
1195 1 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 1 0 1
1196 1 SPAGAIN;
1197 1 ▶ if (povw_seam_died(aTHX_ v, "alert rule")) {
Branch: 1 branch
BranchTrueFalseTotal
if (povw_seam_died(aTHX_ v, "alert rule")) { 1 0 1
1198 1 ▶ if (r) SvREFCNT_dec(r);
Branch: 1 branch
BranchTrueFalseTotal
if (r) SvREFCNT_dec(r); 1 0 1
1199 1 r = NULL;
1200 }
1201 }
1202 2 else r = SvREFCNT_inc(src);
1203  
1204 3 ▶ if (!r || !SvROK(r) || SvTYPE(SvRV(r)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!r || !SvROK(r) || SvTYPE(SvRV(r)) != SVt_PVHV) { 2 1 3
if (!r || !SvROK(r) || SvTYPE(SvRV(r)) != SVt_PVHV) { 2 0 2
if (!r || !SvROK(r) || SvTYPE(SvRV(r)) != SVt_PVHV) { 0 2 2
1205 1 ▶ if (r) SvREFCNT_dec(r);
Branch: 1 branch
BranchTrueFalseTotal
if (r) SvREFCNT_dec(r); 0 1 1
1206 1 hv_stores(v, "rules", newRV_noinc((SV *)rules));
1207 1 goto done;
1208 }
1209 2 rh = (HV *)SvRV(r);
1210  
1211 2 f = hv_fetchs(rh, "can_edit", 0);
1212 2 ▶ hv_stores(v, "can_edit", newSViv(f && SvTRUE(*f) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "can_edit", newSViv(f && SvTRUE(*f) ? 1 : 0)); 2 0 2
hv_stores(v, "can_edit", newSViv(f && SvTRUE(*f) ? 1 : 0)); 2 0 2
1213  
1214 /* HOW LONG, AND HOW OFTEN - which a table of current state cannot
1215 * say. A row reading `firing` answers neither "since when" nor "for
1216 * the third time today", and a rule that flaps every twenty minutes
1217 * looks identical in that table to one that broke once.
1218 *
1219 * Drawn only where the seam supplied the transitions. They are the
1220 * evaluator's own record - alert_events in the shipped schema - and a
1221 * timeline inferred from current state alone would be a straight line
1222 * claiming the present has always been the case. */
1223 2 povw_add_figure_sv(aTHX_ v, "Punk::Observe::Plot::timeline_figure",
1224 r, "timeline_plot");
1225  
1226 {
1227 2 SV **rv = hv_fetchs(rh, "rules", 0);
1228 2 po_sortpair *ord = NULL;
1229 2 SSize_t nkeep = 0;
1230  
1231 2 ▶ if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 2 0 2
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 2 0 2
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 2 0 2
1232 2 AV *ra = (AV *)SvRV(*rv);
1233 2 SSize_t i, n = av_len(ra) + 1;
1234 2 ▶ Newx(ord, n ? n : 1, po_sortpair);
Branch: 3 branches
BranchTrueFalseTotal
Newx(ord, n ? n : 1, po_sortpair); 2 0 2
Newx(ord, n ? n : 1, po_sortpair); 0 2 2
Newx(ord, n ? n : 1, po_sortpair); 2 0 2
1235  
1236 14 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 12 2 14
1237 12 SV **e = av_fetch(ra, i, 0);
1238 HV *rule, *o;
1239 SV **x;
1240 12 const char *state = "ok";
1241 12 STRLEN slen = 2;
1242 int rank;
1243  
1244 16 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 12 0 12
if (!e || !SvROK(*e)) continue; 0 12 12
1245 12 rule = (HV *)SvRV(*e);
1246  
1247 /* A case-insensitive substring on the NAME, which is what
1248 * somebody types into the filter box. */
1249 12 ▶ if (filter && flen) {
Branch: 2 branches
BranchTrueFalseTotal
if (filter && flen) { 6 6 12
if (filter && flen) { 6 0 6
1250 6 SV **nm = hv_fetchs(rule, "name", 0);
1251 6 STRLEN nl = 0;
1252 12 ▶ const char *np = (nm && SvOK(*nm)) ? SvPV(*nm, nl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *np = (nm && SvOK(*nm)) ? SvPV(*nm, nl) : ""; 6 0 6
const char *np = (nm && SvOK(*nm)) ? SvPV(*nm, nl) : ""; 6 0 6
1253 6 ▶ if (!po_memfind(np, (size_t)nl, filter, (size_t)flen))
Branch: 1 branch
BranchTrueFalseTotal
if (!po_memfind(np, (size_t)nl, filter, (size_t)flen)) 4 2 6
1254 4 continue;
1255 }
1256  
1257 8 x = hv_fetchs(rule, "state", 0);
1258 16 ▶ if (x && SvOK(*x) && SvCUR(*x)) state = SvPV(*x, slen);
Branch: 3 branches
BranchTrueFalseTotal
if (x && SvOK(*x) && SvCUR(*x)) state = SvPV(*x, slen); 8 0 8
if (x && SvOK(*x) && SvCUR(*x)) state = SvPV(*x, slen); 8 0 8
if (x && SvOK(*x) && SvCUR(*x)) state = SvPV(*x, slen); 8 0 8
1259 8 ▶ if (slen == 5 && memcmp(state, "error", 5) == 0) broken++;
Branch: 2 branches
BranchTrueFalseTotal
if (slen == 5 && memcmp(state, "error", 5) == 0) broken++; 2 6 8
if (slen == 5 && memcmp(state, "error", 5) == 0) broken++; 1 1 2
1260  
1261 8 o = newHV();
1262 8 x = hv_fetchs(rule, "id", 0);
1263 8 ▶ hv_stores(o, "id", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "id", x ? newSVsv(*x) : newSV(0)); 8 0 8
1264 8 x = hv_fetchs(rule, "name", 0);
1265 8 ▶ hv_stores(o, "name", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "name", x ? newSVsv(*x) : newSV(0)); 8 0 8
1266 8 hv_stores(o, "state", newSVpvn(state, slen));
1267 8 x = hv_fetchs(rule, "series", 0);
1268 8 ▶ hv_stores(o, "series", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "series", x ? newSVsv(*x) : newSV(0)); 0 8 8
1269  
1270 /* WHY, for a rule that could not be evaluated. Counting
1271 * the broken rules without carrying the reason is how
1272 * the screen ended up saying "1 rule(s) could not be
1273 * evaluated" and nothing else. Carried whatever the
1274 * state: a reason on a non-error row is the reader's
1275 * bug to expose, not this table's to hide. */
1276 8 x = hv_fetchs(rule, "reason", 0);
1277 8 ▶ hv_stores(o, "reason", (x && SvOK(*x) && SvCUR(*x))
Branch: 3 branches
BranchTrueFalseTotal
hv_stores(o, "reason", (x && SvOK(*x) && SvCUR(*x)) 1 7 8
hv_stores(o, "reason", (x && SvOK(*x) && SvCUR(*x)) 1 0 1
hv_stores(o, "reason", (x && SvOK(*x) && SvCUR(*x)) 1 0 1
1278 ? newSVsv(*x) : newSVpvs(""));
1279  
1280 8 x = hv_fetchs(rule, "held", 0);
1281 10 ▶ if (x && SvTRUE(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) { 2 6 8
if (x && SvTRUE(*x)) { 2 0 2
1282 2 po_u64 h = 0;
1283 char b[32];
1284 size_t bn;
1285 2 (void)po_sv_to_u64(aTHX_ *x, &h);
1286 2 bn = po_fmt_dur(h, b);
1287 2 hv_stores(o, "held", newSVpvn(b, bn));
1288 }
1289 6 else hv_stores(o, "held", newSVpvs(""));
1290  
1291 8 x = hv_fetchs(rule, "value", 0);
1292 8 ▶ hv_stores(o, "value", (x && SvOK(*x))
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "value", (x && SvOK(*x)) 4 4 8
hv_stores(o, "value", (x && SvOK(*x)) 4 0 4
1293 ? povw_fmt_value(aTHX_ (double)SvNV(*x))
1294 : newSVpvs(""));
1295  
1296 8 x = hv_fetchs(rule, "silenced", 0);
1297 8 ▶ hv_stores(o, "silenced", newSViv(x && SvTRUE(*x) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "silenced", newSViv(x && SvTRUE(*x) ? 1 : 0)); 2 6 8
hv_stores(o, "silenced", newSViv(x && SvTRUE(*x) ? 1 : 0)); 2 0 2
1298  
1299 8 x = hv_fetchs(rule, "query", 0);
1300 {
1301 8 STRLEN ql = 0;
1302 9 ▶ const char *qp = (x && SvOK(*x)) ? SvPV(*x, ql) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *qp = (x && SvOK(*x)) ? SvPV(*x, ql) : ""; 1 7 8
const char *qp = (x && SvOK(*x)) ? SvPV(*x, ql) : ""; 1 0 1
1303 char *esc;
1304 size_t en;
1305 8 Newx(esc, ql * 3 + 1, char);
1306 8 en = po_url_esc(qp, (size_t)ql, esc, ql * 3 + 1);
1307 8 hv_stores(o, "query_esc", newSVpvn(esc, en));
1308 8 Safefree(esc);
1309 }
1310  
1311 /* An ERROR rule is one that could not be EVALUATED, which
1312 * is not a rule that is fine. It gets the error class,
1313 * never the ok one, however it sorts. */
1314 8 ▶ hv_stores(o, "row_class",
Branch: 4 branches
BranchTrueFalseTotal
hv_stores(o, "row_class", 4 4 8
hv_stores(o, "row_class", 0 4 4
hv_stores(o, "row_class", 2 2 4
hv_stores(o, "row_class", 1 1 2
1315 ((slen == 6 && memcmp(state, "firing", 6) == 0)
1316 || (slen == 5 && memcmp(state, "error", 5) == 0))
1317 ? newSVpvs("row-error") : newSVpvs(""));
1318  
1319 /* FIRING AND BROKEN FIRST. Sorted by name, a rule that
1320 * cannot evaluate sits wherever the alphabet puts it,
1321 * which is how it goes unnoticed. */
1322 2 ▶ rank = (slen == 5 && memcmp(state, "error", 5) == 0) ? 0
Branch: 1 branch
BranchTrueFalseTotal
rank = (slen == 5 && memcmp(state, "error", 5) == 0) ? 0 1 1 2
1323 20 ▶ : (slen == 6 && memcmp(state, "firing", 6) == 0) ? 1
Branch: 2 branches
BranchTrueFalseTotal
: (slen == 6 && memcmp(state, "firing", 6) == 0) ? 1 2 6 8
: (slen == 6 && memcmp(state, "firing", 6) == 0) ? 1 0 4 4
1324 15 ▶ : (slen == 7 && memcmp(state, "pending", 7) == 0) ? 2
Branch: 2 branches
BranchTrueFalseTotal
: (slen == 7 && memcmp(state, "pending", 7) == 0) ? 2 4 3 7
: (slen == 7 && memcmp(state, "pending", 7) == 0) ? 2 0 1 1
1325 7 ▶ : (slen == 2 && memcmp(state, "ok", 2) == 0) ? 3
Branch: 2 branches
BranchTrueFalseTotal
: (slen == 2 && memcmp(state, "ok", 2) == 0) ? 3 1 2 3
: (slen == 2 && memcmp(state, "ok", 2) == 0) ? 3 1 0 1
1326 3 ▶ : 9;
Branch: 1 branch
BranchTrueFalseTotal
: 9; 1 1 2
1327 8 ord[nkeep].key = (po_u64)(9 - rank); /* descending sort */
1328 8 ord[nkeep].sv = newRV_noinc((SV *)o);
1329 8 nkeep++;
1330 }
1331 }
1332  
1333 2 ▶ if (nkeep > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (nkeep > 1) { 2 0 2
1334 /* A stable sort, so the name is the tie-break: qsort is not
1335 * stable, and two rules in the same state would otherwise
1336 * come out in whichever order the input had. */
1337 SSize_t i, j;
1338 8 ▶ for (i = 1; i < nkeep; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < nkeep; i++) { 6 2 8
1339 6 po_sortpair k = ord[i];
1340 6 SV **kn = hv_fetchs((HV *)SvRV(k.sv), "name", 0);
1341 13 ▶ for (j = i - 1; j >= 0; j--) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = i - 1; j >= 0; j--) { 11 2 13
1342 11 SV **jn = hv_fetchs((HV *)SvRV(ord[j].sv), "name", 0);
1343 11 int worse = ord[j].key < k.key;
1344 11 ▶ if (!worse && ord[j].key == k.key) {
Branch: 2 branches
BranchTrueFalseTotal
if (!worse && ord[j].key == k.key) { 4 7 11
if (!worse && ord[j].key == k.key) { 2 2 4
1345 2 STRLEN al = 0, bl = 0;
1346 4 ▶ const char *ap = (jn && SvOK(*jn)) ? SvPV(*jn, al) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *ap = (jn && SvOK(*jn)) ? SvPV(*jn, al) : ""; 2 0 2
const char *ap = (jn && SvOK(*jn)) ? SvPV(*jn, al) : ""; 2 0 2
1347 4 ▶ const char *bp = (kn && SvOK(*kn)) ? SvPV(*kn, bl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *bp = (kn && SvOK(*kn)) ? SvPV(*kn, bl) : ""; 2 0 2
const char *bp = (kn && SvOK(*kn)) ? SvPV(*kn, bl) : ""; 2 0 2
1348 2 size_t m = al < bl ? al : bl;
1349 2 ▶ int c = m ? memcmp(ap, bp, m) : 0;
Branch: 1 branch
BranchTrueFalseTotal
int c = m ? memcmp(ap, bp, m) : 0; 2 0 2
1350 2 ▶ if (!c) c = al == bl ? 0 : (al < bl ? -1 : 1);
Branch: 3 branches
BranchTrueFalseTotal
if (!c) c = al == bl ? 0 : (al < bl ? -1 : 1); 0 2 2
if (!c) c = al == bl ? 0 : (al < bl ? -1 : 1); 0 0 0
if (!c) c = al == bl ? 0 : (al < bl ? -1 : 1); 0 0 0
1351 2 worse = c > 0;
1352 }
1353 11 ▶ if (!worse) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!worse) break; 4 7 11
1354 7 ord[j + 1] = ord[j];
1355 }
1356 6 ord[j + 1] = k;
1357 }
1358 }
1359 10 ▶ { SSize_t i; for (i = 0; i < nkeep; i++) av_push(rules, ord[i].sv); }
Branch: 1 branch
BranchTrueFalseTotal
{ SSize_t i; for (i = 0; i < nkeep; i++) av_push(rules, ord[i].sv); } 8 2 10
1360 2 Safefree(ord);
1361 }
1362 2 hv_stores(v, "rules", newRV_noinc((SV *)rules));
1363 2 hv_stores(v, "broken", newSViv(broken));
1364  
1365 {
1366 2 AV *sil = newAV();
1367 2 SV **sv = hv_fetchs(rh, "silences", 0);
1368 2 ▶ if (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 2 0 2
if (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 2 0 2
if (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 2 0 2
1369 2 AV *sa = (AV *)SvRV(*sv);
1370 2 SSize_t i, n = av_len(sa) + 1;
1371 6 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 2 6
1372 4 SV **e = av_fetch(sa, i, 0);
1373 HV *s, *o;
1374 SV **x;
1375 4 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 4 0 4
if (!e || !SvROK(*e)) continue; 0 4 4
1376 4 s = (HV *)SvRV(*e);
1377 4 o = newHV();
1378 /* The id, or the revoke button has nothing to name. */
1379 4 x = hv_fetchs(s, "id", 0);
1380 4 ▶ hv_stores(o, "id", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "id", x ? newSVsv(*x) : newSV(0)); 0 4 4
1381 4 x = hv_fetchs(s, "pattern", 0);
1382 4 ▶ hv_stores(o, "pattern", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "pattern", x ? newSVsv(*x) : newSV(0)); 4 0 4
1383 4 x = hv_fetchs(s, "until", 0);
1384 6 ▶ if (x && SvTRUE(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) { 2 2 4
if (x && SvTRUE(*x)) { 2 0 2
1385 STRLEN ul;
1386 2 const char *up = SvPV(*x, ul);
1387 char b[48];
1388 2 size_t bn = po_fmt_date(up, (size_t)ul, b);
1389 2 hv_stores(o, "until", newSVpvn(b, bn));
1390 }
1391 2 else hv_stores(o, "until", newSVpvs(""));
1392 4 x = hv_fetchs(s, "by", 0);
1393 4 ▶ hv_stores(o, "by", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "by", x ? newSVsv(*x) : newSV(0)); 4 0 4
1394 4 x = hv_fetchs(s, "reason", 0);
1395 4 ▶ hv_stores(o, "reason", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "reason", x ? newSVsv(*x) : newSV(0)); 2 2 4
1396 4 av_push(sil, newRV_noinc((SV *)o));
1397 }
1398 }
1399 2 ▶ hv_stores(v, "empty",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "empty", 0 2 2
hv_stores(v, "empty", 0 0 0
1400 newSViv((av_len(rules) < 0 && av_len(sil) < 0) ? 1 : 0));
1401 2 hv_stores(v, "silences", newRV_noinc((SV *)sil));
1402 }
1403 2 SvREFCNT_dec(r);
1404  
1405 4 done:
1406 4 RETVAL = newRV_noinc((SV *)v);
1407 }
1408 OUTPUT:
1409 RETVAL
1410  
1411 SV *
1412 povw__page_record(SV *class, SV *store, SV *req)
1413 CODE:
1414 {
1415 4 HV *v = newHV();
1416 4 HV *rq = NULL;
1417 SV **f;
1418 4 SV *id = NULL;
1419 4 HV *row = NULL;
1420 4 SV *rowref = NULL;
1421  
1422 PERL_UNUSED_VAR(class);
1423 4 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 4 0 4
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 4 0 4
1424  
1425 4 hv_stores(v, "heading", newSVpvs("Log line"));
1426 4 hv_stores(v, "title", newSVpvs("Log line"));
1427 4 hv_stores(v, "found", newSViv(0));
1428 4 hv_stores(v, "attrs", newRV_noinc((SV *)newAV()));
1429 4 hv_stores(v, "record", newRV_noinc((SV *)newHV()));
1430  
1431 4 ▶ if (rq && (f = hv_fetchs(rq, "id", 0)) && SvOK(*f)) id = *f;
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "id", 0)) && SvOK(*f)) id = *f; 4 0 4
if (rq && (f = hv_fetchs(rq, "id", 0)) && SvOK(*f)) id = *f; 4 0 4
if (rq && (f = hv_fetchs(rq, "id", 0)) && SvOK(*f)) id = *f; 4 0 4
1432 4 ▶ if (!id || !SvOK(store) || !SvROK(store)) goto done;
Branch: 3 branches
BranchTrueFalseTotal
if (!id || !SvOK(store) || !SvROK(store)) goto done; 4 0 4
if (!id || !SvOK(store) || !SvROK(store)) goto done; 4 0 4
if (!id || !SvOK(store) || !SvROK(store)) goto done; 0 4 4
1433  
1434 {
1435 /* The second the record CLAIMS, not the window: a link pasted into
1436 * a chat a week later still resolves. */
1437 4 STRLEN il = 0;
1438 4 const char *ip = SvPV(id, il);
1439 4 const char *dot = (const char *)memchr(ip, '.', (size_t)il);
1440 4 ▶ STRLEN tl = dot ? (STRLEN)(dot - ip) : il;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN tl = dot ? (STRLEN)(dot - ip) : il; 3 1 4
1441 4 SV *t = newSVpvn(ip, tl);
1442 4 AV *rows = NULL;
1443 4 SV *rowsref = NULL;
1444 int n;
1445  
1446 /* Read in the ROW shape, which is the shape the identifier was
1447 * derived from: `service` is lifted out of the attributes there,
1448 * and a record hashed with the attribute still in place hashes to
1449 * something else. */
1450 4 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 4 4
1451 4 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 4 4
1452 4 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(t)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(t))); 0 4 4
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(t))); 0 4 4
1453 4 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(t)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(t))); 0 4 4
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(t))); 0 4 4
1454 4 PUTBACK;
1455 4 n = call_method("rows", G_LIST);
1456 4 SPAGAIN;
1457 {
1458 SSize_t i;
1459 8 ▶ for (i = n - 1; i > 0; i--) (void)POPs; /* the meta half */
Branch: 1 branch
BranchTrueFalseTotal
for (i = n - 1; i > 0; i--) (void)POPs; /* the meta half */ 4 4 8
1460 4 ▶ rowsref = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
rowsref = n ? SvREFCNT_inc(POPs) : NULL; 4 0 4
1461 }
1462 4 PUTBACK;
1463 4 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 4 0 4
1464 4 SPAGAIN;
1465 4 SvREFCNT_dec(t);
1466  
1467 4 ▶ if (rowsref && SvROK(rowsref) && SvTYPE(SvRV(rowsref)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (rowsref && SvROK(rowsref) && SvTYPE(SvRV(rowsref)) == SVt_PVAV) 4 0 4
if (rowsref && SvROK(rowsref) && SvTYPE(SvRV(rowsref)) == SVt_PVAV) 4 0 4
if (rowsref && SvROK(rowsref) && SvTYPE(SvRV(rowsref)) == SVt_PVAV) 4 0 4
1468 4 rows = (AV *)SvRV(rowsref);
1469 4 ▶ if (rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (rows) { 4 0 4
1470 4 SSize_t i, cnt = av_len(rows) + 1;
1471 13 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 11 2 13
1472 11 SV **e = av_fetch(rows, i, 0);
1473 11 ▶ if (e && povw_record_matches_c(aTHX_ *e, id)) {
Branch: 2 branches
BranchTrueFalseTotal
if (e && povw_record_matches_c(aTHX_ *e, id)) { 11 0 11
if (e && povw_record_matches_c(aTHX_ *e, id)) { 2 9 11
1474 2 rowref = SvREFCNT_inc(*e);
1475 2 row = (HV *)SvRV(*e);
1476 2 break;
1477 }
1478 }
1479 }
1480 4 ▶ if (rowsref) SvREFCNT_dec(rowsref);
Branch: 1 branch
BranchTrueFalseTotal
if (rowsref) SvREFCNT_dec(rowsref); 4 0 4
1481 }
1482 4 ▶ if (!row) goto done;
Branch: 1 branch
BranchTrueFalseTotal
if (!row) goto done; 2 2 4
1483  
1484 {
1485 2 HV *rec = newHV();
1486 SV **x;
1487 const char *sev;
1488 2 const char *tp = "0";
1489 2 STRLEN tlen = 1;
1490 char b[64];
1491 size_t bn;
1492  
1493 2 x = hv_fetchs(row, "severity", 0);
1494 2 ▶ sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0);
Branch: 2 branches
BranchTrueFalseTotal
sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0); 2 0 2
sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0); 2 0 2
1495  
1496 2 x = hv_fetchs(row, "t", 0);
1497 4 ▶ if (x && SvOK(*x)) tp = SvPV(*x, tlen);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) tp = SvPV(*x, tlen); 2 0 2
if (x && SvOK(*x)) tp = SvPV(*x, tlen); 2 0 2
1498 2 bn = po_fmt_time(tp, (size_t)tlen, b);
1499 2 hv_stores(rec, "time", newSVpvn(b, bn));
1500 2 bn = po_fmt_date(tp, (size_t)tlen, b);
1501 2 hv_stores(rec, "date", newSVpvn(b, bn));
1502 2 ▶ hv_stores(rec, "t", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(rec, "t", x ? newSVsv(*x) : newSV(0)); 2 0 2
1503 2 hv_stores(rec, "sev_name", newSVpv(sev, 0));
1504  
1505 2 x = hv_fetchs(row, "service", 0);
1506 2 ▶ hv_stores(rec, "service", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(rec, "service", x ? newSVsv(*x) : newSV(0)); 2 0 2
1507 2 x = hv_fetchs(row, "body", 0);
1508 2 ▶ hv_stores(rec, "body", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(rec, "body", x ? newSVsv(*x) : newSV(0)); 2 0 2
1509 2 x = hv_fetchs(row, "kind", 0);
1510 2 ▶ hv_stores(rec, "kind", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(rec, "kind", x ? newSVsv(*x) : newSV(0)); 2 0 2
1511  
1512 2 x = hv_fetchs(row, "duration", 0);
1513 2 ▶ if (x && SvTRUE(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) { 2 0 2
if (x && SvTRUE(*x)) { 0 2 2
1514 0 po_u64 d = 0;
1515 0 (void)po_sv_to_u64(aTHX_ *x, &d);
1516 0 bn = po_fmt_dur(d, b);
1517 0 hv_stores(rec, "duration", newSVpvn(b, bn));
1518 }
1519 2 else hv_stores(rec, "duration", newSVpvs(""));
1520  
1521 {
1522 2 SV **hi = hv_fetchs(row, "trace_hi", 0);
1523 2 SV **lo = hv_fetchs(row, "trace_lo", 0);
1524 2 ▶ if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo)))
Branch: 4 branches
BranchTrueFalseTotal
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) 2 0 2
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) 1 1 2
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) 1 0 1
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) 0 1 1
1525 1 ▶ hv_stores(rec, "trace",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(rec, "trace", 1 0 1
hv_stores(rec, "trace", 1 0 1
1526 povw_trace_hex_sv(aTHX_ hi ? *hi : &PL_sv_no,
1527 lo ? *lo : &PL_sv_no));
1528 1 else hv_stores(rec, "trace", newSVpvs(""));
1529 }
1530  
1531 2 x = hv_fetchs(row, "span_id", 0);
1532 2 ▶ hv_stores(rec, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(rec, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x) 2 0 2
hv_stores(rec, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x) 1 1 2
1533 : newSVpvs(""));
1534  
1535 2 hv_stores(v, "found", newSViv(1));
1536 2 hv_stores(v, "record", newRV_noinc((SV *)rec));
1537  
1538 {
1539 2 SV *head = newSVpv(sev, 0);
1540 2 SV **svc = hv_fetchs(row, "service", 0);
1541 2 sv_catpvs(head, " - ");
1542 2 ▶ if (svc && SvOK(*svc)) sv_catsv(head, *svc);
Branch: 2 branches
BranchTrueFalseTotal
if (svc && SvOK(*svc)) sv_catsv(head, *svc); 2 0 2
if (svc && SvOK(*svc)) sv_catsv(head, *svc); 2 0 2
1543 2 hv_stores(v, "heading", head);
1544 }
1545 }
1546  
1547 { /* the attributes, in a stable order */
1548 2 AV *out = newAV();
1549 2 SV **av = hv_fetchs(row, "attrs", 0);
1550 2 ▶ if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 2 0 2
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 2 0 2
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 2 0 2
1551 2 HV *ah = (HV *)SvRV(*av);
1552 2 SSize_t nk = 0, i;
1553 2 po_sortpair *ks = NULL;
1554 HE *he;
1555 2 hv_iterinit(ah);
1556 2 ▶ Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair);
Branch: 7 branches
BranchTrueFalseTotal
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 0 2 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 2 0 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 0 2 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 0 2 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 0 2 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 2 0 2
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, po_sortpair); 0 2 2
1557 4 ▶ while ((he = hv_iternext(ah))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(ah))) { 2 2 4
1558 2 ks[nk].key = 0;
1559 2 ks[nk].sv = newSVsv(hv_iterkeysv(he));
1560 2 nk++;
1561 }
1562 /* insertion sort on the key text: the attribute count on one
1563 * record is small, and this keeps the comparison honest about
1564 * being a byte compare */
1565 2 ▶ for (i = 1; i < nk; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < nk; i++) { 0 2 2
1566 0 po_sortpair k = ks[i];
1567 SSize_t j;
1568 STRLEN kl;
1569 0 const char *kp = SvPV(k.sv, kl);
1570 0 ▶ for (j = i - 1; j >= 0; j--) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = i - 1; j >= 0; j--) { 0 0 0
1571 STRLEN jl;
1572 0 const char *jp = SvPV(ks[j].sv, jl);
1573 0 size_t m = jl < kl ? jl : kl;
1574 0 ▶ int c = m ? memcmp(jp, kp, m) : 0;
Branch: 1 branch
BranchTrueFalseTotal
int c = m ? memcmp(jp, kp, m) : 0; 0 0 0
1575 0 ▶ if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1);
Branch: 3 branches
BranchTrueFalseTotal
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
1576 0 ▶ if (c <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (c <= 0) break; 0 0 0
1577 0 ks[j + 1] = ks[j];
1578 }
1579 0 ks[j + 1] = k;
1580 }
1581 4 ▶ for (i = 0; i < nk; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nk; i++) { 2 2 4
1582 2 HV *pair = newHV();
1583 STRLEN kl;
1584 2 const char *kp = SvPV(ks[i].sv, kl);
1585 2 SV **val = hv_fetch(ah, kp, (I32)kl, 0);
1586 2 hv_stores(pair, "key", ks[i].sv);
1587 /* stringified, as the page prints it */
1588 4 ▶ hv_stores(pair, "value",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(pair, "value", 2 0 2
1589 val ? newSVpv(SvPV_nolen(*val), 0) : newSVpvs(""));
1590 2 av_push(out, newRV_noinc((SV *)pair));
1591 }
1592 2 Safefree(ks);
1593 }
1594 2 hv_stores(v, "attrs", newRV_noinc((SV *)out));
1595 }
1596  
1597 { /* The lines either side, which is the question anybody opening one
1598 * line asks next.
1599 *
1600 * CENTRED ON THE RECORD, NOT ON THE WINDOW'S EDGE. `rows` answers
1601 * newest first and `limit` keeps that end, so the capped call this
1602 * used to make kept the newest 40 of the ten seconds: on a busy
1603 * store that is everything AFTER the record and nothing before
1604 * it, with the record itself pushed off its own context. The scan
1605 * materialises the whole window before any limit trims it, so
1606 * asking for it all costs the same and the centring is a slice
1607 * here. */
1608 2 AV *ctx = newAV();
1609 2 SV **tsv = hv_fetchs(row, "t", 0);
1610 2 po_u64 t = 0;
1611 2 SV *near = NULL;
1612 int n;
1613  
1614 2 ▶ if (tsv) (void)po_sv_to_u64(aTHX_ *tsv, &t);
Branch: 1 branch
BranchTrueFalseTotal
if (tsv) (void)po_sv_to_u64(aTHX_ *tsv, &t); 2 0 2
1615 2 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 2 2
1616 2 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 2 2
1617 2 ▶ XPUSHs(sv_2mortal(newSVpvs("from")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); 0 2 2
1618 2 ▶ XPUSHs(sv_2mortal(po_u64_to_sv(po_ns_sub(t, 5000000000ULL))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(po_u64_to_sv(po_ns_sub(t, 5000000000ULL)))); 0 2 2
1619 2 ▶ XPUSHs(sv_2mortal(newSVpvs("to")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); 0 2 2
1620 2 ▶ XPUSHs(sv_2mortal(po_u64_to_sv(po_ns_add(t, 5000000000ULL))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(po_u64_to_sv(po_ns_add(t, 5000000000ULL)))); 0 2 2
1621 2 ▶ XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2))); 0 2 2
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2))); 0 2 2
1622 2 PUTBACK;
1623 2 n = call_method("rows", G_LIST);
1624 2 SPAGAIN;
1625 {
1626 SSize_t i;
1627 4 ▶ for (i = n - 1; i > 0; i--) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
for (i = n - 1; i > 0; i--) (void)POPs; 2 2 4
1628 2 ▶ near = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
near = n ? SvREFCNT_inc(POPs) : NULL; 2 0 2
1629 }
1630 2 PUTBACK;
1631 2 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 2 0 2
1632 2 SPAGAIN;
1633  
1634 2 ▶ if (near && SvROK(near) && SvTYPE(SvRV(near)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (near && SvROK(near) && SvTYPE(SvRV(near)) == SVt_PVAV) { 2 0 2
if (near && SvROK(near) && SvTYPE(SvRV(near)) == SVt_PVAV) { 2 0 2
if (near && SvROK(near) && SvTYPE(SvRV(near)) == SVt_PVAV) { 2 0 2
1635 2 AV *na = (AV *)SvRV(near);
1636 2 SSize_t i, cnt = av_len(na) + 1;
1637 2 SSize_t i0 = cnt, lo, hi;
1638  
1639 /* The record's own place in the descending order: the first
1640 * row at or before it. Everything above index i0 is after
1641 * the record, everything from it on is at-or-before. */
1642 62 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 62 0 62
1643 62 SV **e = av_fetch(na, i, 0);
1644 SV **x;
1645 62 po_u64 rt = 0;
1646 62 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 62 0 62
if (!e || !SvROK(*e)) continue; 0 62 62
1647 62 x = hv_fetchs((HV *)SvRV(*e), "t", 0);
1648 62 ▶ if (x && SvOK(*x)) (void)po_sv_to_u64(aTHX_ *x, &rt);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) (void)po_sv_to_u64(aTHX_ *x, &rt); 62 0 62
if (x && SvOK(*x)) (void)po_sv_to_u64(aTHX_ *x, &rt); 62 0 62
1649 62 ▶ if (rt <= t) { i0 = i; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (rt <= t) { i0 = i; break; } 2 60 62
1650 }
1651 /* Twenty either side, a contiguous slice of the sorted
1652 * window - so the page shows before, the line itself, and
1653 * after, whatever the traffic rate. */
1654 2 lo = i0 > 20 ? i0 - 20 : 0;
1655 2 hi = i0 + 21 < cnt ? i0 + 21 : cnt;
1656  
1657 45 ▶ for (i = lo; i < hi; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = lo; i < hi; i++) { 43 2 45
1658 43 SV **e = av_fetch(na, i, 0);
1659 HV *w, *o;
1660 SV **x;
1661 char b[64];
1662 size_t bn;
1663 43 const char *wp = "0";
1664 43 STRLEN wl = 1;
1665  
1666 43 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 43 0 43
if (!e || !SvROK(*e)) continue; 0 43 43
1667 43 w = (HV *)SvRV(*e);
1668 43 o = newHV();
1669 43 x = hv_fetchs(w, "t", 0);
1670 86 ▶ if (x && SvOK(*x)) wp = SvPV(*x, wl);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) wp = SvPV(*x, wl); 43 0 43
if (x && SvOK(*x)) wp = SvPV(*x, wl); 43 0 43
1671 43 bn = po_fmt_time(wp, (size_t)wl, b);
1672 43 hv_stores(o, "time", newSVpvn(b, bn));
1673 43 x = hv_fetchs(w, "severity", 0);
1674 43 ▶ hv_stores(o, "sev_name",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "sev_name", 43 0 43
hv_stores(o, "sev_name", 43 0 43
1675 newSVpv(po_severity_name(x && SvOK(*x)
1676 ? (int)SvIV(*x) : 0), 0));
1677 43 x = hv_fetchs(w, "service", 0);
1678 43 ▶ hv_stores(o, "service", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "service", x ? newSVsv(*x) : newSV(0)); 43 0 43
1679 43 x = hv_fetchs(w, "body", 0);
1680 43 ▶ hv_stores(o, "body", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "body", x ? newSVsv(*x) : newSV(0)); 43 0 43
1681 43 hv_stores(o, "id", povw_record_id_sv(aTHX_ *e));
1682 /* THE WHOLE ID, not the nanosecond: two lines in the
1683 * same ns both carried the highlight, and a context
1684 * with two "current" rows reads as a rendering fault. */
1685 43 hv_stores(o, "current",
1686 newSViv(povw_record_matches_c(aTHX_ *e, id)
1687 ? 1 : 0));
1688 43 av_push(ctx, newRV_noinc((SV *)o));
1689 }
1690 }
1691 2 ▶ if (near) SvREFCNT_dec(near);
Branch: 1 branch
BranchTrueFalseTotal
if (near) SvREFCNT_dec(near); 2 0 2
1692 2 hv_stores(v, "context", newRV_noinc((SV *)ctx));
1693 }
1694  
1695 4 done:
1696 4 ▶ if (rowref) SvREFCNT_dec(rowref);
Branch: 1 branch
BranchTrueFalseTotal
if (rowref) SvREFCNT_dec(rowref); 2 2 4
1697 4 RETVAL = newRV_noinc((SV *)v);
1698 }
1699 OUTPUT:
1700 RETVAL
1701  
1702 # The SVG lines for a row set, and the y axis they share.
1703 #
1704 # THE EXTENTS ARE THE BOX, because the axis is already chosen: letting each
1705 # series rescale would draw every one of them to its own top and bottom, and
1706 # the legend would be comparing different axes.
1707 SV *
1708 povw__series_paths(SV *rows_sv, SV *from, SV *to, SV *vars)
1709 CODE:
1710 {
1711 1 AV *out = newAV();
1712 1 povw_series *g = NULL;
1713 1 SSize_t ng = 0, i;
1714 1 double lo = 0, hi = 0;
1715 1 int seen = 0;
1716 po_axis ax;
1717 double alo, ahi;
1718 1 HV *v = NULL;
1719  
1720 1 ▶ if (SvROK(vars) && SvTYPE(SvRV(vars)) == SVt_PVHV) v = (HV *)SvRV(vars);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(vars) && SvTYPE(SvRV(vars)) == SVt_PVHV) v = (HV *)SvRV(vars); 1 0 1
if (SvROK(vars) && SvTYPE(SvRV(vars)) == SVt_PVHV) v = (HV *)SvRV(vars); 1 0 1
1721 1 ▶ if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV) 1 0 1
if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV) 1 0 1
1722 1 ng = povw_series_split(aTHX_ (AV *)SvRV(rows_sv), &g);
1723 1 ▶ if (!ng) { if (g) povw_series_free(aTHX_ g, ng); goto done; }
Branch: 2 branches
BranchTrueFalseTotal
if (!ng) { if (g) povw_series_free(aTHX_ g, ng); goto done; } 0 1 1
if (!ng) { if (g) povw_series_free(aTHX_ g, ng); goto done; } 0 0 0
1724  
1725 2 ▶ for (i = 0; i < ng; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ng; i++) { 1 1 2
1726 1 SSize_t j, cnt = av_len(g[i].pts) + 1;
1727 31 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 30 1 31
1728 30 SV **e = av_fetch(g[i].pts, j, 0);
1729 30 ▶ SV **val = e ? hv_fetchs((HV *)SvRV(*e), "value", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **val = e ? hv_fetchs((HV *)SvRV(*e), "value", 0) : NULL; 30 0 30
1730 30 ▶ double d = val ? (double)SvNV(*val) : 0;
Branch: 1 branch
BranchTrueFalseTotal
double d = val ? (double)SvNV(*val) : 0; 30 0 30
1731 30 ▶ if (!seen) { lo = hi = d; seen = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (!seen) { lo = hi = d; seen = 1; } 1 29 30
1732 29 ▶ else { if (d < lo) lo = d; if (d > hi) hi = d; }
Branch: 2 branches
BranchTrueFalseTotal
else { if (d < lo) lo = d; if (d > hi) hi = d; } 0 29 29
else { if (d < lo) lo = d; if (d > hi) hi = d; } 29 0 29
1733 }
1734 }
1735 1 ▶ if (!seen || hi == lo) hi = lo + 1;
Branch: 2 branches
BranchTrueFalseTotal
if (!seen || hi == lo) hi = lo + 1; 1 0 1
if (!seen || hi == lo) hi = lo + 1; 0 1 1
1736  
1737 1 po_axis_make(&ax, lo, hi, 4);
1738 1 alo = ax.lo; ahi = ax.hi;
1739 1 ▶ if (ahi == alo) ahi = alo + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (ahi == alo) ahi = alo + 1; 0 1 1
1740  
1741 1 ▶ if (v) {
Branch: 1 branch
BranchTrueFalseTotal
if (v) { 1 0 1
1742 1 AV *ticks = newAV();
1743 int k;
1744 4 ▶ for (k = 0; k < ax.n; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < ax.n; k++) { 3 1 4
1745 3 HV *t = newHV();
1746 3 double y = POVW_CHART_H
1747 3 - POVW_CHART_H * (ax.tick[k] - alo) / (ahi - alo);
1748 3 hv_stores(t, "y", povw_fixed(aTHX_ y, 1));
1749 3 hv_stores(t, "label_y", povw_fixed(aTHX_ y - 3, 1));
1750 3 hv_stores(t, "label", newSVnv((NV)ax.tick[k]));
1751 3 av_push(ticks, newRV_noinc((SV *)t));
1752 }
1753 1 (void)hv_stores(v, "yticks", newRV_noinc((SV *)ticks));
1754 }
1755  
1756 {
1757 1 po_u64 t0 = 0, t1 = 0;
1758 1 (void)po_sv_to_u64(aTHX_ from, &t0);
1759 1 (void)po_sv_to_u64(aTHX_ to, &t1);
1760  
1761 2 ▶ for (i = 0; i < ng; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ng; i++) { 1 1 2
1762 1 SSize_t j, cnt = av_len(g[i].pts) + 1;
1763 1 HV *s = newHV();
1764 1 AV *ex = newAV();
1765 double *xs, *ys;
1766 char cls[16];
1767  
1768 1 ▶ Newx(xs, cnt ? cnt : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newx(xs, cnt ? cnt : 1, double); 1 0 1
Newx(xs, cnt ? cnt : 1, double); 0 1 1
Newx(xs, cnt ? cnt : 1, double); 1 0 1
1769 1 ▶ Newx(ys, cnt ? cnt : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newx(ys, cnt ? cnt : 1, double); 1 0 1
Newx(ys, cnt ? cnt : 1, double); 0 1 1
Newx(ys, cnt ? cnt : 1, double); 1 0 1
1770 31 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 30 1 31
1771 30 SV **e = av_fetch(g[i].pts, j, 0);
1772 30 HV *row = (HV *)SvRV(*e);
1773 30 SV **val = hv_fetchs(row, "value", 0);
1774 30 SV **tsv = hv_fetchs(row, "t", 0);
1775 30 po_u64 t = 0;
1776 30 ▶ double d = val ? (double)SvNV(*val) : 0;
Branch: 1 branch
BranchTrueFalseTotal
double d = val ? (double)SvNV(*val) : 0; 30 0 30
1777  
1778 30 ▶ if (tsv) (void)po_sv_to_u64(aTHX_ *tsv, &t);
Branch: 1 branch
BranchTrueFalseTotal
if (tsv) (void)po_sv_to_u64(aTHX_ *tsv, &t); 30 0 30
1779 /* The projection is integer subtraction then one
1780 * division, in C. */
1781 30 xs[j] = po_chart_x(t, t0, t1, POVW_CHART_W);
1782 30 ys[j] = POVW_CHART_H
1783 30 - POVW_CHART_H * (d - alo) / (ahi - alo);
1784  
1785 30 ▶ if (povw_row_has_trace(aTHX_ *e)) {
Branch: 1 branch
BranchTrueFalseTotal
if (povw_row_has_trace(aTHX_ *e)) { 0 30 30
1786 0 HV *x = newHV();
1787 0 SV **thi = hv_fetchs(row, "trace_hi", 0);
1788 0 SV **tlo = hv_fetchs(row, "trace_lo", 0);
1789 0 ▶ hv_stores(x, "trace",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(x, "trace", 0 0 0
hv_stores(x, "trace", 0 0 0
1790 povw_trace_hex_sv(aTHX_
1791 thi ? *thi : &PL_sv_no,
1792 tlo ? *tlo : &PL_sv_no));
1793 0 hv_stores(x, "x", povw_fixed(aTHX_ xs[j], 1));
1794 0 hv_stores(x, "y",
1795 povw_fixed(aTHX_
1796 po_chart_y(d, alo, ahi, POVW_CHART_H), 1));
1797 0 av_push(ex, newRV_noinc((SV *)x));
1798 }
1799 }
1800  
1801 1 hv_stores(s, "name", newSVsv(g[i].name));
1802 {
1803 2 size_t cn = (size_t)my_snprintf(cls, sizeof(cls),
1804 1 "series-%d", (int)(i % 8));
1805 1 hv_stores(s, "class", newSVpvn(cls, cn));
1806 }
1807 1 hv_stores(s, "path", povw_path_sv(aTHX_ xs, ys, (size_t)cnt));
1808 1 hv_stores(s, "points", newSViv((IV)cnt));
1809 1 hv_stores(s, "exemplars", newRV_noinc((SV *)ex));
1810 1 av_push(out, newRV_noinc((SV *)s));
1811 1 Safefree(xs); Safefree(ys);
1812 }
1813 }
1814 1 povw_series_free(aTHX_ g, ng);
1815  
1816 1 done:
1817 1 RETVAL = newRV_noinc((SV *)out);
1818 }
1819 OUTPUT:
1820 RETVAL
1821  
1822 # The same rows as a plotly figure, for the screens that draw client side.
1823 #
1824 # COLOUR IS NAMED BY ROLE, never by value: "series:2" is resolved against the
1825 # stylesheet's custom properties in the browser, at draw time. A figure
1826 # carrying a hex would be a figure that is wrong in one of the two themes, and
1827 # the server has no idea which theme the reader is in.
1828 SV *
1829 povw__rows_as_series(SV *rows_sv, SV *req)
1830 CODE:
1831 {
1832 9 HV *v = newHV();
1833 9 AV *legend = newAV();
1834 9 AV *data = newAV();
1835 9 povw_series *g = NULL;
1836 9 SSize_t ng = 0, i;
1837  
1838 PERL_UNUSED_VAR(req);
1839 9 ▶ if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV) 9 0 9
if (SvROK(rows_sv) && SvTYPE(SvRV(rows_sv)) == SVt_PVAV) 9 0 9
1840 9 ng = povw_series_split(aTHX_ (AV *)SvRV(rows_sv), &g);
1841  
1842 9 ▶ if (!ng) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ng) { 0 9 9
1843 0 ▶ if (g) povw_series_free(aTHX_ g, ng);
Branch: 1 branch
BranchTrueFalseTotal
if (g) povw_series_free(aTHX_ g, ng); 0 0 0
1844 0 SvREFCNT_dec((SV *)data);
1845 0 hv_stores(v, "legend", newRV_noinc((SV *)legend));
1846 0 goto done;
1847 }
1848  
1849 18 ▶ for (i = 0; i < ng; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ng; i++) { 9 9 18
1850 9 SSize_t j, cnt = av_len(g[i].pts) + 1, nex = 0;
1851 9 HV *line = newHV(), *lstyle = newHV(), *leg = newHV();
1852 9 AV *lx = newAV(), *ly = newAV();
1853 9 AV *ex_x = newAV(), *ex_y = newAV(), *ex_c = newAV();
1854 char role[16];
1855 18 size_t rn = (size_t)my_snprintf(role, sizeof(role),
1856 9 "series:%d", (int)(i % 8));
1857 /* THE LINE IS DECIMATED; THE EXEMPLARS ARE NOT.
1858 *
1859 * There are a handful of exemplars and each one is a link to a
1860 * trace, so dropping one removes a way into the data. There are
1861 * six figures of line points and the chart is 720 pixels wide. */
1862 9 SSize_t *keep = NULL, nkeep = 0, kc = 0;
1863  
1864 9 ▶ if (cnt > POVW_PLOT_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (cnt > POVW_PLOT_MAX) { 5 4 9
1865 5 Newx(keep, POVW_PLOT_MAX + 2, SSize_t);
1866 5 nkeep = povw_decimate(aTHX_ g[i].pts, cnt, keep);
1867 }
1868  
1869 70115 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 70106 9 70115
1870 70106 SV **e = av_fetch(g[i].pts, j, 0);
1871 70106 HV *row = (HV *)SvRV(*e);
1872 70106 SV **val = hv_fetchs(row, "value", 0);
1873 70106 SV **tsv = hv_fetchs(row, "t", 0);
1874 70106 int take = 1;
1875  
1876 70106 ▶ if (keep) {
Branch: 1 branch
BranchTrueFalseTotal
if (keep) { 70000 106 70106
1877 70000 ▶ take = (kc < nkeep && keep[kc] == j);
Branch: 2 branches
BranchTrueFalseTotal
take = (kc < nkeep && keep[kc] == j); 70000 0 70000
take = (kc < nkeep && keep[kc] == j); 8004 61996 70000
1878 70000 ▶ if (take) kc++;
Branch: 1 branch
BranchTrueFalseTotal
if (take) kc++; 8004 61996 70000
1879 }
1880 70106 ▶ if (take) {
Branch: 1 branch
BranchTrueFalseTotal
if (take) { 8110 61996 70106
1881 8110 ▶ av_push(lx, povw_plot_ms(aTHX_ tsv ? *tsv : NULL));
Branch: 1 branch
BranchTrueFalseTotal
av_push(lx, povw_plot_ms(aTHX_ tsv ? *tsv : NULL)); 8110 0 8110
1882 8110 ▶ av_push(ly, povw_num(aTHX_ val ? *val : NULL));
Branch: 1 branch
BranchTrueFalseTotal
av_push(ly, povw_num(aTHX_ val ? *val : NULL)); 8110 0 8110
1883 }
1884  
1885 70106 ▶ if (povw_row_has_trace(aTHX_ *e)) {
Branch: 1 branch
BranchTrueFalseTotal
if (povw_row_has_trace(aTHX_ *e)) { 12 70094 70106
1886 12 SV **thi = hv_fetchs(row, "trace_hi", 0);
1887 12 SV **tlo = hv_fetchs(row, "trace_lo", 0);
1888 12 SV *cd = newSVpvs("");
1889 12 ▶ if (thi && SvOK(*thi)) sv_catsv(cd, *thi);
Branch: 2 branches
BranchTrueFalseTotal
if (thi && SvOK(*thi)) sv_catsv(cd, *thi); 12 0 12
if (thi && SvOK(*thi)) sv_catsv(cd, *thi); 12 0 12
1890 12 sv_catpvs(cd, "-");
1891 12 ▶ if (tlo && SvOK(*tlo)) sv_catsv(cd, *tlo);
Branch: 2 branches
BranchTrueFalseTotal
if (tlo && SvOK(*tlo)) sv_catsv(cd, *tlo); 12 0 12
if (tlo && SvOK(*tlo)) sv_catsv(cd, *tlo); 12 0 12
1892 12 ▶ av_push(ex_x, povw_plot_ms(aTHX_ tsv ? *tsv : NULL));
Branch: 1 branch
BranchTrueFalseTotal
av_push(ex_x, povw_plot_ms(aTHX_ tsv ? *tsv : NULL)); 12 0 12
1893 12 ▶ av_push(ex_y, povw_num(aTHX_ val ? *val : NULL));
Branch: 1 branch
BranchTrueFalseTotal
av_push(ex_y, povw_num(aTHX_ val ? *val : NULL)); 12 0 12
1894 12 av_push(ex_c, cd);
1895 12 nex++;
1896 }
1897 }
1898  
1899 9 ▶ if (keep) Safefree(keep);
Branch: 1 branch
BranchTrueFalseTotal
if (keep) Safefree(keep); 5 4 9
1900  
1901 9 hv_stores(lstyle, "color", newSVpvn(role, rn));
1902 9 hv_stores(lstyle, "width", newSViv(2));
1903 9 hv_stores(line, "type", newSVpvs("scatter"));
1904 9 hv_stores(line, "mode", newSVpvs("lines"));
1905 9 hv_stores(line, "name", newSVsv(g[i].name));
1906 9 hv_stores(line, "x", newRV_noinc((SV *)lx));
1907 9 hv_stores(line, "y", newRV_noinc((SV *)ly));
1908 9 hv_stores(line, "line", newRV_noinc((SV *)lstyle));
1909 9 av_push(data, newRV_noinc((SV *)line));
1910  
1911 9 ▶ if (nex) {
Branch: 1 branch
BranchTrueFalseTotal
if (nex) { 2 7 9
1912 2 HV *m = newHV(), *mstyle = newHV(), *mline = newHV();
1913 2 SV *nm = newSVsv(g[i].name);
1914 2 sv_catpvs(nm, " exemplars");
1915 2 hv_stores(mline, "width", newSViv(2));
1916 2 hv_stores(mstyle, "color", newSVpvn(role, rn));
1917 2 hv_stores(mstyle, "size", newSViv(9));
1918 2 hv_stores(mstyle, "symbol", newSVpvs("circle-open"));
1919 2 hv_stores(mstyle, "line", newRV_noinc((SV *)mline));
1920 2 hv_stores(m, "type", newSVpvs("scatter"));
1921 2 hv_stores(m, "mode", newSVpvs("markers"));
1922 2 hv_stores(m, "name", nm);
1923 /* The exemplar markers ride the series' own legend entry;
1924 * a second one for them would double the list. */
1925 2 hv_stores(m, "showlegend", newRV_noinc(newSViv(0)));
1926 2 hv_stores(m, "x", newRV_noinc((SV *)ex_x));
1927 2 hv_stores(m, "y", newRV_noinc((SV *)ex_y));
1928 2 hv_stores(m, "customdata", newRV_noinc((SV *)ex_c));
1929 2 hv_stores(m, "marker", newRV_noinc((SV *)mstyle));
1930 2 hv_stores(m, "hovertemplate",
1931 newSVpvs("trace %{customdata}<extra></extra>"));
1932 2 av_push(data, newRV_noinc((SV *)m));
1933 }
1934 else {
1935 7 SvREFCNT_dec((SV *)ex_x);
1936 7 SvREFCNT_dec((SV *)ex_y);
1937 7 SvREFCNT_dec((SV *)ex_c);
1938 }
1939  
1940 {
1941 char cls[16];
1942 18 size_t cn = (size_t)my_snprintf(cls, sizeof(cls),
1943 9 "series-%d", (int)(i % 8));
1944 9 hv_stores(leg, "name", newSVsv(g[i].name));
1945 9 hv_stores(leg, "class", newSVpvn(cls, cn));
1946 9 hv_stores(leg, "points", newSViv((IV)cnt));
1947 9 hv_stores(leg, "exemplars", newSViv((IV)nex));
1948 }
1949 9 av_push(legend, newRV_noinc((SV *)leg));
1950 }
1951 9 povw_series_free(aTHX_ g, ng);
1952  
1953 {
1954 9 HV *fig = newHV(), *layout = newHV(), *xaxis = newHV(), *yaxis = newHV();
1955 9 hv_stores(xaxis, "type", newSVpvs("date"));
1956 9 hv_stores(yaxis, "rangemode", newSVpvs("tozero"));
1957 9 hv_stores(layout, "hovermode", newSVpvs("x unified"));
1958 9 hv_stores(layout, "xaxis", newRV_noinc((SV *)xaxis));
1959 9 hv_stores(layout, "yaxis", newRV_noinc((SV *)yaxis));
1960 /* One series needs no legend: the heading already names it, and
1961 * a legend of one is a box that says the same word twice. */
1962 9 hv_stores(layout, "showlegend",
1963 newRV_noinc(newSViv(av_len(legend) > 0 ? 1 : 0)));
1964 9 hv_stores(fig, "data", newRV_noinc((SV *)data));
1965 9 hv_stores(fig, "layout", newRV_noinc((SV *)layout));
1966 9 hv_stores(v, "legend", newRV_noinc((SV *)legend));
1967 9 hv_stores(v, "figure", newRV_noinc((SV *)fig));
1968 }
1969  
1970 9 done:
1971 9 RETVAL = newRV_noinc((SV *)v);
1972 }
1973 OUTPUT:
1974 RETVAL
1975  
1976 # Frames into rects.
1977 #
1978 # THE X POSITION IS THE ONE THING THE TREE DOES NOT CARRY. Frames arrive in
1979 # tree order with a parent index and a total, so each frame starts where its
1980 # parent's cursor has got to, and the parent's cursor advances by what this
1981 # frame took. Every frame is visited once and the whole layout falls out.
1982 SV *
1983 povw__flame_rows(SV *f_sv, SV *names_sv, SV *services_sv)
1984 CODE:
1985 {
1986 5 AV *out = newAV();
1987 5 AV *frames = NULL, *names = NULL, *services = NULL;
1988 5 SSize_t n = 0, i;
1989 5 po_u64 root_total = 0, root_cursor = 0;
1990 5 po_u64 *start = NULL, *cursor = NULL;
1991 5 char *seen = NULL;
1992 5 SV **path = NULL;
1993  
1994 5 ▶ if (SvROK(f_sv) && SvTYPE(SvRV(f_sv)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(f_sv) && SvTYPE(SvRV(f_sv)) == SVt_PVHV) { 5 0 5
if (SvROK(f_sv) && SvTYPE(SvRV(f_sv)) == SVt_PVHV) { 5 0 5
1995 5 SV **fr = hv_fetchs((HV *)SvRV(f_sv), "frames", 0);
1996 5 ▶ if (fr && SvROK(*fr) && SvTYPE(SvRV(*fr)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (fr && SvROK(*fr) && SvTYPE(SvRV(*fr)) == SVt_PVAV) 5 0 5
if (fr && SvROK(*fr) && SvTYPE(SvRV(*fr)) == SVt_PVAV) 5 0 5
if (fr && SvROK(*fr) && SvTYPE(SvRV(*fr)) == SVt_PVAV) 5 0 5
1997 5 frames = (AV *)SvRV(*fr);
1998 }
1999 5 ▶ if (SvROK(names_sv) && SvTYPE(SvRV(names_sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(names_sv) && SvTYPE(SvRV(names_sv)) == SVt_PVAV) 5 0 5
if (SvROK(names_sv) && SvTYPE(SvRV(names_sv)) == SVt_PVAV) 5 0 5
2000 5 names = (AV *)SvRV(names_sv);
2001 5 ▶ if (SvROK(services_sv) && SvTYPE(SvRV(services_sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(services_sv) && SvTYPE(SvRV(services_sv)) == SVt_PVAV) 5 0 5
if (SvROK(services_sv) && SvTYPE(SvRV(services_sv)) == SVt_PVAV) 5 0 5
2002 5 services = (AV *)SvRV(services_sv);
2003  
2004 5 ▶ n = frames ? av_len(frames) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
n = frames ? av_len(frames) + 1 : 0; 5 0 5
2005 5 ▶ if (!n) goto done;
Branch: 1 branch
BranchTrueFalseTotal
if (!n) goto done; 0 5 5
2006 #define POVW_FR(ix) ((SV **)av_fetch(frames, (ix), 0))
2007 #define POVW_FH(ix) ((HV *)SvRV(*POVW_FR(ix)))
2008  
2009 { /* The roots' total is the width of the whole picture. */
2010 15 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 10 5 15
2011 10 SV **e = POVW_FR(i);
2012 SV **p, **t;
2013 IV par;
2014 10 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 10 0 10
if (!e || !SvROK(*e)) continue; 0 10 10
2015 10 p = hv_fetchs((HV *)SvRV(*e), "parent", 0);
2016 10 ▶ par = (p && SvOK(*p)) ? SvIV(*p) : -1;
Branch: 2 branches
BranchTrueFalseTotal
par = (p && SvOK(*p)) ? SvIV(*p) : -1; 10 0 10
par = (p && SvOK(*p)) ? SvIV(*p) : -1; 10 0 10
2017 10 ▶ if (par >= 0) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (par >= 0) continue; 5 5 10
2018 5 t = hv_fetchs((HV *)SvRV(*e), "total", 0);
2019 5 ▶ root_total += (t && SvOK(*t)) ? (po_u64)SvUV(*t) : 0;
Branch: 2 branches
BranchTrueFalseTotal
root_total += (t && SvOK(*t)) ? (po_u64)SvUV(*t) : 0; 5 0 5
root_total += (t && SvOK(*t)) ? (po_u64)SvUV(*t) : 0; 5 0 5
2020 }
2021 }
2022 5 ▶ if (!root_total) goto done;
Branch: 1 branch
BranchTrueFalseTotal
if (!root_total) goto done; 0 5 5
2023  
2024 5 ▶ Newxz(start, n, po_u64);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(start, n, po_u64); 0 5 5
2025 5 ▶ Newxz(cursor, n, po_u64);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(cursor, n, po_u64); 0 5 5
2026 5 Newxz(seen, n, char); /* has this frame's cursor been set? */
2027 5 ▶ Newxz(path, n, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(path, n, SV *); 0 5 5
2028  
2029 15 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 10 5 15
2030 10 SV **e = POVW_FR(i);
2031 HV *fr;
2032 SV **x;
2033 IV par;
2034 po_u64 total, self, count;
2035 10 SV *name = NULL;
2036 10 const char *np = "(unnamed)";
2037 10 STRLEN nlen = 9;
2038 10 int name_utf8 = 0;
2039 double wpct;
2040 IV budget, depth;
2041 HV *o;
2042  
2043 10 ▶ if (!e || !SvROK(*e)) { path[i] = newSVpvs(""); continue; }
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) { path[i] = newSVpvs(""); continue; } 10 0 10
if (!e || !SvROK(*e)) { path[i] = newSVpvs(""); continue; } 0 10 10
2044 10 fr = (HV *)SvRV(*e);
2045  
2046 10 x = hv_fetchs(fr, "parent", 0);
2047 10 ▶ par = (x && SvOK(*x)) ? SvIV(*x) : -1;
Branch: 2 branches
BranchTrueFalseTotal
par = (x && SvOK(*x)) ? SvIV(*x) : -1; 10 0 10
par = (x && SvOK(*x)) ? SvIV(*x) : -1; 10 0 10
2048 10 x = hv_fetchs(fr, "total", 0);
2049 10 ▶ total = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
total = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0; 10 0 10
total = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0; 10 0 10
2050  
2051 10 ▶ if (par < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (par < 0) { 5 5 10
2052 5 start[i] = root_cursor;
2053 5 root_cursor += total;
2054 5 path[i] = newSViv((IV)i);
2055 }
2056 else {
2057 /* `||`, not a defined check: a cursor sitting at zero has not
2058 * moved, so the frame starts where its parent starts. */
2059 5 po_u64 s = 0;
2060 5 SV *pp = NULL;
2061 5 ▶ if (par < n) {
Branch: 1 branch
BranchTrueFalseTotal
if (par < n) { 5 0 5
2062 5 ▶ s = cursor[par] ? cursor[par] : start[par];
Branch: 1 branch
BranchTrueFalseTotal
s = cursor[par] ? cursor[par] : start[par]; 0 5 5
2063 5 pp = path[par];
2064 }
2065 5 start[i] = s;
2066 5 ▶ if (par < n) cursor[par] = start[i] + total;
Branch: 1 branch
BranchTrueFalseTotal
if (par < n) cursor[par] = start[i] + total; 5 0 5
2067 5 ▶ path[i] = pp ? newSVsv(pp) : newSVpvs("");
Branch: 1 branch
BranchTrueFalseTotal
path[i] = pp ? newSVsv(pp) : newSVpvs(""); 5 0 5
2068 5 sv_catpvs(path[i], "/");
2069 5 sv_catpvf(path[i], PO_IVf, (IV)i);
2070 }
2071 10 ▶ if (!seen[i]) { cursor[i] = start[i]; seen[i] = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (!seen[i]) { cursor[i] = start[i]; seen[i] = 1; } 10 0 10
2072  
2073 10 x = hv_fetchs(fr, "name", 0);
2074 10 ▶ if (names && x && SvOK(*x)) {
Branch: 3 branches
BranchTrueFalseTotal
if (names && x && SvOK(*x)) { 10 0 10
if (names && x && SvOK(*x)) { 10 0 10
if (names && x && SvOK(*x)) { 10 0 10
2075 10 SV **nm = av_fetch(names, SvIV(*x), 0);
2076 10 ▶ if (nm && SvOK(*nm) && SvCUR(*nm)) {
Branch: 3 branches
BranchTrueFalseTotal
if (nm && SvOK(*nm) && SvCUR(*nm)) { 10 0 10
if (nm && SvOK(*nm) && SvCUR(*nm)) { 10 0 10
if (nm && SvOK(*nm) && SvCUR(*nm)) { 10 0 10
2077 10 name = *nm;
2078 10 np = SvPV(name, nlen);
2079 10 name_utf8 = SvUTF8(name) ? 1 : 0;
2080 }
2081 }
2082  
2083 10 wpct = 100.0 * (double)total / (double)root_total;
2084  
2085 /* THE LABEL IS TRUNCATED HERE, not clipped by the browser. An SVG
2086 * text element neither wraps nor ellipsises; left whole it runs
2087 * straight across the frames beside it, and a flamegraph with
2088 * every name overlapping every other name is less readable than
2089 * one with no names at all. Roughly one character per 0.62% of
2090 * the width, and nothing at all below the width of an ellipsis. */
2091 10 budget = (IV)(wpct / 0.62);
2092  
2093 10 o = newHV();
2094 10 ▶ hv_stores(o, "name", name ? newSVsv(name) : newSVpvn(np, nlen));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "name", name ? newSVsv(name) : newSVpvn(np, nlen)); 10 0 10
2095  
2096 10 ▶ if (budget < 4) hv_stores(o, "label", newSVpvs(""));
Branch: 1 branch
BranchTrueFalseTotal
if (budget < 4) hv_stores(o, "label", newSVpvs("")); 0 10 10
2097 else {
2098 10 ▶ IV clen = name_utf8 ? (IV)sv_len_utf8(name) : (IV)nlen;
Branch: 1 branch
BranchTrueFalseTotal
IV clen = name_utf8 ? (IV)sv_len_utf8(name) : (IV)nlen; 0 10 10
2099 10 ▶ if (clen <= budget)
Branch: 1 branch
BranchTrueFalseTotal
if (clen <= budget) 10 0 10
2100 10 ▶ hv_stores(o, "label",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "label", 10 0 10
2101 name ? newSVsv(name) : newSVpvn(np, nlen));
2102 else {
2103 STRLEN keep;
2104 SV *lab;
2105 0 ▶ if (name_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (name_utf8) { 0 0 0
2106 0 const U8 *s = (const U8 *)np;
2107 0 const U8 *e2 = s + nlen;
2108 0 IV k = budget - 1;
2109 0 ▶ while (k-- > 0 && s < e2) s += UTF8SKIP(s);
Branch: 2 branches
BranchTrueFalseTotal
while (k-- > 0 && s < e2) s += UTF8SKIP(s); 0 0 0
while (k-- > 0 && s < e2) s += UTF8SKIP(s); 0 0 0
2110 0 keep = (STRLEN)((const char *)s - np);
2111 }
2112 0 else keep = (STRLEN)(budget - 1);
2113 0 lab = newSVpvn(np, keep);
2114 0 ▶ if (name_utf8) SvUTF8_on(lab);
Branch: 1 branch
BranchTrueFalseTotal
if (name_utf8) SvUTF8_on(lab); 0 0 0
2115 /* The ellipsis is one CHARACTER, so the result is a
2116 * character string whatever the name was. */
2117 0 sv_utf8_upgrade(lab);
2118 0 sv_catpvn(lab, "\342\200\246", 3);
2119 0 hv_stores(o, "label", lab);
2120 }
2121 }
2122  
2123 10 x = hv_fetchs(fr, "service", 0);
2124 20 ▶ if (services && x && SvOK(*x)) {
Branch: 3 branches
BranchTrueFalseTotal
if (services && x && SvOK(*x)) { 10 0 10
if (services && x && SvOK(*x)) { 10 0 10
if (services && x && SvOK(*x)) { 10 0 10
2125 10 SV **sv = av_fetch(services, SvIV(*x), 0);
2126 10 ▶ hv_stores(o, "service",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "service", 10 0 10
hv_stores(o, "service", 10 0 10
2127 (sv && SvOK(*sv)) ? newSVsv(*sv) : newSVpvs(""));
2128 }
2129 0 else hv_stores(o, "service", newSVpvs(""));
2130  
2131 10 x = hv_fetchs(fr, "depth", 0);
2132 10 ▶ depth = (x && SvOK(*x)) ? SvIV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
depth = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
depth = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
2133 10 ▶ hv_stores(o, "depth", (x && SvOK(*x)) ? newSVsv(*x) : newSV(0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "depth", (x && SvOK(*x)) ? newSVsv(*x) : newSV(0)); 10 0 10
hv_stores(o, "depth", (x && SvOK(*x)) ? newSVsv(*x) : newSV(0)); 10 0 10
2134 10 hv_stores(o, "y", newSViv(depth * 18));
2135 /* The baseline sits in the middle of the 16px band. */
2136 10 hv_stores(o, "text_y", newSViv(depth * 18 + 8));
2137  
2138 10 x = hv_fetchs(fr, "self", 0);
2139 10 ▶ self = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
self = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0; 10 0 10
self = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 0; 10 0 10
2140 10 x = hv_fetchs(fr, "count", 0);
2141 10 ▶ count = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 1;
Branch: 2 branches
BranchTrueFalseTotal
count = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 1; 10 0 10
count = (x && SvTRUE(*x)) ? (po_u64)SvUV(*x) : 1; 10 0 10
2142  
2143 10 hv_stores(o, "total", po_u64_to_sv(total));
2144 10 hv_stores(o, "self", po_u64_to_sv(self));
2145 10 hv_stores(o, "count", po_u64_to_sv(count));
2146 10 hv_stores(o, "start", po_u64_to_sv(start[i]));
2147 10 hv_stores(o, "path", SvREFCNT_inc(path[i]));
2148  
2149 {
2150 char b[64];
2151 10 size_t bn = po_fmt_dur(self, b);
2152 10 hv_stores(o, "self_ms", newSVpvn(b, bn));
2153 10 bn = po_fmt_dur(total, b);
2154 10 hv_stores(o, "total_ms", newSVpvn(b, bn));
2155 }
2156  
2157 10 hv_stores(o, "x", povw_fixed(aTHX_
2158 100.0 * (double)start[i] / (double)root_total, 4));
2159 /* A frame narrower than this is invisible; drawn at its real
2160 * width it is a rect nobody can click. */
2161 10 ▶ hv_stores(o, "width", povw_fixed(aTHX_
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "width", povw_fixed(aTHX_ 10 0 10
2162 wpct > 0.05 ? wpct : 0.05, 4));
2163 10 av_push(out, newRV_noinc((SV *)o));
2164 }
2165  
2166 15 ▶ for (i = 0; i < n; i++) if (path[i]) SvREFCNT_dec(path[i]);
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n; i++) if (path[i]) SvREFCNT_dec(path[i]); 10 0 10
for (i = 0; i < n; i++) if (path[i]) SvREFCNT_dec(path[i]); 10 5 15
2167 5 Safefree(start); Safefree(cursor); Safefree(seen); Safefree(path);
2168 #undef POVW_FR
2169 #undef POVW_FH
2170  
2171 5 done:
2172 5 RETVAL = newRV_noinc((SV *)out);
2173 }
2174 OUTPUT:
2175 RETVAL
2176  
2177 # One box over every signal.
2178 SV *
2179 povw__page_explore(SV *class, SV *store, SV *req)
2180 CODE:
2181 {
2182 16 HV *v = newHV();
2183 16 HV *rq = NULL;
2184 SV **f;
2185 16 SV *from = NULL, *to = NULL, *res = NULL;
2186 16 HV *r = NULL;
2187 16 const char *q = "";
2188 16 STRLEN ql = 0;
2189 16 int has_q = 0;
2190 SSize_t i;
2191 /* THESE ARE THE PAGE when there is nothing else on it, so they are
2192 * the language's shop window rather than a hint under the box.
2193 *
2194 * The first five covered `where`, `search`, `slowest`, `by`+`count`
2195 * and `p95 by`, and demonstrated none of `bucket`, `rate`, `sort`,
2196 * `limit`, `distinct`, the `{...}` selector, `and`/`or`, `=~` - or
2197 * the cross-signal pipeline, which is the one thing this backend does
2198 * that a stack of separate tools cannot, and which the overview calls
2199 * the differentiator of the whole project.
2200 *
2201 * Every one of them is parsed by t/0915-discovery.t, so an example
2202 * that stopped being valid is a failing build rather than something
2203 * teaching the wrong thing from the front page. */
2204 /* EVERY ONE OF THESE ANSWERS ON THE DEMO STORE. The first set was
2205 * written against an imagined store: it named http.server.duration,
2206 * which the SDK never emits (the semconv name is
2207 * http.server.request.duration), asked a histogram metric for | p95,
2208 * which has no raw points to take a percentile of, and led with the
2209 * cross-signal pipeline, which is refused until it is executed.
2210 * An example that returns nothing teaches that the tool is broken. */
2211 static const char *const EX[] = {
2212 "log | where severity >= error", "every error in the window",
2213 "log | bucket(5m) count by severity",
2214 "log volume over time, by severity",
2215 "log | search \"refused\"", "a substring, using the block filter",
2216 "log | where body =~ \"^connect\"",
2217 "an anchored prefix; =~ is not a full regex engine",
2218 "trace | slowest 20", "the slowest traces",
2219 "spans | where duration > 500ms and status == 2 | by service | count",
2220 "failures that were also slow, per service",
2221 "spans{service = \"shop\"} | bucket(30s) p95 | viz area",
2222 "the selector, p95 of duration, and a chart",
2223 "spans | by service | count | top 5 by count",
2224 "the busiest five",
2225 "metric http.server.request.count | rate(1m) by http.route",
2226 "a per-second rate per route",
2227 "log | sort t desc | limit 100", "the hundred most recent",
2228 "log | by severity | count | viz bar",
2229 "one bar per group, drawn how you asked",
2230 "spans | by http.route | distinct",
2231 "how many distinct routes there are"
2232 };
2233  
2234 PERL_UNUSED_VAR(class);
2235 16 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 16 0 16
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 16 0 16
2236  
2237 16 hv_stores(v, "heading", newSVpvs("Explore"));
2238 16 hv_stores(v, "title", newSVpvs("Explore"));
2239 16 hv_stores(v, "rows", newRV_noinc((SV *)newAV()));
2240 16 hv_stores(v, "groups", newRV_noinc((SV *)newAV()));
2241 16 hv_stores(v, "columns", newRV_noinc((SV *)newAV()));
2242  
2243 16 ▶ if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) {
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 16 0 16
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 11 5 16
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 11 0 11
2244 11 q = SvPV(*f, ql);
2245 11 hv_stores(v, "query", newSVsv(*f));
2246 }
2247 5 else hv_stores(v, "query", newSVpvs(""));
2248 {
2249 char *esc;
2250 size_t en;
2251 16 Newx(esc, ql * 3 + 1, char);
2252 16 en = po_url_esc(q, (size_t)ql, esc, ql * 3 + 1);
2253 16 hv_stores(v, "query_esc", newSVpvn(esc, en));
2254 16 Safefree(esc);
2255 }
2256  
2257 { /* The examples are the page when there is nothing else on it, so
2258 * they are not a hint under the box - they are what it shows. */
2259 16 AV *ex = newAV();
2260 size_t k;
2261 208 ▶ for (k = 0; k < sizeof(EX) / sizeof(EX[0]); k += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < sizeof(EX) / sizeof(EX[0]); k += 2) { 192 16 208
2262 192 HV *e = newHV();
2263 192 size_t l = strlen(EX[k]);
2264 char *esc;
2265 size_t en;
2266 192 Newx(esc, l * 3 + 1, char);
2267 192 en = po_url_esc(EX[k], l, esc, l * 3 + 1);
2268 192 hv_stores(e, "q", newSVpvn(EX[k], l));
2269 192 hv_stores(e, "href", newSVpvn(esc, en));
2270 192 hv_stores(e, "why", newSVpv(EX[k + 1], 0));
2271 192 Safefree(esc);
2272 192 av_push(ex, newRV_noinc((SV *)e));
2273 }
2274 16 hv_stores(v, "examples", newRV_noinc((SV *)ex));
2275 }
2276  
2277 16 povw_window_vars(aTHX_ v, req, &from, &to);
2278  
2279 16 ▶ for (i = 0; i < (SSize_t)ql; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (SSize_t)ql; i++) 11 5 16
2280 11 ▶ if (!isSPACE((U8)q[i])) { has_q = 1; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (!isSPACE((U8)q[i])) { has_q = 1; break; } 11 0 11
2281 16 ▶ if (!has_q || !SvOK(store) || !SvROK(store)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!has_q || !SvOK(store) || !SvROK(store)) { 11 5 16
if (!has_q || !SvOK(store) || !SvROK(store)) { 11 0 11
if (!has_q || !SvOK(store) || !SvROK(store)) { 0 11 11
2282 5 SvREFCNT_dec(from); SvREFCNT_dec(to);
2283 5 goto done;
2284 }
2285  
2286 {
2287 int n;
2288 11 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 11 11
2289 11 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 11 11
2290 11 ▶ XPUSHs(sv_2mortal(newSVpvn(q, ql)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(q, ql))); 0 11 11
2291 11 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 11 11
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 11 11
2292 11 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 11 11
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 11 11
2293 11 PUTBACK;
2294 11 n = call_method(povw_read_method(aTHX_ store), G_SCALAR);
2295 11 SPAGAIN;
2296 11 ▶ res = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
res = n ? SvREFCNT_inc(POPs) : NULL; 11 0 11
2297 11 PUTBACK;
2298 11 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 11 0 11
2299 11 SPAGAIN;
2300 }
2301 11 SvREFCNT_dec(from); SvREFCNT_dec(to);
2302  
2303 11 ▶ if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 11 0 11
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 11 0 11
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 0 11 11
2304 0 ▶ if (res) SvREFCNT_dec(res);
Branch: 1 branch
BranchTrueFalseTotal
if (res) SvREFCNT_dec(res); 0 0 0
2305 0 goto done;
2306 }
2307 11 r = (HV *)SvRV(res);
2308  
2309 11 f = hv_fetchs(r, "ok", 0);
2310 11 ▶ if (!f || !SvTRUE(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!f || !SvTRUE(*f)) { 11 0 11
if (!f || !SvTRUE(*f)) { 0 11 11
2311 0 SV **e = hv_fetchs(r, "error", 0);
2312 0 SV **of = hv_fetchs(r, "offset", 0);
2313 0 SV **st = hv_fetchs(r, "stage", 0);
2314 0 ▶ int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse");
Branch: 3 branches
BranchTrueFalseTotal
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 0 0 0
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 0 0 0
int parse = st && SvOK(*st) && strEQ(SvPV_nolen(*st), "parse"); 0 0 0
2315 0 ▶ hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 0 0 0
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 0 0 0
2316 : newSVpvs("that query could not be run"));
2317 0 ▶ hv_stores(v, "offset", of ? newSVsv(*of) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "offset", of ? newSVsv(*of) : newSV(0)); 0 0 0
2318 /* WHERE it failed is the whole message - and the store's own
2319 * hint, when it wrote one, is the most specific message there
2320 * is. The generic lines are the fallback, not the answer. */
2321 {
2322 0 SV **ht = hv_fetchs(r, "hint", 0);
2323 0 ▶ hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht))
Branch: 4 branches
BranchTrueFalseTotal
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
2324 ? newSVsv(*ht)
2325 : parse
2326 ? newSVpvs("The parser stopped there.")
2327 : newSVpvs("The planner refused it before it ran."));
2328 }
2329 0 SvREFCNT_dec(res);
2330 0 goto done;
2331 }
2332  
2333 {
2334 11 SV **sh = hv_fetchs(r, "shape", 0);
2335 11 SV **meta = hv_fetchs(r, "meta", 0);
2336 11 ▶ HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 11 0 11
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 11 0 11
2337 22 ▶ ? (HV *)SvRV(*meta) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*meta) : NULL; 11 0 11
2338 22 ▶ int rows_shape = !(sh && SvOK(*sh)) || strEQ(SvPV_nolen(*sh), "rows");
Branch: 3 branches
BranchTrueFalseTotal
int rows_shape = !(sh && SvOK(*sh)) || strEQ(SvPV_nolen(*sh), "rows"); 11 0 11
int rows_shape = !(sh && SvOK(*sh)) || strEQ(SvPV_nolen(*sh), "rows"); 11 0 11
int rows_shape = !(sh && SvOK(*sh)) || strEQ(SvPV_nolen(*sh), "rows"); 1 10 11
2339 11 ▶ int buckets_shape = sh && SvOK(*sh)
Branch: 1 branch
BranchTrueFalseTotal
int buckets_shape = sh && SvOK(*sh) 11 0 11
2340 33 ▶ && strEQ(SvPV_nolen(*sh), "buckets");
Branch: 2 branches
BranchTrueFalseTotal
&& strEQ(SvPV_nolen(*sh), "buckets"); 11 0 11
&& strEQ(SvPV_nolen(*sh), "buckets"); 5 6 11
2341  
2342 11 ▶ hv_stores(v, "shape", sh ? newSVsv(*sh) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "shape", sh ? newSVsv(*sh) : newSV(0)); 11 0 11
2343  
2344 /* A BUCKETED ANSWER IS A THIRD SHAPE, and this branched on two.
2345 *
2346 * `explore` is one box over every signal, so it cannot know what
2347 * shape an answer will take - and rows-versus-groups was every
2348 * shape there was until `bucket` added one. A bucketed answer has
2349 * `series` and no `groups`, so it took the groups branch, found
2350 * nothing, and drew a heading over an empty panel.
2351 *
2352 * The `| viz` handling and the bucketed fill live in
2353 * povw_apply_viz, SHARED with the logs page - one vocabulary, or
2354 * a viz that draws here and not in the box it was worked out
2355 * in. */
2356 11 povw_apply_viz(aTHX_ v, r, res, q, (size_t)ql,
2357 rows_shape, buckets_shape);
2358 11 ▶ if (mh) {
Branch: 1 branch
BranchTrueFalseTotal
if (mh) { 11 0 11
2359 11 povw_set_count(aTHX_ v, "scanned", mh, "scanned_rows");
2360 11 f = hv_fetchs(mh, "truncated", 0);
2361 11 ▶ hv_stores(v, "truncated", f ? newSVsv(*f) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "truncated", f ? newSVsv(*f) : newSV(0)); 11 0 11
2362 11 f = hv_fetchs(mh, "exact", 0);
2363 11 ▶ hv_stores(v, "exact", f ? newSVsv(*f) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "exact", f ? newSVsv(*f) : newSV(0)); 11 0 11
2364 }
2365 else {
2366 0 hv_stores(v, "scanned", newSVpvs("0"));
2367 0 hv_stores(v, "truncated", newSV(0));
2368 0 hv_stores(v, "exact", newSV(0));
2369 }
2370  
2371 11 ▶ if (rows_shape) {
Branch: 1 branch
BranchTrueFalseTotal
if (rows_shape) { 1 10 11
2372 1 AV *out = newAV();
2373 1 SV **rv = hv_fetchs(r, "rows", 0);
2374 1 int has_sev = 0, has_dur = 0, has_val = 0, has_tr = 0;
2375  
2376 1 ▶ if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 1 0 1
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 1 0 1
if (rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVAV) { 1 0 1
2377 1 AV *ra = (AV *)SvRV(*rv);
2378 1 SSize_t j, cnt = av_len(ra) + 1;
2379 3 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 2 1 3
2380 2 SV **e = av_fetch(ra, j, 0);
2381 HV *row, *o;
2382 SV **x;
2383 char b[64];
2384 size_t bn;
2385 2 const char *tp = "0";
2386 2 STRLEN tl = 1;
2387  
2388 2 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 2 0 2
if (!e || !SvROK(*e)) continue; 0 2 2
2389 2 row = (HV *)SvRV(*e);
2390 2 o = newHV();
2391  
2392 2 x = hv_fetchs(row, "t", 0);
2393 4 ▶ if (x && SvOK(*x)) tp = SvPV(*x, tl);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) tp = SvPV(*x, tl); 2 0 2
if (x && SvOK(*x)) tp = SvPV(*x, tl); 2 0 2
2394 2 bn = po_fmt_time(tp, (size_t)tl, b);
2395 2 hv_stores(o, "time", newSVpvn(b, bn));
2396  
2397 2 x = hv_fetchs(row, "service", 0);
2398 2 ▶ hv_stores(o, "service", (x && SvTRUE(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "service", (x && SvTRUE(*x)) ? newSVsv(*x) 2 0 2
hv_stores(o, "service", (x && SvTRUE(*x)) ? newSVsv(*x) 2 0 2
2399 : newSVpvs(""));
2400 2 x = hv_fetchs(row, "body", 0);
2401 2 ▶ hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 2 0 2
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 2 0 2
2402 : newSVpvs(""));
2403  
2404 2 x = hv_fetchs(row, "severity", 0);
2405 4 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 2 0 2
if (x && SvOK(*x)) { 2 0 2
2406 2 const char *s = po_severity_name((int)SvIV(*x));
2407 2 hv_stores(o, "severity", newSVpv(s, 0));
2408 2 ▶ if (*s) has_sev = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (*s) has_sev = 1; 2 0 2
2409 }
2410 0 else hv_stores(o, "severity", newSVpvs(""));
2411  
2412 2 x = hv_fetchs(row, "duration", 0);
2413 2 ▶ if (x && SvTRUE(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) { 0 2 2
if (x && SvTRUE(*x)) { 0 0 0
2414 0 po_u64 d = 0;
2415 0 (void)po_sv_to_u64(aTHX_ *x, &d);
2416 0 bn = po_fmt_dur(d, b);
2417 0 hv_stores(o, "duration", newSVpvn(b, bn));
2418 0 ▶ if (bn) has_dur = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (bn) has_dur = 1; 0 0 0
2419 }
2420 2 else hv_stores(o, "duration", newSVpvs(""));
2421  
2422 2 x = hv_fetchs(row, "value", 0);
2423 2 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 0 2 2
if (x && SvOK(*x)) { 0 0 0
2424 0 SV *val = povw_fmt_value(aTHX_ (double)SvNV(*x));
2425 0 ▶ if (SvCUR(val)) has_val = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(val)) has_val = 1; 0 0 0
2426 0 hv_stores(o, "value", val);
2427 }
2428 2 else hv_stores(o, "value", newSVpvs(""));
2429  
2430 {
2431 2 SV **hi = hv_fetchs(row, "trace_hi", 0);
2432 2 SV **lo = hv_fetchs(row, "trace_lo", 0);
2433 2 ▶ if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) {
Branch: 4 branches
BranchTrueFalseTotal
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) { 2 0 2
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) { 0 2 2
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) { 0 0 0
if ((hi && SvTRUE(*hi)) || (lo && SvTRUE(*lo))) { 0 0 0
2434 2 ▶ hv_stores(o, "trace",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "trace", 2 0 2
hv_stores(o, "trace", 2 0 2
2435 povw_trace_hex_sv(aTHX_
2436 hi ? *hi : &PL_sv_no,
2437 lo ? *lo : &PL_sv_no));
2438 2 has_tr = 1;
2439 }
2440 0 else hv_stores(o, "trace", newSVpvs(""));
2441 }
2442 2 av_push(out, newRV_noinc((SV *)o));
2443 }
2444 }
2445 1 hv_stores(v, "rows", newRV_noinc((SV *)out));
2446  
2447 /* A COLUMN NO ROW FILLS IS NOT SHOWN. `explore` is one box
2448 * over every signal, so the widest possible table is what it
2449 * would otherwise draw - and a span query then renders a
2450 * severity column and a value column that are empty on every
2451 * row, for ever. The answer decides its own shape. */
2452 1 hv_stores(v, "has_severity", newSViv(has_sev));
2453 1 hv_stores(v, "has_duration", newSViv(has_dur));
2454 1 hv_stores(v, "has_value", newSViv(has_val));
2455 1 hv_stores(v, "has_trace", newSViv(has_tr));
2456 }
2457 else {
2458 10 AV *out = newAV();
2459 10 SV **gv = hv_fetchs(r, "groups", 0);
2460 10 double max = 0;
2461 10 ▶ if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 5 5 10
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 5 0 5
if (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) { 5 0 5
2462 5 AV *ga = (AV *)SvRV(*gv);
2463 5 SSize_t j, cnt = av_len(ga) + 1;
2464 14 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 9 5 14
2465 9 SV **e = av_fetch(ga, j, 0);
2466 9 ▶ SV **x = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **x = (e && SvROK(*e)) 9 0 9
2467 18 ▶ ? hv_fetchs((HV *)SvRV(*e), "value", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "value", 0) : NULL; 9 0 9
2468 9 ▶ double d = x ? (double)SvNV(*x) : 0;
Branch: 1 branch
BranchTrueFalseTotal
double d = x ? (double)SvNV(*x) : 0; 9 0 9
2469 9 ▶ if (d > max) max = d;
Branch: 1 branch
BranchTrueFalseTotal
if (d > max) max = d; 5 4 9
2470 }
2471 14 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 9 5 14
2472 9 SV **e = av_fetch(ga, j, 0);
2473 HV *gh, *o;
2474 SV **x;
2475 double d;
2476  
2477 9 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 9 0 9
if (!e || !SvROK(*e)) continue; 0 9 9
2478 9 gh = (HV *)SvRV(*e);
2479 9 o = newHV();
2480 9 x = hv_fetchs(gh, "key", 0);
2481 9 ▶ hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x))
Branch: 3 branches
BranchTrueFalseTotal
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 9 0 9
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 9 0 9
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 9 0 9
2482 ? newSVsv(*x) : newSVpvs("(none)"));
2483 9 x = hv_fetchs(gh, "value", 0);
2484 9 ▶ d = x ? (double)SvNV(*x) : 0;
Branch: 1 branch
BranchTrueFalseTotal
d = x ? (double)SvNV(*x) : 0; 9 0 9
2485 9 hv_stores(o, "value", povw_fmt_value(aTHX_ d));
2486 9 x = hv_fetchs(gh, "count", 0);
2487 {
2488 char b[32];
2489 9 STRLEN cl = 0;
2490 18 ▶ const char *cp = (x && SvOK(*x)) ? SvPV(*x, cl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *cp = (x && SvOK(*x)) ? SvPV(*x, cl) : ""; 9 0 9
const char *cp = (x && SvOK(*x)) ? SvPV(*x, cl) : ""; 9 0 9
2491 9 size_t bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
2492 9 hv_stores(o, "count", newSVpvn(b, bn));
2493 }
2494 /* Truncated, as int() is: a bar drawn at 99.6% and
2495 * labelled 100 is a bar that says it is the largest
2496 * when it is not. */
2497 9 ▶ hv_stores(o, "width_pct",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "width_pct", 9 0 9
2498 newSViv(max ? (IV)(100.0 * d / max) : 0));
2499 9 av_push(out, newRV_noinc((SV *)o));
2500 }
2501 }
2502 10 hv_stores(v, "groups", newRV_noinc((SV *)out));
2503 }
2504 }
2505 11 SvREFCNT_dec(res);
2506  
2507 16 done:
2508 16 RETVAL = newRV_noinc((SV *)v);
2509 }
2510 OUTPUT:
2511 RETVAL
2512  
2513 # THE WATERFALL, COMPLETE IN THE MARKUP.
2514 #
2515 # Every bar's offset and width are percentages computed here, so the tree, the
2516 # timings and the nesting are all in the HTML. JavaScript makes it navigable;
2517 # it does not make it exist.
2518 SV *
2519 povw__trace_one(SV *class, SV *store, SV *req, SV *from, SV *to, SV *range)
2520 CODE:
2521 {
2522 6 HV *v = newHV();
2523 6 HV *rq = NULL;
2524 SV **f;
2525 6 po_u64 hi = 0, lo = 0;
2526 6 int have_id = 0;
2527 6 SV *tsv = NULL;
2528 6 HV *t = NULL;
2529 6 AV *spans_out = newAV();
2530 6 AV *nname = newAV(), *sname = newAV();
2531 6 HV *nsym = newHV(), *ssym = newHV();
2532 6 AV *specs = newAV();
2533 6 po_u64 dur = 1;
2534  
2535 PERL_UNUSED_VAR(class);
2536 6 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 6 0 6
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 6 0 6
2537  
2538 6 hv_stores(v, "heading", newSVpvs("Trace"));
2539 6 hv_stores(v, "title", newSVpvs("Trace"));
2540 6 hv_stores(v, "spans", newRV_noinc((SV *)spans_out));
2541 6 hv_stores(v, "from", newSVsv(from));
2542 6 hv_stores(v, "to", newSVsv(to));
2543 6 ▶ f = rq ? hv_fetchs(rq, "trace", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "trace", 0) : NULL; 6 0 6
2544 6 ▶ hv_stores(v, "trace", f ? newSVsv(*f) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "trace", f ? newSVsv(*f) : newSV(0)); 6 0 6
2545 6 povw_range_vars(aTHX_ v, req, range);
2546  
2547 /* WHICHEVER SPELLING ARRIVED. The links carry hex now; a bookmark
2548 * from before, or a decimal pair somebody built by hand, still
2549 * resolves. */
2550 6 ▶ if (f) have_id = povw_trace_id_c(aTHX_ *f, &hi, &lo);
Branch: 1 branch
BranchTrueFalseTotal
if (f) have_id = povw_trace_id_c(aTHX_ *f, &hi, &lo); 6 0 6
2551 6 ▶ if (!have_id || !SvOK(store) || !SvROK(store)) goto done;
Branch: 3 branches
BranchTrueFalseTotal
if (!have_id || !SvOK(store) || !SvROK(store)) goto done; 6 0 6
if (!have_id || !SvOK(store) || !SvROK(store)) goto done; 6 0 6
if (!have_id || !SvOK(store) || !SvROK(store)) goto done; 0 6 6
2552  
2553 { /* A trace is looked up over a wide window, because the link to
2554 * one is usually followed later than the window that produced
2555 * it. */
2556 int n;
2557 6 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 6 6
2558 6 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 6 6
2559 6 ▶ XPUSHs(sv_2mortal(po_u64_to_sv(hi)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(po_u64_to_sv(hi))); 0 6 6
2560 6 ▶ XPUSHs(sv_2mortal(po_u64_to_sv(lo)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(po_u64_to_sv(lo))); 0 6 6
2561 6 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSV(0))); 0 6 6
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSV(0))); 0 6 6
2562 6 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSV(0))); 0 6 6
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSV(0))); 0 6 6
2563 6 PUTBACK;
2564 6 n = call_method("trace", G_SCALAR);
2565 6 SPAGAIN;
2566 6 ▶ tsv = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
tsv = n ? SvREFCNT_inc(POPs) : NULL; 6 0 6
2567 6 PUTBACK;
2568 6 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 6 0 6
2569 6 SPAGAIN;
2570 }
2571 6 ▶ if (!tsv || !SvTRUE(tsv) || !SvROK(tsv)
Branch: 3 branches
BranchTrueFalseTotal
if (!tsv || !SvTRUE(tsv) || !SvROK(tsv) 6 0 6
if (!tsv || !SvTRUE(tsv) || !SvROK(tsv) 5 1 6
if (!tsv || !SvTRUE(tsv) || !SvROK(tsv) 5 0 5
2572 5 ▶ || SvTYPE(SvRV(tsv)) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(tsv)) != SVt_PVHV) { 0 5 5
2573 1 ▶ if (tsv) SvREFCNT_dec(tsv);
Branch: 1 branch
BranchTrueFalseTotal
if (tsv) SvREFCNT_dec(tsv); 1 0 1
2574 1 hv_stores(v, "heading", newSVpvs("Trace not found"));
2575 1 hv_stores(v, "root_name", newSVpvs("That trace is not in the store"));
2576 1 hv_stores(v, "error",
2577 newSVpvs("No spans with that trace id are in the retention window."));
2578 1 hv_stores(v, "hint",
2579 newSVpvs("It may have aged out, or the id may be truncated."));
2580 1 goto done;
2581 }
2582 5 t = (HV *)SvRV(tsv);
2583  
2584 5 f = hv_fetchs(t, "duration", 0);
2585 5 ▶ if (f && SvTRUE(*f)) (void)po_sv_to_u64(aTHX_ *f, &dur);
Branch: 2 branches
BranchTrueFalseTotal
if (f && SvTRUE(*f)) (void)po_sv_to_u64(aTHX_ *f, &dur); 5 0 5
if (f && SvTRUE(*f)) (void)po_sv_to_u64(aTHX_ *f, &dur); 5 0 5
2586 5 ▶ if (!dur) dur = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (!dur) dur = 1; 0 5 5
2587  
2588 {
2589 5 SV **sv = hv_fetchs(t, "spans", 0);
2590 5 ▶ AV *sa = (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
AV *sa = (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) 5 0 5
AV *sa = (sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) 5 0 5
2591 10 ▶ ? (AV *)SvRV(*sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(*sv) : NULL; 5 0 5
2592 5 ▶ SSize_t i, cnt = sa ? av_len(sa) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, cnt = sa ? av_len(sa) + 1 : 0; 5 0 5
2593 5 HV *attrs_of = newHV();
2594  
2595 /* THE ATTRIBUTES ARE NOT IN THE TREE. Assembly works on the
2596 * 64-byte span the seal indexes - ids, times, two symbols - so
2597 * a waterfall built from it alone can say SELECT and nothing
2598 * more. The records of this trace are read once more, filtered
2599 * in the scan on the trace id, and matched to their rows by
2600 * span id. `limit` is the span count: the trace has exactly
2601 * that many, so the read cannot be cut short. */
2602 5 ▶ if (cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if (cnt) { 5 0 5
2603 5 SV *rows = NULL;
2604 int n;
2605 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
2606 5 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 5 5
2607 5 ▶ XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(3)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(3))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(3))); 0 5 5
2608 5 ▶ XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi))); 0 5 5
2609 5 ▶ XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo))); 0 5 5
2610 5 ▶ XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv((IV)cnt)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv((IV)cnt))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv((IV)cnt))); 0 5 5
2611 5 PUTBACK;
2612 5 n = call_method("rows", G_LIST);
2613 5 SPAGAIN;
2614 {
2615 SSize_t k;
2616 10 ▶ for (k = n - 1; k > 0; k--) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
for (k = n - 1; k > 0; k--) (void)POPs; 5 5 10
2617 5 ▶ rows = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
rows = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
2618 }
2619 5 PUTBACK;
2620 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
2621 5 SPAGAIN;
2622 5 ▶ if (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) { 5 0 5
if (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) { 5 0 5
if (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) { 5 0 5
2623 5 AV *ra = (AV *)SvRV(rows);
2624 5 SSize_t k, rn = av_len(ra) + 1;
2625 15 ▶ for (k = 0; k < rn; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < rn; k++) { 10 5 15
2626 10 SV **e = av_fetch(ra, k, 0);
2627 SV **id, **at;
2628 STRLEN il;
2629 const char *ip;
2630 10 ▶ if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVHV) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVHV) continue; 10 0 10
if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVHV) continue; 10 0 10
if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVHV) continue; 0 10 10
2631 10 id = hv_fetchs((HV *)SvRV(*e), "span_id", 0);
2632 10 at = hv_fetchs((HV *)SvRV(*e), "attrs", 0);
2633 10 ▶ if (!id || !SvOK(*id) || !at || !SvROK(*at)) continue;
Branch: 4 branches
BranchTrueFalseTotal
if (!id || !SvOK(*id) || !at || !SvROK(*at)) continue; 10 0 10
if (!id || !SvOK(*id) || !at || !SvROK(*at)) continue; 10 0 10
if (!id || !SvOK(*id) || !at || !SvROK(*at)) continue; 10 0 10
if (!id || !SvOK(*id) || !at || !SvROK(*at)) continue; 0 10 10
2634 10 ip = SvPV(*id, il);
2635 10 (void)hv_store(attrs_of, ip, (I32)il, newSVsv(*at), 0);
2636 }
2637 }
2638 5 ▶ if (rows) SvREFCNT_dec(rows);
Branch: 1 branch
BranchTrueFalseTotal
if (rows) SvREFCNT_dec(rows); 5 0 5
2639 }
2640  
2641 15 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 10 5 15
2642 10 SV **e = av_fetch(sa, i, 0);
2643 HV *s, *o, *spec;
2644 SV **x;
2645 10 po_u64 off = 0, w = 0;
2646 10 IV depth = 0, status = 0;
2647 char b[64];
2648 size_t bn;
2649 SV *nm, *svc;
2650 IV nid, sid;
2651  
2652 10 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 10 0 10
if (!e || !SvROK(*e)) continue; 0 10 10
2653 10 s = (HV *)SvRV(*e);
2654 10 o = newHV();
2655  
2656 10 x = hv_fetchs(s, "offset", 0);
2657 10 ▶ if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &off);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &off); 10 0 10
if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &off); 5 5 10
2658 10 x = hv_fetchs(s, "duration", 0);
2659 10 ▶ if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &w);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &w); 10 0 10
if (x && SvTRUE(*x)) (void)po_sv_to_u64(aTHX_ *x, &w); 10 0 10
2660 10 x = hv_fetchs(s, "depth", 0);
2661 10 ▶ depth = (x && SvOK(*x)) ? SvIV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
depth = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
depth = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
2662 10 x = hv_fetchs(s, "status", 0);
2663 10 ▶ status = (x && SvOK(*x)) ? SvIV(*x) : 0;
Branch: 2 branches
BranchTrueFalseTotal
status = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
status = (x && SvOK(*x)) ? SvIV(*x) : 0; 10 0 10
2664  
2665 10 x = hv_fetchs(s, "span_id", 0);
2666 10 ▶ hv_stores(o, "span_id", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "span_id", x ? newSVsv(*x) : newSV(0)); 10 0 10
2667 /* The parent, for collapsing a subtree by IDENTITY. Rows come
2668 * out chronological (store.xs), so a subtree's descendants
2669 * are not adjacent whenever two sibling subtrees overlap in
2670 * time - and walking the next rows while depth is greater
2671 * hides part of somebody else's subtree, or stops at the
2672 * first sibling and hides nothing. */
2673 10 x = hv_fetchs(s, "parent_span_id", 0);
2674 10 ▶ hv_stores(o, "parent_span_id", x ? newSVsv(*x) : newSViv(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "parent_span_id", x ? newSVsv(*x) : newSViv(0)); 10 0 10
2675 10 x = hv_fetchs(s, "depth", 0);
2676 10 ▶ hv_stores(o, "depth", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "depth", x ? newSVsv(*x) : newSV(0)); 10 0 10
2677 /* A root span starts at 5 rather than 0: flush against the
2678 * cell edge the label touches the panel border and reads as
2679 * part of it. */
2680 /* depth is -1 for a span in a cycle or past PO_TREE_MAX_DEPTH;
2681 * 5 + -1*14 is -9px, which pulls the label out of its cell. */
2682 10 ▶ hv_stores(o, "indent", newSViv(depth > 0 ? 5 + depth * 14 : 5));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "indent", newSViv(depth > 0 ? 5 + depth * 14 : 5)); 5 5 10
2683 10 x = hv_fetchs(s, "kind", 0);
2684 10 ▶ hv_stores(o, "kind_name",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "kind_name", 10 0 10
hv_stores(o, "kind_name", 10 0 10
2685 newSVpv(po_span_kind_name(x && SvOK(*x)
2686 ? (int)SvIV(*x) : 0), 0));
2687  
2688 10 x = hv_fetchs(s, "name", 0);
2689 10 ▶ nm = (x && SvTRUE(*x)) ? newSVsv(*x) : newSVpvs("(unnamed)");
Branch: 2 branches
BranchTrueFalseTotal
nm = (x && SvTRUE(*x)) ? newSVsv(*x) : newSVpvs("(unnamed)"); 10 0 10
nm = (x && SvTRUE(*x)) ? newSVsv(*x) : newSVpvs("(unnamed)"); 10 0 10
2690 10 hv_stores(o, "name", nm);
2691 10 x = hv_fetchs(s, "service", 0);
2692 10 ▶ svc = x ? newSVsv(*x) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
svc = x ? newSVsv(*x) : newSV(0); 10 0 10
2693 10 hv_stores(o, "service", svc);
2694  
2695 10 bn = po_fmt_dur(w, b);
2696 10 hv_stores(o, "dur_ms", newSVpvn(b, bn));
2697 10 hv_stores(o, "start_pct", newSVnv(po_pct(off, dur)));
2698 /* A span that rounds to nothing still has to be visible, or a
2699 * fast child of a slow parent vanishes from its own trace. */
2700 {
2701 10 double p = po_pct(w, dur);
2702 10 ▶ hv_stores(o, "width_pct", newSVnv(p > 1 ? p : 1));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "width_pct", newSVnv(p > 1 ? p : 1)); 10 0 10
2703 }
2704 10 hv_stores(o, "status", newSViv(status));
2705 10 ▶ hv_stores(o, "row_class",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "row_class", 5 5 10
2706 status == 2 ? newSVpvs("row-error") : newSVpvs(""));
2707  
2708 { /* the attributes, in a stable order */
2709 10 AV *out = newAV();
2710 10 SV **av = NULL;
2711 10 x = hv_fetchs(s, "span_id", 0);
2712 10 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 10 0 10
if (x && SvOK(*x)) { 10 0 10
2713 STRLEN il;
2714 10 const char *ip = SvPV(*x, il);
2715 10 av = hv_fetch(attrs_of, ip, (I32)il, 0);
2716 }
2717 10 ▶ if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 10 0 10
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 10 0 10
if (av && SvROK(*av) && SvTYPE(SvRV(*av)) == SVt_PVHV) { 10 0 10
2718 10 HV *ah = (HV *)SvRV(*av);
2719 10 SSize_t nk = 0, k;
2720 SV **ks;
2721 HE *he;
2722 10 hv_iterinit(ah);
2723 10 ▶ Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *);
Branch: 7 branches
BranchTrueFalseTotal
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 0 10 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 10 0 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 0 10 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 0 10 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 0 10 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 10 0 10
Newx(ks, HvUSEDKEYS(ah) ? HvUSEDKEYS(ah) : 1, SV *); 0 10 10
2724 35 ▶ while ((he = hv_iternext(ah)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(ah))) 25 10 35
2725 25 ks[nk++] = newSVsv(hv_iterkeysv(he));
2726 25 ▶ for (k = 1; k < nk; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 1; k < nk; k++) { 15 10 25
2727 15 SV *key = ks[k];
2728 SSize_t j;
2729 STRLEN kl;
2730 15 const char *kp = SvPV(key, kl);
2731 28 ▶ for (j = k - 1; j >= 0; j--) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = k - 1; j >= 0; j--) { 20 8 28
2732 STRLEN jl;
2733 20 const char *jp = SvPV(ks[j], jl);
2734 20 size_t m = jl < kl ? jl : kl;
2735 20 ▶ int c = m ? memcmp(jp, kp, m) : 0;
Branch: 1 branch
BranchTrueFalseTotal
int c = m ? memcmp(jp, kp, m) : 0; 20 0 20
2736 20 ▶ if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1);
Branch: 3 branches
BranchTrueFalseTotal
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 20 20
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
2737 20 ▶ if (c <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (c <= 0) break; 7 13 20
2738 13 ks[j + 1] = ks[j];
2739 }
2740 15 ks[j + 1] = key;
2741 }
2742 35 ▶ for (k = 0; k < nk; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < nk; k++) { 25 10 35
2743 25 HV *pair = newHV();
2744 STRLEN kl;
2745 25 const char *kp = SvPV(ks[k], kl);
2746 25 SV **val = hv_fetch(ah, kp, (I32)kl, 0);
2747 25 hv_stores(pair, "key", ks[k]);
2748 50 ▶ hv_stores(pair, "value",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(pair, "value", 25 0 25
2749 val ? newSVpv(SvPV_nolen(*val), 0)
2750 : newSVpvs(""));
2751 25 av_push(out, newRV_noinc((SV *)pair));
2752 /* The statement, lifted out for the bar's
2753 * tooltip: a database span is named for its
2754 * OPERATION so the name stays a grouping key,
2755 * and a row that says only SELECT answers
2756 * nothing about which one. */
2757 25 ▶ if (val && kl == 13 && !memcmp(kp, "db.query.text", 13))
Branch: 3 branches
BranchTrueFalseTotal
if (val && kl == 13 && !memcmp(kp, "db.query.text", 13)) 25 0 25
if (val && kl == 13 && !memcmp(kp, "db.query.text", 13)) 5 20 25
if (val && kl == 13 && !memcmp(kp, "db.query.text", 13)) 5 0 5
2758 5 hv_stores(o, "query", newSVsv(*val));
2759 }
2760 10 Safefree(ks);
2761 }
2762 10 hv_stores(o, "attrs", newRV_noinc((SV *)out));
2763 }
2764 10 av_push(spans_out, newRV_noinc((SV *)o));
2765  
2766 /* The tree wants SYMBOLS, not strings: it folds frames by
2767 * identity, and comparing names as strings for every span of
2768 * a large trace is the difference between a picture and a
2769 * wait. */
2770 {
2771 10 SV **x2 = hv_fetchs(s, "name", 0);
2772 10 ▶ SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs("");
Branch: 2 branches
BranchTrueFalseTotal
SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs(""); 10 0 10
SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs(""); 10 0 10
2773 STRLEN kl;
2774 10 const char *kp = SvPV(key, kl);
2775 10 SV **slot = hv_fetch(nsym, kp, (I32)kl, 0);
2776 10 ▶ if (slot) nid = SvIV(*slot);
Branch: 1 branch
BranchTrueFalseTotal
if (slot) nid = SvIV(*slot); 0 10 10
2777 else {
2778 10 nid = av_len(nname) + 1;
2779 10 av_push(nname, newSVsv(key));
2780 10 (void)hv_store(nsym, kp, (I32)kl, newSViv(nid), 0);
2781 }
2782 10 SvREFCNT_dec(key);
2783 }
2784 {
2785 10 SV **x2 = hv_fetchs(s, "service", 0);
2786 10 ▶ SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs("");
Branch: 2 branches
BranchTrueFalseTotal
SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs(""); 10 0 10
SV *key = (x2 && SvOK(*x2)) ? newSVsv(*x2) : newSVpvs(""); 10 0 10
2787 STRLEN kl;
2788 10 const char *kp = SvPV(key, kl);
2789 10 SV **slot = hv_fetch(ssym, kp, (I32)kl, 0);
2790 10 ▶ if (slot) sid = SvIV(*slot);
Branch: 1 branch
BranchTrueFalseTotal
if (slot) sid = SvIV(*slot); 0 10 10
2791 else {
2792 10 sid = av_len(sname) + 1;
2793 10 av_push(sname, newSVsv(key));
2794 10 (void)hv_store(ssym, kp, (I32)kl, newSViv(sid), 0);
2795 }
2796 10 SvREFCNT_dec(key);
2797 }
2798  
2799 10 spec = newHV();
2800 10 hv_stores(spec, "trace_hi", po_u64_to_sv(hi));
2801 10 hv_stores(spec, "trace_lo", po_u64_to_sv(lo));
2802 10 x = hv_fetchs(s, "span_id", 0);
2803 10 ▶ hv_stores(spec, "span_id", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(spec, "span_id", x ? newSVsv(*x) : newSV(0)); 10 0 10
2804 /* The store already gives the parent SPAN ID (store.xs), and
2805 * Flame::build's span spec wants a span id - so this is a
2806 * pass-through and was not.
2807 *
2808 * It ran through povw_parent_id_sv, which converts an INDEX to
2809 * a span id and is written for Trace::analyse's output. Handed
2810 * a span id it did this: the root, whose parent is 0, indexed
2811 * spans[0] - ITSELF - and became its own parent, which
2812 * po_tree_build reads as a cycle and po_flame_add then skips.
2813 * Every child's real 64-bit parent fell outside the array and
2814 * flattened to 0. So the flamegraph lost the root span of
2815 * every trace, while the waterfall above it - which uses the
2816 * store's own depth - looked right. */
2817 10 x = hv_fetchs(s, "parent_span_id", 0);
2818 10 ▶ hv_stores(spec, "parent", x ? newSVsv(*x) : newSViv(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(spec, "parent", x ? newSVsv(*x) : newSViv(0)); 10 0 10
2819 10 x = hv_fetchs(s, "start", 0);
2820 10 ▶ hv_stores(spec, "start", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(spec, "start", x ? newSVsv(*x) : newSV(0)); 10 0 10
2821 {
2822 10 po_u64 st = 0, d2 = 0;
2823 10 ▶ if (x) (void)po_sv_to_u64(aTHX_ *x, &st);
Branch: 1 branch
BranchTrueFalseTotal
if (x) (void)po_sv_to_u64(aTHX_ *x, &st); 10 0 10
2824 {
2825 10 SV **dd = hv_fetchs(s, "duration", 0);
2826 10 ▶ if (dd) (void)po_sv_to_u64(aTHX_ *dd, &d2);
Branch: 1 branch
BranchTrueFalseTotal
if (dd) (void)po_sv_to_u64(aTHX_ *dd, &d2); 10 0 10
2827 }
2828 10 hv_stores(spec, "end", po_u64_to_sv(po_ns_add(st, d2)));
2829 }
2830 10 hv_stores(spec, "name", newSViv(nid));
2831 10 hv_stores(spec, "service", newSViv(sid));
2832 10 x = hv_fetchs(s, "status", 0);
2833 10 ▶ hv_stores(spec, "status", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(spec, "status", x ? newSVsv(*x) : newSV(0)); 10 0 10
2834 10 x = hv_fetchs(s, "kind", 0);
2835 10 ▶ hv_stores(spec, "kind", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(spec, "kind", x ? newSVsv(*x) : newSV(0)); 10 0 10
2836 10 av_push(specs, newRV_noinc((SV *)spec));
2837 }
2838 5 SvREFCNT_dec((SV *)attrs_of);
2839 }
2840  
2841 5 povw_set_iv(aTHX_ v, "span_count", t, "span_count");
2842 {
2843 char b[64];
2844 5 SV **d = hv_fetchs(t, "duration", 0);
2845 5 po_u64 dv = 0;
2846 size_t bn;
2847 5 ▶ if (d) (void)po_sv_to_u64(aTHX_ *d, &dv);
Branch: 1 branch
BranchTrueFalseTotal
if (d) (void)po_sv_to_u64(aTHX_ *d, &dv); 5 0 5
2848 5 bn = po_fmt_dur(dv, b);
2849 5 hv_stores(v, "duration_ms", newSVpvn(b, bn));
2850 }
2851 {
2852 5 SV **first = av_fetch(spans_out, 0, 0);
2853 SV *root;
2854 10 ▶ if (first && SvROK(*first)) {
Branch: 2 branches
BranchTrueFalseTotal
if (first && SvROK(*first)) { 5 0 5
if (first && SvROK(*first)) { 5 0 5
2855 5 HV *o = (HV *)SvRV(*first);
2856 5 SV **svc = hv_fetchs(o, "service", 0);
2857 5 SV **nm = hv_fetchs(o, "name", 0);
2858 5 root = newSVpvs("");
2859 5 ▶ if (svc && SvOK(*svc)) sv_catsv(root, *svc);
Branch: 2 branches
BranchTrueFalseTotal
if (svc && SvOK(*svc)) sv_catsv(root, *svc); 5 0 5
if (svc && SvOK(*svc)) sv_catsv(root, *svc); 5 0 5
2860 5 sv_catpvs(root, " ");
2861 5 ▶ if (nm && SvOK(*nm)) sv_catsv(root, *nm);
Branch: 2 branches
BranchTrueFalseTotal
if (nm && SvOK(*nm)) sv_catsv(root, *nm); 5 0 5
if (nm && SvOK(*nm)) sv_catsv(root, *nm); 5 0 5
2862 }
2863 0 else root = newSVpvs("Trace");
2864 5 hv_stores(v, "root_name", newSVsv(root));
2865 5 hv_stores(v, "heading", root);
2866 }
2867 5 povw_set_iv(aTHX_ v, "orphans", t, "orphans");
2868 5 povw_set_iv(aTHX_ v, "cycles", t, "cycles");
2869 5 povw_set_iv(aTHX_ v, "errors", t, "errors");
2870  
2871 { /* THE LOGS THIS TRACE PRODUCED, which is the cross-signal join
2872 * the query language names `traces | logs` and the reason log
2873 * records carry a trace id at all. Filtered in the scan on two
2874 * integers rather than read wholesale and sifted here.
2875 *
2876 * No window: a trace is looked at long after the window that
2877 * produced it, and a link pasted into a chat an hour later should
2878 * still show its logs. */
2879 5 AV *out = newAV();
2880 5 SV *logs = NULL;
2881 int n;
2882  
2883 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
2884 5 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 5 5
2885 5 ▶ XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("kind"))); XPUSHs(sv_2mortal(newSViv(2))); 0 5 5
2886 5 ▶ XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("trace_hi"))); XPUSHs(sv_2mortal(po_u64_to_sv(hi))); 0 5 5
2887 5 ▶ XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("trace_lo"))); XPUSHs(sv_2mortal(po_u64_to_sv(lo))); 0 5 5
2888 5 ▶ XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(500)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(500))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(500))); 0 5 5
2889 5 PUTBACK;
2890 5 n = call_method("rows", G_LIST);
2891 5 SPAGAIN;
2892 {
2893 SSize_t k;
2894 10 ▶ for (k = n - 1; k > 0; k--) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
for (k = n - 1; k > 0; k--) (void)POPs; 5 5 10
2895 5 ▶ logs = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
logs = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
2896 }
2897 5 PUTBACK;
2898 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
2899 5 SPAGAIN;
2900  
2901 5 ▶ if (logs && SvROK(logs) && SvTYPE(SvRV(logs)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (logs && SvROK(logs) && SvTYPE(SvRV(logs)) == SVt_PVAV) { 5 0 5
if (logs && SvROK(logs) && SvTYPE(SvRV(logs)) == SVt_PVAV) { 5 0 5
if (logs && SvROK(logs) && SvTYPE(SvRV(logs)) == SVt_PVAV) { 5 0 5
2902 5 AV *la = (AV *)SvRV(logs);
2903 5 SSize_t k, cnt = av_len(la) + 1;
2904 /* REVERSED: the store hands them back newest first and a log
2905 * beside a waterfall reads downwards, in the order the trace
2906 * happened. */
2907 10 ▶ for (k = cnt - 1; k >= 0; k--) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = cnt - 1; k >= 0; k--) { 5 5 10
2908 5 SV **e = av_fetch(la, k, 0);
2909 HV *w, *o;
2910 SV **x;
2911 const char *sev;
2912 char b[64];
2913 size_t bn;
2914 5 const char *tp = "0";
2915 5 STRLEN tl = 1;
2916  
2917 5 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 5 0 5
if (!e || !SvROK(*e)) continue; 0 5 5
2918 5 w = (HV *)SvRV(*e);
2919 5 o = newHV();
2920 5 x = hv_fetchs(w, "t", 0);
2921 10 ▶ if (x && SvOK(*x)) tp = SvPV(*x, tl);
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) tp = SvPV(*x, tl); 5 0 5
if (x && SvOK(*x)) tp = SvPV(*x, tl); 5 0 5
2922 5 bn = po_fmt_time(tp, (size_t)tl, b);
2923 5 hv_stores(o, "time", newSVpvn(b, bn));
2924 5 x = hv_fetchs(w, "severity", 0);
2925 5 ▶ sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0);
Branch: 2 branches
BranchTrueFalseTotal
sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0); 5 0 5
sev = po_severity_name(x && SvOK(*x) ? (int)SvIV(*x) : 0); 5 0 5
2926 5 hv_stores(o, "sev_name", newSVpv(sev, 0));
2927 5 x = hv_fetchs(w, "service", 0);
2928 5 ▶ hv_stores(o, "service", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "service", x ? newSVsv(*x) : newSV(0)); 5 0 5
2929 5 x = hv_fetchs(w, "body", 0);
2930 5 ▶ hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 5 0 5
hv_stores(o, "body", (x && SvOK(*x)) ? newSVsv(*x) 5 0 5
2931 : newSVpvs(""));
2932 5 hv_stores(o, "id", povw_record_id_sv(aTHX_ *e));
2933 5 x = hv_fetchs(w, "span_id", 0);
2934 5 ▶ hv_stores(o, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x) 5 0 5
hv_stores(o, "span_id", (x && SvTRUE(*x)) ? newSVsv(*x) 5 0 5
2935 : newSVpvs(""));
2936 5 ▶ hv_stores(o, "row_class",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "row_class", 0 5 5
hv_stores(o, "row_class", 0 0 0
2937 (strEQ(sev, "error") || strEQ(sev, "fatal"))
2938 ? newSVpvs("row-error") : newSVpvs(""));
2939 5 av_push(out, newRV_noinc((SV *)o));
2940 }
2941 }
2942 5 ▶ if (logs) SvREFCNT_dec(logs);
Branch: 1 branch
BranchTrueFalseTotal
if (logs) SvREFCNT_dec(logs); 5 0 5
2943 5 hv_stores(v, "logs", newRV_noinc((SV *)out));
2944 }
2945  
2946 { /* The flamegraph, from SELF time rather than total, so a parent
2947 * that spent its time waiting on a child does not appear to have
2948 * spent it working. */
2949 5 SV *tree = NULL;
2950 int n;
2951 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
2952 5 ▶ XPUSHs(sv_2mortal(newRV_inc((SV *)specs)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV *)specs))); 0 5 5
2953 5 PUTBACK;
2954 5 n = call_pv("Punk::Observe::Flame::build", G_SCALAR | G_EVAL);
2955 5 SPAGAIN;
2956 5 ▶ tree = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
tree = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
2957 5 PUTBACK;
2958 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
2959 5 SPAGAIN;
2960 5 ▶ if (SvTRUE(ERRSV) && tree) { SvREFCNT_dec(tree); tree = NULL; }
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV) && tree) { SvREFCNT_dec(tree); tree = NULL; } 5 0 5
if (SvTRUE(ERRSV) && tree) { SvREFCNT_dec(tree); tree = NULL; } 0 5 5
if (SvTRUE(ERRSV) && tree) { SvREFCNT_dec(tree); tree = NULL; } 0 0 0
2961  
2962 5 ▶ if (tree && SvTRUE(tree)) {
Branch: 2 branches
BranchTrueFalseTotal
if (tree && SvTRUE(tree)) { 5 0 5
if (tree && SvTRUE(tree)) { 5 0 5
2963 SV *rows;
2964 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
2965 5 ▶ XPUSHs(sv_2mortal(newSVsv(tree)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(tree))); 0 5 5
2966 5 ▶ XPUSHs(sv_2mortal(newRV_inc((SV *)nname)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV *)nname))); 0 5 5
2967 5 ▶ XPUSHs(sv_2mortal(newRV_inc((SV *)sname)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV *)sname))); 0 5 5
2968 5 PUTBACK;
2969 5 n = call_pv("Punk::Observe::View::_flame_rows", G_SCALAR);
2970 5 SPAGAIN;
2971 5 ▶ rows = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
rows = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
2972 5 PUTBACK;
2973 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
2974 5 SPAGAIN;
2975  
2976 5 ▶ if (rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (rows) { 5 0 5
2977 5 IV deep = 0;
2978 5 ▶ if (SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) { 5 0 5
if (SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) { 5 0 5
2979 5 AV *ra = (AV *)SvRV(rows);
2980 5 SSize_t k, cnt = av_len(ra) + 1;
2981 15 ▶ for (k = 0; k < cnt; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < cnt; k++) { 10 5 15
2982 10 SV **e = av_fetch(ra, k, 0);
2983 10 ▶ SV **d = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **d = (e && SvROK(*e)) 10 0 10
2984 20 ▶ ? hv_fetchs((HV *)SvRV(*e), "depth", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "depth", 0) : NULL; 10 0 10
2985 10 ▶ IV dv = (d && SvOK(*d)) ? SvIV(*d) : 0;
Branch: 2 branches
BranchTrueFalseTotal
IV dv = (d && SvOK(*d)) ? SvIV(*d) : 0; 10 0 10
IV dv = (d && SvOK(*d)) ? SvIV(*d) : 0; 10 0 10
2986 10 ▶ if (dv > deep) deep = dv;
Branch: 1 branch
BranchTrueFalseTotal
if (dv > deep) deep = dv; 5 5 10
2987 }
2988 }
2989 5 hv_stores(v, "flame", rows);
2990 5 hv_stores(v, "flame_height", newSViv((deep + 1) * 18 + 4));
2991 }
2992 }
2993 5 ▶ if (tree) SvREFCNT_dec(tree);
Branch: 1 branch
BranchTrueFalseTotal
if (tree) SvREFCNT_dec(tree); 5 0 5
2994 }
2995 5 SvREFCNT_dec(tsv);
2996  
2997 6 done:
2998 6 SvREFCNT_dec((SV *)nname);
2999 6 SvREFCNT_dec((SV *)sname);
3000 6 SvREFCNT_dec((SV *)nsym);
3001 6 SvREFCNT_dec((SV *)ssym);
3002 6 SvREFCNT_dec((SV *)specs);
3003 6 RETVAL = newRV_noinc((SV *)v);
3004 }
3005 OUTPUT:
3006 RETVAL
3007  
3008 # ONE BOX, TWO QUESTIONS, because they are asked with the same gesture.
3009 #
3010 # Somebody arriving at this page has either an identifier - pasted out of a
3011 # log line, a header, another vendor's UI - or a description of what they are
3012 # looking for. Making them choose the right control first means the id goes in
3013 # the filter box, matches nothing, and the page says "no traces", which reads
3014 # as "that trace is gone".
3015 #
3016 # So: if it parses as an identifier, it IS one, and the trace opens.
3017 # Everything that does not parse is a search term.
3018 SV *
3019 povw__page_trace(SV *class, SV *store, SV *req)
3020 CODE:
3021 {
3022 40 HV *v = NULL;
3023 40 HV *rq = NULL;
3024 SV **f;
3025 40 SV *from = NULL, *to = NULL, *range = NULL;
3026 40 SV *res = NULL;
3027 40 const char *q = "";
3028 40 STRLEN qlen = 0;
3029 40 po_u64 ns = 0;
3030 40 int is_max = 0, have_ns = 0;
3031 40 const char *mm = "";
3032 40 STRLEN mmlen = 0;
3033 40 AV *traces_out = NULL;
3034 40 po_u64 max = 0;
3035  
3036 40 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 40 0 40
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 40 0 40
3037 40 range = povw_window_range(aTHX_ req, &from, &to);
3038  
3039 /* An explicit trace opens it, and so does a query that parses as an
3040 * identifier - canonicalised on the way in, so the page it opens
3041 * carries the same identifier as every link to it. */
3042 40 ▶ f = rq ? hv_fetchs(rq, "trace", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "trace", 0) : NULL; 40 0 40
3043 40 ▶ if (f && SvOK(*f) && SvCUR(*f)) {
Branch: 3 branches
BranchTrueFalseTotal
if (f && SvOK(*f) && SvCUR(*f)) { 3 37 40
if (f && SvOK(*f) && SvCUR(*f)) { 3 0 3
if (f && SvOK(*f) && SvCUR(*f)) { 3 0 3
3044 3 RETVAL = povw_trace_one_sv(aTHX_ class, store, req, from, to, range);
3045 3 goto out;
3046 }
3047 37 ▶ if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f) && SvCUR(*f)) {
Branch: 4 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f) && SvCUR(*f)) { 37 0 37
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f) && SvCUR(*f)) { 8 29 37
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f) && SvCUR(*f)) { 8 0 8
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f) && SvCUR(*f)) { 8 0 8
3048 8 po_u64 hi = 0, lo = 0;
3049 8 ▶ if (povw_trace_id_c(aTHX_ *f, &hi, &lo)) {
Branch: 1 branch
BranchTrueFalseTotal
if (povw_trace_id_c(aTHX_ *f, &hi, &lo)) { 3 5 8
3050 3 HV *copy = newHVhv(rq);
3051 3 SV *rr = sv_2mortal(newRV_noinc((SV *)copy));
3052 3 hv_stores(copy, "trace", povw_trace_hex_sv(aTHX_
3053 sv_2mortal(po_u64_to_sv(hi)),
3054 sv_2mortal(po_u64_to_sv(lo))));
3055 3 RETVAL = povw_trace_one_sv(aTHX_ class, store, rr, from, to, range);
3056 3 goto out;
3057 }
3058 }
3059  
3060 34 v = newHV();
3061 34 hv_stores(v, "heading", newSVpvs("Traces"));
3062 34 hv_stores(v, "title", newSVpvs("Traces"));
3063 34 hv_stores(v, "from", newSVsv(from));
3064 34 hv_stores(v, "to", newSVsv(to));
3065 34 hv_stores(v, "spans", newRV_noinc((SV *)newAV()));
3066 34 traces_out = newAV();
3067 34 hv_stores(v, "traces", newRV_noinc((SV *)traces_out));
3068  
3069 34 povw_range_vars(aTHX_ v, req, range);
3070  
3071 39 ▶ if (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) q = SvPV(*f, qlen);
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) q = SvPV(*f, qlen); 34 0 34
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) q = SvPV(*f, qlen); 5 29 34
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) q = SvPV(*f, qlen); 5 0 5
3072 34 hv_stores(v, "query", newSVpvn(q, qlen));
3073 {
3074 char *esc;
3075 size_t en;
3076 34 Newx(esc, qlen * 3 + 1, char);
3077 34 en = po_url_esc(q, (size_t)qlen, esc, qlen * 3 + 1);
3078 34 hv_stores(v, "query_esc", newSVpvn(esc, en));
3079 34 Safefree(esc);
3080 }
3081 34 ▶ f = rq ? hv_fetchs(rq, "errors", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "errors", 0) : NULL; 34 0 34
3082 34 ▶ hv_stores(v, "errors_only", newSViv(f && SvTRUE(*f) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "errors_only", newSViv(f && SvTRUE(*f) ? 1 : 0)); 1 33 34
hv_stores(v, "errors_only", newSViv(f && SvTRUE(*f) ? 1 : 0)); 1 0 1
3083 /* The DISPLAY value blanks a bare "0", as `|| ''` did; the GUARD
3084 * below reads the raw string, because "0" is a filter somebody typed
3085 * and a filter of zero is not the absence of one. */
3086 34 ▶ f = rq ? hv_fetchs(rq, "min_ms", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "min_ms", 0) : NULL; 34 0 34
3087 48 ▶ if (f && SvOK(*f)) mm = SvPV(*f, mmlen);
Branch: 2 branches
BranchTrueFalseTotal
if (f && SvOK(*f)) mm = SvPV(*f, mmlen); 14 20 34
if (f && SvOK(*f)) mm = SvPV(*f, mmlen); 14 0 14
3088 34 ▶ hv_stores(v, "min_ms", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs(""));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "min_ms", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs("")); 14 20 34
hv_stores(v, "min_ms", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs("")); 12 2 14
3089 34 ▶ f = rq ? hv_fetchs(rq, "service", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "service", 0) : NULL; 34 0 34
3090 34 ▶ hv_stores(v, "service", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs(""));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "service", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs("")); 0 34 34
hv_stores(v, "service", (f && SvTRUE(*f)) ? newSVsv(*f) : newSVpvs("")); 0 0 0
3091  
3092 /* A FILTER THAT CANNOT BE READ IS REFUSED, NOT DROPPED. An empty box
3093 * is no filter; text that is not a duration is a mistake, and
3094 * dropping it silently answered with the whole unfiltered table -
3095 * which is the one outcome indistinguishable from a correct answer. */
3096 /* THREE ANSWERS, not two: nothing typed, something typed that does
3097 * not read as a duration, and a duration. Only the middle one is an
3098 * error, and collapsing it into the first is what made an unreadable
3099 * filter answer with the whole unfiltered table. */
3100 34 ▶ if (mmlen) have_ns = po_min_duration(mm, (size_t)mmlen, &ns, &is_max);
Branch: 1 branch
BranchTrueFalseTotal
if (mmlen) have_ns = po_min_duration(mm, (size_t)mmlen, &ns, &is_max); 13 21 34
3101 34 ▶ if (mmlen && have_ns <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (mmlen && have_ns <= 0) { 13 21 34
if (mmlen && have_ns <= 0) { 3 10 13
3102 3 SV *e = newSVpvs("'");
3103 3 sv_catpvn(e, mm, mmlen);
3104 3 sv_catpvs(e, "' is not a duration.");
3105 3 hv_stores(v, "error", e);
3106 3 hv_stores(v, "hint",
3107 newSVpvs("Try 100 for milliseconds, or give a unit: 250us, "
3108 "500ms, 1.5s. Put < in front for faster than: < 100ms."));
3109 3 goto done;
3110 }
3111 31 ▶ if (!SvOK(store) || !SvROK(store)) goto done;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(store) || !SvROK(store)) goto done; 31 0 31
if (!SvOK(store) || !SvROK(store)) goto done; 0 31 31
3112  
3113 {
3114 int n;
3115 31 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 31 31
3116 31 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 31 31
3117 31 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 31 31
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 31 31
3118 31 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 31 31
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 31 31
3119 31 ▶ XPUSHs(sv_2mortal(newSVpvs("errors_only")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("errors_only"))); 0 31 31
3120 31 ▶ f = rq ? hv_fetchs(rq, "errors", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "errors", 0) : NULL; 31 0 31
3121 31 ▶ XPUSHs(sv_2mortal(newSViv(f && SvTRUE(*f) ? 1 : 0)));
Branch: 3 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(f && SvTRUE(*f) ? 1 : 0))); 0 31 31
XPUSHs(sv_2mortal(newSViv(f && SvTRUE(*f) ? 1 : 0))); 1 30 31
XPUSHs(sv_2mortal(newSViv(f && SvTRUE(*f) ? 1 : 0))); 1 0 1
3122 /* THE SAME BOX BOUNDS EITHER END. "faster than 100ms" is a
3123 * question about the same column as "slower than 100ms" and there
3124 * is no reason one should be askable and the other not. */
3125 31 ▶ XPUSHs(sv_2mortal(newSVpv(is_max ? "max_duration" : "min_duration", 0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(is_max ? "max_duration" : "min_duration", 0))); 0 31 31
XPUSHs(sv_2mortal(newSVpv(is_max ? "max_duration" : "min_duration", 0))); 5 26 31
3126 31 ▶ XPUSHs(sv_2mortal(have_ns > 0 ? po_u64_to_sv(ns) : newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(have_ns > 0 ? po_u64_to_sv(ns) : newSV(0))); 0 31 31
XPUSHs(sv_2mortal(have_ns > 0 ? po_u64_to_sv(ns) : newSV(0))); 10 21 31
3127 31 ▶ XPUSHs(sv_2mortal(newSVpvs("service")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("service"))); 0 31 31
3128 31 ▶ f = rq ? hv_fetchs(rq, "service", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "service", 0) : NULL; 31 0 31
3129 31 ▶ XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0))); 0 31 31
XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0))); 0 31 31
3130 31 ▶ XPUSHs(sv_2mortal(newSVpvs("match")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("match"))); 0 31 31
3131 31 ▶ f = rq ? hv_fetchs(rq, "q", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "q", 0) : NULL; 31 0 31
3132 31 ▶ XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0))); 0 31 31
XPUSHs(sv_2mortal(f ? newSVsv(*f) : newSV(0))); 5 26 31
3133 31 ▶ XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(50)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(50))); 0 31 31
XPUSHs(sv_2mortal(newSVpvs("limit"))); XPUSHs(sv_2mortal(newSViv(50))); 0 31 31
3134 /* THE PAGE CURSOR: "durns-hi-lo", the triple that gives the
3135 * duration walk its total order. Parsed strictly - a mangled
3136 * cursor is ignored and the first page answers, which beats a
3137 * 500 for a truncated paste. */
3138 31 ▶ f = rq ? hv_fetchs(rq, "after", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
f = rq ? hv_fetchs(rq, "after", 0) : NULL; 31 0 31
3139 31 ▶ if (f && SvOK(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (f && SvOK(*f)) { 7 24 31
if (f && SvOK(*f)) { 7 0 7
3140 STRLEN al;
3141 7 const char *ap = SvPV(*f, al);
3142 7 STRLEN d1 = 0, d2 = 0, ix;
3143 7 int digits = 1;
3144 79 ▶ for (ix = 0; ix < al; ix++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ix = 0; ix < al; ix++) { 72 7 79
3145 72 ▶ if (ap[ix] == '-') { if (!d1) d1 = ix; else if (!d2) d2 = ix; else digits = 0; }
Branch: 3 branches
BranchTrueFalseTotal
if (ap[ix] == '-') { if (!d1) d1 = ix; else if (!d2) d2 = ix; else digits = 0; } 14 58 72
if (ap[ix] == '-') { if (!d1) d1 = ix; else if (!d2) d2 = ix; else digits = 0; } 7 7 14
if (ap[ix] == '-') { if (!d1) d1 = ix; else if (!d2) d2 = ix; else digits = 0; } 7 0 7
3146 58 ▶ else if (ap[ix] < '0' || ap[ix] > '9') digits = 0;
Branch: 2 branches
BranchTrueFalseTotal
else if (ap[ix] < '0' || ap[ix] > '9') digits = 0; 58 0 58
else if (ap[ix] < '0' || ap[ix] > '9') digits = 0; 10 48 58
3147 }
3148 7 ▶ if (digits && d1 && d2 > d1 + 1 && d2 + 1 < al) {
Branch: 4 branches
BranchTrueFalseTotal
if (digits && d1 && d2 > d1 + 1 && d2 + 1 < al) { 6 1 7
if (digits && d1 && d2 > d1 + 1 && d2 + 1 < al) { 6 0 6
if (digits && d1 && d2 > d1 + 1 && d2 + 1 < al) { 6 0 6
if (digits && d1 && d2 > d1 + 1 && d2 + 1 < al) { 6 0 6
3149 6 ▶ XPUSHs(sv_2mortal(newSVpvs("after_dur")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("after_dur"))); 0 6 6
3150 6 ▶ XPUSHs(sv_2mortal(newSVpvn(ap, d1)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(ap, d1))); 0 6 6
3151 6 ▶ XPUSHs(sv_2mortal(newSVpvs("after_hi")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("after_hi"))); 0 6 6
3152 6 ▶ XPUSHs(sv_2mortal(newSVpvn(ap + d1 + 1, d2 - d1 - 1)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(ap + d1 + 1, d2 - d1 - 1))); 0 6 6
3153 6 ▶ XPUSHs(sv_2mortal(newSVpvs("after_lo")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("after_lo"))); 0 6 6
3154 6 ▶ XPUSHs(sv_2mortal(newSVpvn(ap + d2 + 1, al - d2 - 1)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(ap + d2 + 1, al - d2 - 1))); 0 6 6
3155 6 hv_stores(v, "paged", newSViv(1));
3156 }
3157 }
3158 31 PUTBACK;
3159 31 n = call_method("traces", G_SCALAR);
3160 31 SPAGAIN;
3161 31 ▶ res = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
res = n ? SvREFCNT_inc(POPs) : NULL; 31 0 31
3162 31 PUTBACK;
3163 31 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 31 0 31
3164 31 SPAGAIN;
3165 }
3166 31 ▶ if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 31 0 31
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 31 0 31
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 0 31 31
3167 0 ▶ if (res) SvREFCNT_dec(res);
Branch: 1 branch
BranchTrueFalseTotal
if (res) SvREFCNT_dec(res); 0 0 0
3168 0 goto done;
3169 }
3170  
3171 {
3172 31 HV *r = (HV *)SvRV(res);
3173 31 SV **tv = hv_fetchs(r, "traces", 0);
3174 31 ▶ AV *ta = (tv && SvROK(*tv) && SvTYPE(SvRV(*tv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
AV *ta = (tv && SvROK(*tv) && SvTYPE(SvRV(*tv)) == SVt_PVAV) 31 0 31
AV *ta = (tv && SvROK(*tv) && SvTYPE(SvRV(*tv)) == SVt_PVAV) 31 0 31
3175 62 ▶ ? (AV *)SvRV(*tv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(*tv) : NULL; 31 0 31
3176 31 ▶ SSize_t i, cnt = ta ? av_len(ta) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, cnt = ta ? av_len(ta) + 1 : 0; 31 0 31
3177 31 AV *pts = newAV();
3178  
3179 472 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 441 31 472
3180 441 SV **e = av_fetch(ta, i, 0);
3181 441 ▶ SV **d = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **d = (e && SvROK(*e)) 441 0 441
3182 882 ▶ ? hv_fetchs((HV *)SvRV(*e), "duration", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "duration", 0) : NULL; 441 0 441
3183 441 po_u64 dv = 0;
3184 441 ▶ if (d) (void)po_sv_to_u64(aTHX_ *d, &dv);
Branch: 1 branch
BranchTrueFalseTotal
if (d) (void)po_sv_to_u64(aTHX_ *d, &dv); 441 0 441
3185 441 ▶ if (dv > max) max = dv;
Branch: 1 branch
BranchTrueFalseTotal
if (dv > max) max = dv; 143 298 441
3186 }
3187  
3188 472 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 441 31 472
3189 441 SV **e = av_fetch(ta, i, 0);
3190 HV *t, *o;
3191 SV **x, **hi, **lo;
3192 441 po_u64 dv = 0;
3193 char b[64];
3194 size_t bn;
3195  
3196 441 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 441 0 441
if (!e || !SvROK(*e)) continue; 0 441 441
3197 441 t = (HV *)SvRV(*e);
3198 441 o = newHV();
3199 441 hi = hv_fetchs(t, "trace_hi", 0);
3200 441 lo = hv_fetchs(t, "trace_lo", 0);
3201 441 ▶ hv_stores(o, "id", povw_trace_hex_sv(aTHX_
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "id", povw_trace_hex_sv(aTHX_ 441 0 441
hv_stores(o, "id", povw_trace_hex_sv(aTHX_ 441 0 441
3202 hi ? *hi : &PL_sv_no, lo ? *lo : &PL_sv_no));
3203 441 x = hv_fetchs(t, "service", 0);
3204 441 ▶ hv_stores(o, "service", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "service", x ? newSVsv(*x) : newSV(0)); 441 0 441
3205 441 x = hv_fetchs(t, "name", 0);
3206 441 ▶ hv_stores(o, "name", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "name", x ? newSVsv(*x) : newSV(0)); 441 0 441
3207 441 x = hv_fetchs(t, "spans", 0);
3208 441 ▶ hv_stores(o, "spans", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "spans", x ? newSVsv(*x) : newSV(0)); 441 0 441
3209 441 x = hv_fetchs(t, "errors", 0);
3210 441 ▶ hv_stores(o, "errors", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "errors", x ? newSVsv(*x) : newSV(0)); 441 0 441
3211 441 ▶ hv_stores(o, "row_class",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "row_class", 441 0 441
hv_stores(o, "row_class", 16 425 441
3212 (x && SvTRUE(*x)) ? newSVpvs("row-error")
3213 : newSVpvs(""));
3214 {
3215 441 SV **dd = hv_fetchs(t, "duration", 0);
3216 441 ▶ if (dd) (void)po_sv_to_u64(aTHX_ *dd, &dv);
Branch: 1 branch
BranchTrueFalseTotal
if (dd) (void)po_sv_to_u64(aTHX_ *dd, &dv); 441 0 441
3217 }
3218 441 bn = po_fmt_dur(dv, b);
3219 441 hv_stores(o, "duration", newSVpvn(b, bn));
3220 441 ▶ hv_stores(o, "width_pct",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "width_pct", 441 0 441
3221 newSViv(max ? (IV)(100.0 * (double)dv / (double)max)
3222 : 0));
3223 441 av_push(traces_out, newRV_noinc((SV *)o));
3224  
3225 /* WHERE THE SLOW ONES CLUSTER IS WHAT THE TABLE CANNOT SHOW.
3226 *
3227 * A list of the fifty slowest answers "which were slow"; it
3228 * cannot answer "were they slow all afternoon or for ninety
3229 * seconds at half past two", which is the question that
3230 * separates a capacity problem from an incident. Same rows,
3231 * plotted against the time they happened. */
3232 441 x = hv_fetchs(t, "t", 0);
3233 441 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 441 0 441
if (x && SvOK(*x)) { 441 0 441
3234 441 HV *p = newHV();
3235 441 SV **er = hv_fetchs(t, "errors", 0);
3236 441 SV **dd = hv_fetchs(t, "duration", 0);
3237 441 hv_stores(p, "t", newSVsv(*x));
3238 441 ▶ hv_stores(p, "duration", dd ? newSVsv(*dd) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(p, "duration", dd ? newSVsv(*dd) : newSV(0)); 441 0 441
3239 441 ▶ hv_stores(p, "errors", er ? newSVsv(*er) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(p, "errors", er ? newSVsv(*er) : newSV(0)); 441 0 441
3240 441 ▶ hv_stores(p, "id", povw_trace_hex_sv(aTHX_
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(p, "id", povw_trace_hex_sv(aTHX_ 441 0 441
hv_stores(p, "id", povw_trace_hex_sv(aTHX_ 441 0 441
3241 hi ? *hi : &PL_sv_no, lo ? *lo : &PL_sv_no));
3242 441 av_push(pts, newRV_noinc((SV *)p));
3243 }
3244 }
3245  
3246 /* The scatter is drawn from the same trace list the table below
3247 * it shows, so the two cannot disagree about what is in the
3248 * window. */
3249 31 ▶ if (cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if (cnt) { 26 5 31
3250 26 SV *fig = NULL, *enc = NULL;
3251 int n;
3252 26 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 26 26
3253 26 ▶ XPUSHs(sv_2mortal(newRV_inc((SV *)pts)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV *)pts))); 0 26 26
3254 26 PUTBACK;
3255 26 n = call_pv("Punk::Observe::Plot::latency_scatter", G_SCALAR);
3256 26 SPAGAIN;
3257 26 ▶ fig = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
fig = n ? SvREFCNT_inc(POPs) : NULL; 26 0 26
3258 26 PUTBACK;
3259 26 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 26 0 26
3260 26 SPAGAIN;
3261  
3262 26 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 26 26
3263 26 ▶ XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0))); 0 26 26
XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0))); 26 0 26
3264 26 PUTBACK;
3265 26 n = call_pv("Punk::Observe::Plot::encode", G_SCALAR);
3266 26 SPAGAIN;
3267 26 ▶ enc = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
enc = n ? SvREFCNT_inc(POPs) : NULL; 26 0 26
3268 26 PUTBACK;
3269 26 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 26 0 26
3270 26 SPAGAIN;
3271 26 ▶ if (fig) SvREFCNT_dec(fig);
Branch: 1 branch
BranchTrueFalseTotal
if (fig) SvREFCNT_dec(fig); 26 0 26
3272 26 ▶ if (enc) hv_stores(v, "scatter_plot", enc);
Branch: 1 branch
BranchTrueFalseTotal
if (enc) hv_stores(v, "scatter_plot", enc); 26 0 26
3273 }
3274 31 SvREFCNT_dec((SV *)pts);
3275  
3276 /* MORE BEYOND THIS PAGE. A full page's last trace is the
3277 * cursor for the next fifty; a short page IS the end, and a
3278 * "next" link there would page into nothing. From the raw result
3279 * rather than the formatted rows, because the cursor needs the
3280 * exact duration and the row carries "1.3s". The first version
3281 * of this block ran before `res` existed, on the store of an
3282 * empty placeholder - which is a segfault, and the reminder that
3283 * "after the assignment in the source" is not "after it runs". */
3284 {
3285 31 SV **tv2 = hv_fetchs(r, "traces", 0);
3286 31 ▶ if (tv2 && SvROK(*tv2) && SvTYPE(SvRV(*tv2)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (tv2 && SvROK(*tv2) && SvTYPE(SvRV(*tv2)) == SVt_PVAV) { 31 0 31
if (tv2 && SvROK(*tv2) && SvTYPE(SvRV(*tv2)) == SVt_PVAV) { 31 0 31
if (tv2 && SvROK(*tv2) && SvTYPE(SvRV(*tv2)) == SVt_PVAV) { 31 0 31
3287 31 AV *ta2 = (AV *)SvRV(*tv2);
3288 31 SSize_t n2 = av_len(ta2) + 1;
3289 31 ▶ if (n2 >= 50) {
Branch: 1 branch
BranchTrueFalseTotal
if (n2 >= 50) { 7 24 31
3290 7 SV **le = av_fetch(ta2, n2 - 1, 0);
3291 7 ▶ if (le && SvROK(*le)
Branch: 2 branches
BranchTrueFalseTotal
if (le && SvROK(*le) 7 0 7
if (le && SvROK(*le) 7 0 7
3292 7 ▶ && SvTYPE(SvRV(*le)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(*le)) == SVt_PVHV) { 7 0 7
3293 7 HV *lh = (HV *)SvRV(*le);
3294 7 SV **du = hv_fetchs(lh, "duration", 0);
3295 7 SV **hi2 = hv_fetchs(lh, "trace_hi", 0);
3296 7 SV **lo2 = hv_fetchs(lh, "trace_lo", 0);
3297 7 ▶ if (du && hi2 && lo2) {
Branch: 3 branches
BranchTrueFalseTotal
if (du && hi2 && lo2) { 7 0 7
if (du && hi2 && lo2) { 7 0 7
if (du && hi2 && lo2) { 7 0 7
3298 7 SV *cur = newSVsv(*du);
3299 7 sv_catpvs(cur, "-");
3300 7 sv_catsv(cur, *hi2);
3301 7 sv_catpvs(cur, "-");
3302 7 sv_catsv(cur, *lo2);
3303 7 hv_stores(v, "next_cursor", cur);
3304 }
3305 }
3306 }
3307 }
3308 }
3309 31 povw_set_iv(aTHX_ v, "span_count", r, "spans");
3310 31 povw_set_iv(aTHX_ v, "total", r, "total");
3311 31 hv_stores(v, "root_name", newSVpvs("Traces in this window"));
3312 }
3313 31 SvREFCNT_dec(res);
3314  
3315 34 done:
3316 34 RETVAL = newRV_noinc((SV *)v);
3317 40 out:
3318 40 SvREFCNT_dec(from); SvREFCNT_dec(to); SvREFCNT_dec(range);
3319 }
3320 OUTPUT:
3321 RETVAL
3322  
3323 # The service map.
3324 #
3325 # Services become symbols for the layout and names again for the drawing. The
3326 # layout works in numbers because a graph algorithm has no business comparing
3327 # strings; the page needs the names back or it draws the boxes the demo drew:
3328 # correctly placed and unlabelled.
3329 SV *
3330 povw__page_map(SV *class, SV *store, SV *req)
3331 CODE:
3332 {
3333 6 HV *v = newHV();
3334 6 AV *nodes_out = newAV(), *edges_out = newAV();
3335 6 SV *from = NULL, *to = NULL, *range = NULL;
3336 6 SV *gsv = NULL, *lay = NULL;
3337 6 AV *edges = NULL;
3338 6 HV *sym = newHV();
3339 6 AV *names = newAV();
3340 6 SSize_t ne = 0, i;
3341 6 double *px = NULL, *py = NULL;
3342 6 char *hasp = NULL;
3343 6 SSize_t nsym = 0;
3344  
3345 PERL_UNUSED_VAR(class);
3346 6 hv_stores(v, "heading", newSVpvs("Service map"));
3347 6 hv_stores(v, "title", newSVpvs("Service map"));
3348 6 hv_stores(v, "nodes", newRV_noinc((SV *)nodes_out));
3349 6 hv_stores(v, "edges", newRV_noinc((SV *)edges_out));
3350 6 hv_stores(v, "width", newSViv(POVW_CHART_W));
3351 6 hv_stores(v, "height", newSViv(POVW_CHART_H));
3352  
3353 6 range = povw_window_range(aTHX_ req, &from, &to);
3354 6 hv_stores(v, "from", newSVsv(from));
3355 6 hv_stores(v, "to", newSVsv(to));
3356 6 povw_range_vars(aTHX_ v, req, range);
3357  
3358 6 ▶ if (!SvOK(store) || !SvROK(store)) goto done;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(store) || !SvROK(store)) goto done; 6 0 6
if (!SvOK(store) || !SvROK(store)) goto done; 0 6 6
3359  
3360 {
3361 int n;
3362 6 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 6 6
3363 6 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 6 6
3364 6 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 6 6
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 6 6
3365 6 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 6 6
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 6 6
3366 6 PUTBACK;
3367 6 n = call_method("graph", G_SCALAR);
3368 6 SPAGAIN;
3369 6 ▶ gsv = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gsv = n ? SvREFCNT_inc(POPs) : NULL; 6 0 6
3370 6 PUTBACK;
3371 6 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 6 0 6
3372 6 SPAGAIN;
3373 }
3374 6 ▶ if (gsv && SvROK(gsv) && SvTYPE(SvRV(gsv)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (gsv && SvROK(gsv) && SvTYPE(SvRV(gsv)) == SVt_PVHV) { 6 0 6
if (gsv && SvROK(gsv) && SvTYPE(SvRV(gsv)) == SVt_PVHV) { 6 0 6
if (gsv && SvROK(gsv) && SvTYPE(SvRV(gsv)) == SVt_PVHV) { 6 0 6
3375 6 SV **e = hv_fetchs((HV *)SvRV(gsv), "edges", 0);
3376 6 ▶ if (e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 6 0 6
if (e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 6 0 6
if (e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 6 0 6
3377 6 edges = (AV *)SvRV(*e);
3378 }
3379 6 ▶ ne = edges ? av_len(edges) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ne = edges ? av_len(edges) + 1 : 0; 6 0 6
3380 6 ▶ if (!ne) { hv_stores(v, "empty", newSViv(1)); goto done; }
Branch: 1 branch
BranchTrueFalseTotal
if (!ne) { hv_stores(v, "empty", newSViv(1)); goto done; } 1 5 6
3381  
3382 15 ▶ for (i = 0; i < ne; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ne; i++) { 10 5 15
3383 10 SV **e = av_fetch(edges, i, 0);
3384 HV *eh;
3385 int end;
3386 10 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 10 0 10
if (!e || !SvROK(*e)) continue; 0 10 10
3387 10 eh = (HV *)SvRV(*e);
3388 30 ▶ for (end = 0; end < 2; end++) {
Branch: 1 branch
BranchTrueFalseTotal
for (end = 0; end < 2; end++) { 20 10 30
3389 10 SV **x = end ? hv_fetchs(eh, "callee", 0)
3390 20 ▶ : hv_fetchs(eh, "caller", 0);
Branch: 1 branch
BranchTrueFalseTotal
: hv_fetchs(eh, "caller", 0); 10 10 20
3391 STRLEN l;
3392 const char *p;
3393 30 ▶ if (!x || !SvOK(*x)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!x || !SvOK(*x)) continue; 20 0 20
if (!x || !SvOK(*x)) continue; 0 20 20
3394 20 p = SvPV(*x, l);
3395 20 ▶ if (l == 1 && *p == '*') continue;
Branch: 2 branches
BranchTrueFalseTotal
if (l == 1 && *p == '*') continue; 5 15 20
if (l == 1 && *p == '*') continue; 5 0 5
3396 15 ▶ if (hv_fetch(sym, p, (I32)l, 0)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (hv_fetch(sym, p, (I32)l, 0)) continue; 5 10 15
3397 10 (void)hv_store(sym, p, (I32)l, newSViv((IV)(av_len(names) + 1)), 0);
3398 10 av_push(names, newSVpvn(p, l));
3399 }
3400 }
3401 5 nsym = av_len(names) + 1;
3402  
3403 {
3404 5 AV *in = newAV();
3405 int n;
3406 15 ▶ for (i = 0; i < ne; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ne; i++) { 10 5 15
3407 10 SV **e = av_fetch(edges, i, 0);
3408 HV *eh, *o;
3409 SV **x;
3410 10 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 10 0 10
if (!e || !SvROK(*e)) continue; 0 10 10
3411 10 eh = (HV *)SvRV(*e);
3412 10 o = newHV();
3413 10 x = hv_fetchs(eh, "caller", 0);
3414 10 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 10 0 10
if (x && SvOK(*x)) { 10 0 10
3415 STRLEN l;
3416 10 const char *p = SvPV(*x, l);
3417 10 ▶ if (l == 1 && *p == '*') hv_stores(o, "caller", newSVpvs("*"));
Branch: 2 branches
BranchTrueFalseTotal
if (l == 1 && *p == '*') hv_stores(o, "caller", newSVpvs("*")); 5 5 10
if (l == 1 && *p == '*') hv_stores(o, "caller", newSVpvs("*")); 5 0 5
3418 else {
3419 5 SV **s2 = hv_fetch(sym, p, (I32)l, 0);
3420 5 ▶ hv_stores(o, "caller", s2 ? newSVsv(*s2) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "caller", s2 ? newSVsv(*s2) : newSV(0)); 5 0 5
3421 }
3422 }
3423 10 x = hv_fetchs(eh, "callee", 0);
3424 10 ▶ if (x && SvOK(*x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x && SvOK(*x)) { 10 0 10
if (x && SvOK(*x)) { 10 0 10
3425 STRLEN l;
3426 10 const char *p = SvPV(*x, l);
3427 10 SV **s2 = hv_fetch(sym, p, (I32)l, 0);
3428 10 ▶ hv_stores(o, "callee", s2 ? newSVsv(*s2) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "callee", s2 ? newSVsv(*s2) : newSV(0)); 10 0 10
3429 }
3430 10 x = hv_fetchs(eh, "count", 0);
3431 10 ▶ hv_stores(o, "count", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "count", x ? newSVsv(*x) : newSV(0)); 10 0 10
3432 10 x = hv_fetchs(eh, "errors", 0);
3433 10 ▶ hv_stores(o, "errors", x ? newSVsv(*x) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "errors", x ? newSVsv(*x) : newSV(0)); 10 0 10
3434 10 av_push(in, newRV_noinc((SV *)o));
3435 }
3436 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
3437 5 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV *)in)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV *)in))); 0 5 5
3438 5 PUTBACK;
3439 5 n = call_pv("Punk::Observe::Map::layout", G_SCALAR | G_EVAL);
3440 5 SPAGAIN;
3441 5 ▶ lay = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
lay = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
3442 5 PUTBACK;
3443 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
3444 5 SPAGAIN;
3445 5 ▶ if (SvTRUE(ERRSV) && lay) { SvREFCNT_dec(lay); lay = NULL; }
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV) && lay) { SvREFCNT_dec(lay); lay = NULL; } 5 0 5
if (SvTRUE(ERRSV) && lay) { SvREFCNT_dec(lay); lay = NULL; } 0 5 5
if (SvTRUE(ERRSV) && lay) { SvREFCNT_dec(lay); lay = NULL; } 0 0 0
3446 }
3447 5 ▶ if (!lay || !SvTRUE(lay) || !SvROK(lay)
Branch: 3 branches
BranchTrueFalseTotal
if (!lay || !SvTRUE(lay) || !SvROK(lay) 5 0 5
if (!lay || !SvTRUE(lay) || !SvROK(lay) 5 0 5
if (!lay || !SvTRUE(lay) || !SvROK(lay) 5 0 5
3448 5 ▶ || SvTYPE(SvRV(lay)) != SVt_PVHV) goto done;
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(lay)) != SVt_PVHV) goto done; 0 5 5
3449  
3450 {
3451 5 HV *lh = (HV *)SvRV(lay);
3452 5 SV **x = hv_fetchs(lh, "nodes", 0);
3453 5 ▶ AV *ln = (x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
AV *ln = (x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) 5 0 5
AV *ln = (x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) 5 0 5
3454 10 ▶ ? (AV *)SvRV(*x) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(*x) : NULL; 5 0 5
3455 5 ▶ SSize_t nn = ln ? av_len(ln) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t nn = ln ? av_len(ln) + 1 : 0; 5 0 5
3456 5 IV layers, tallest = 1;
3457 5 IV *per_layer = NULL, *slot = NULL;
3458 5 IV maxlayer = 0;
3459 5 double w = POVW_CHART_W, h, dx;
3460 SSize_t k;
3461  
3462 5 x = hv_fetchs(lh, "layers", 0);
3463 5 ▶ layers = (x && SvTRUE(*x)) ? SvIV(*x) : 1;
Branch: 2 branches
BranchTrueFalseTotal
layers = (x && SvTRUE(*x)) ? SvIV(*x) : 1; 5 0 5
layers = (x && SvTRUE(*x)) ? SvIV(*x) : 1; 5 0 5
3464  
3465 20 ▶ for (k = 0; k < nn; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < nn; k++) { 15 5 20
3466 15 SV **e = av_fetch(ln, k, 0);
3467 15 ▶ SV **l = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **l = (e && SvROK(*e)) 15 0 15
3468 30 ▶ ? hv_fetchs((HV *)SvRV(*e), "layer", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "layer", 0) : NULL; 15 0 15
3469 15 ▶ IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0;
Branch: 2 branches
BranchTrueFalseTotal
IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
3470 15 ▶ if (lv > maxlayer) maxlayer = lv;
Branch: 1 branch
BranchTrueFalseTotal
if (lv > maxlayer) maxlayer = lv; 10 5 15
3471 }
3472 5 ▶ Newxz(per_layer, maxlayer + 1, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(per_layer, maxlayer + 1, IV); 0 5 5
3473 5 ▶ Newxz(slot, maxlayer + 1, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(slot, maxlayer + 1, IV); 0 5 5
3474 20 ▶ for (k = 0; k < nn; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < nn; k++) { 15 5 20
3475 15 SV **e = av_fetch(ln, k, 0);
3476 15 ▶ SV **l = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **l = (e && SvROK(*e)) 15 0 15
3477 30 ▶ ? hv_fetchs((HV *)SvRV(*e), "layer", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "layer", 0) : NULL; 15 0 15
3478 15 ▶ IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0;
Branch: 2 branches
BranchTrueFalseTotal
IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
IV lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
3479 15 ▶ if (lv >= 0 && lv <= maxlayer) per_layer[lv]++;
Branch: 2 branches
BranchTrueFalseTotal
if (lv >= 0 && lv <= maxlayer) per_layer[lv]++; 15 0 15
if (lv >= 0 && lv <= maxlayer) per_layer[lv]++; 15 0 15
3480 }
3481 20 ▶ for (k = 0; k <= maxlayer; k++)
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k <= maxlayer; k++) 15 5 20
3482 15 ▶ if (per_layer[k] > tallest) tallest = per_layer[k];
Branch: 1 branch
BranchTrueFalseTotal
if (per_layer[k] > tallest) tallest = per_layer[k]; 0 15 15
3483  
3484 /* Layer and slot are a grid; this is the only place that turns
3485 * them into coordinates, so the layout stays a layout and the
3486 * geometry stays here. */
3487 5 h = (double)POVW_CHART_H;
3488 5 ▶ if ((double)(tallest * 62 + 40) > h) h = (double)(tallest * 62 + 40);
Branch: 1 branch
BranchTrueFalseTotal
if ((double)(tallest * 62 + 40) > h) h = (double)(tallest * 62 + 40); 0 5 5
3489 5 ▶ dx = layers > 1 ? (w - 140) / (double)(layers - 1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
dx = layers > 1 ? (w - 140) / (double)(layers - 1) : 0; 5 0 5
3490  
3491 5 ▶ Newxz(px, nsym + 1, double);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(px, nsym + 1, double); 0 5 5
3492 5 ▶ Newxz(py, nsym + 1, double);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(py, nsym + 1, double); 0 5 5
3493 5 Newxz(hasp, nsym + 1, char);
3494  
3495 20 ▶ for (k = 0; k < nn; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < nn; k++) { 15 5 20
3496 15 SV **e = av_fetch(ln, k, 0);
3497 HV *nh, *o;
3498 SV **svc, **l;
3499 IV lv, idx, count, islot;
3500 double nx, ny;
3501 int is_root;
3502 SV *nm;
3503  
3504 15 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 15 0 15
if (!e || !SvROK(*e)) continue; 0 15 15
3505 15 nh = (HV *)SvRV(*e);
3506 15 l = hv_fetchs(nh, "layer", 0);
3507 15 ▶ lv = (l && SvOK(*l)) ? SvIV(*l) : 0;
Branch: 2 branches
BranchTrueFalseTotal
lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
lv = (l && SvOK(*l)) ? SvIV(*l) : 0; 15 0 15
3508 15 ▶ count = (lv >= 0 && lv <= maxlayer && per_layer[lv])
Branch: 2 branches
BranchTrueFalseTotal
count = (lv >= 0 && lv <= maxlayer && per_layer[lv]) 15 0 15
count = (lv >= 0 && lv <= maxlayer && per_layer[lv]) 15 0 15
3509 30 ▶ ? per_layer[lv] : 1;
Branch: 1 branch
BranchTrueFalseTotal
? per_layer[lv] : 1; 15 0 15
3510 15 ▶ islot = (lv >= 0 && lv <= maxlayer) ? slot[lv]++ : 0;
Branch: 2 branches
BranchTrueFalseTotal
islot = (lv >= 0 && lv <= maxlayer) ? slot[lv]++ : 0; 15 0 15
islot = (lv >= 0 && lv <= maxlayer) ? slot[lv]++ : 0; 15 0 15
3511 15 nx = 70 + (double)lv * dx;
3512 15 ny = (h / (double)(count + 1)) * (double)(islot + 1);
3513  
3514 15 svc = hv_fetchs(nh, "service", 0);
3515 {
3516 15 STRLEN sl = 0;
3517 30 ▶ const char *sp = (svc && SvOK(*svc)) ? SvPV(*svc, sl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *sp = (svc && SvOK(*svc)) ? SvPV(*svc, sl) : ""; 15 0 15
const char *sp = (svc && SvOK(*svc)) ? SvPV(*svc, sl) : ""; 15 0 15
3518 15 ▶ is_root = (sl == 1 && *sp == '*');
Branch: 2 branches
BranchTrueFalseTotal
is_root = (sl == 1 && *sp == '*'); 15 0 15
is_root = (sl == 1 && *sp == '*'); 5 10 15
3519 15 ▶ if (is_root) { idx = nsym; nm = newSVpvs("internet"); }
Branch: 1 branch
BranchTrueFalseTotal
if (is_root) { idx = nsym; nm = newSVpvs("internet"); } 5 10 15
3520 else {
3521 SV **got;
3522 10 idx = SvIV(*svc);
3523 10 got = av_fetch(names, (SSize_t)idx, 0);
3524 10 ▶ nm = got ? newSVsv(*got) : newSVpvs("");
Branch: 1 branch
BranchTrueFalseTotal
nm = got ? newSVsv(*got) : newSVpvs(""); 10 0 10
3525 }
3526 }
3527 15 ▶ if (idx >= 0 && idx <= nsym) {
Branch: 2 branches
BranchTrueFalseTotal
if (idx >= 0 && idx <= nsym) { 15 0 15
if (idx >= 0 && idx <= nsym) { 15 0 15
3528 15 px[idx] = nx; py[idx] = ny; hasp[idx] = 1;
3529 }
3530  
3531 15 o = newHV();
3532 15 hv_stores(o, "name", nm);
3533 15 ▶ hv_stores(o, "service",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "service", 5 10 15
3534 is_root ? newSVpvs("") : newSVsv(nm));
3535 15 hv_stores(o, "x", povw_fixed(aTHX_ nx, 1));
3536 15 hv_stores(o, "y", povw_fixed(aTHX_ ny, 1));
3537 {
3538 char b[32];
3539 STRLEN cl;
3540 const char *cp;
3541 15 SV **c = hv_fetchs(nh, "in", 0);
3542 size_t bn;
3543 30 ▶ cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, "");
Branch: 2 branches
BranchTrueFalseTotal
cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, ""); 15 0 15
cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, ""); 15 0 15
3544 15 bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
3545 15 hv_stores(o, "in", newSVpvn(b, bn));
3546 15 c = hv_fetchs(nh, "out", 0);
3547 30 ▶ cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, "");
Branch: 2 branches
BranchTrueFalseTotal
cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, ""); 15 0 15
cp = (c && SvOK(*c)) ? SvPV(*c, cl) : (cl = 0, ""); 15 0 15
3548 15 bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
3549 15 hv_stores(o, "out", newSVpvn(b, bn));
3550 }
3551 {
3552 15 SV **er = hv_fetchs(nh, "errors", 0);
3553 15 ▶ int bad = er && SvTRUE(*er);
Branch: 2 branches
BranchTrueFalseTotal
int bad = er && SvTRUE(*er); 15 0 15
int bad = er && SvTRUE(*er); 5 10 15
3554 15 ▶ hv_stores(o, "errors", bad ? newSVsv(*er) : newSViv(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "errors", bad ? newSVsv(*er) : newSViv(0)); 5 10 15
3555 15 ▶ hv_stores(o, "state",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "state", 5 10 15
3556 bad ? newSVpvs("error") : newSVpvs("ok"));
3557 }
3558 15 hv_stores(o, "root", newSViv(is_root ? 1 : 0));
3559 15 av_push(nodes_out, newRV_noinc((SV *)o));
3560 }
3561 5 Safefree(per_layer); Safefree(slot);
3562  
3563 { /* An edge is drawn from the DEDUPLICATED graph the layout
3564 * saw, which is also what `back` indexes into. */
3565 5 HV *back = newHV();
3566 5 SV **bv = hv_fetchs(lh, "back", 0);
3567 5 po_u64 heaviest = 1;
3568  
3569 5 ▶ if (bv && SvROK(*bv) && SvTYPE(SvRV(*bv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (bv && SvROK(*bv) && SvTYPE(SvRV(*bv)) == SVt_PVAV) { 5 0 5
if (bv && SvROK(*bv) && SvTYPE(SvRV(*bv)) == SVt_PVAV) { 5 0 5
if (bv && SvROK(*bv) && SvTYPE(SvRV(*bv)) == SVt_PVAV) { 5 0 5
3570 5 AV *ba = (AV *)SvRV(*bv);
3571 5 SSize_t j, cnt = av_len(ba) + 1;
3572 5 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 0 5 5
3573 0 SV **e = av_fetch(ba, j, 0);
3574 0 ▶ if (e && SvOK(*e)) {
Branch: 2 branches
BranchTrueFalseTotal
if (e && SvOK(*e)) { 0 0 0
if (e && SvOK(*e)) { 0 0 0
3575 STRLEN kl;
3576 0 const char *kp = SvPV(*e, kl);
3577 0 (void)hv_store(back, kp, (I32)kl, newSViv(1), 0);
3578 }
3579 }
3580 }
3581 15 ▶ for (i = 0; i < ne; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ne; i++) { 10 5 15
3582 10 SV **e = av_fetch(edges, i, 0);
3583 10 ▶ SV **c = (e && SvROK(*e))
Branch: 1 branch
BranchTrueFalseTotal
SV **c = (e && SvROK(*e)) 10 0 10
3584 20 ▶ ? hv_fetchs((HV *)SvRV(*e), "count", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetchs((HV *)SvRV(*e), "count", 0) : NULL; 10 0 10
3585 10 po_u64 cv = 0;
3586 10 ▶ if (c) (void)po_sv_to_u64(aTHX_ *c, &cv);
Branch: 1 branch
BranchTrueFalseTotal
if (c) (void)po_sv_to_u64(aTHX_ *c, &cv); 10 0 10
3587 10 ▶ if (cv > heaviest) heaviest = cv;
Branch: 1 branch
BranchTrueFalseTotal
if (cv > heaviest) heaviest = cv; 5 5 10
3588 }
3589  
3590 15 ▶ for (i = 0; i < ne; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ne; i++) { 10 5 15
3591 10 SV **e = av_fetch(edges, i, 0);
3592 HV *eh, *o;
3593 SV **x2;
3594 10 IV ai = -1, bi = -1;
3595 double mx;
3596 10 po_u64 cv = 0;
3597 SV *caller_name, *callee_name;
3598 char b[32];
3599 size_t bn;
3600  
3601 10 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 10 0 10
if (!e || !SvROK(*e)) continue; 0 10 10
3602 10 eh = (HV *)SvRV(*e);
3603  
3604 10 x2 = hv_fetchs(eh, "caller", 0);
3605 10 ▶ if (x2 && SvOK(*x2)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x2 && SvOK(*x2)) { 10 0 10
if (x2 && SvOK(*x2)) { 10 0 10
3606 STRLEN l;
3607 10 const char *p = SvPV(*x2, l);
3608 10 ▶ if (l == 1 && *p == '*') ai = nsym;
Branch: 2 branches
BranchTrueFalseTotal
if (l == 1 && *p == '*') ai = nsym; 5 5 10
if (l == 1 && *p == '*') ai = nsym; 5 0 5
3609 else {
3610 5 SV **s2 = hv_fetch(sym, p, (I32)l, 0);
3611 5 ▶ if (s2) ai = SvIV(*s2);
Branch: 1 branch
BranchTrueFalseTotal
if (s2) ai = SvIV(*s2); 5 0 5
3612 }
3613 15 ▶ caller_name = (l == 1 && *p == '*')
Branch: 1 branch
BranchTrueFalseTotal
caller_name = (l == 1 && *p == '*') 5 0 5
3614 15 ▶ ? newSVpvs("internet") : newSVsv(*x2);
Branch: 1 branch
BranchTrueFalseTotal
? newSVpvs("internet") : newSVsv(*x2); 5 5 10
3615 }
3616 0 else caller_name = newSV(0);
3617  
3618 10 x2 = hv_fetchs(eh, "callee", 0);
3619 20 ▶ if (x2 && SvOK(*x2)) {
Branch: 2 branches
BranchTrueFalseTotal
if (x2 && SvOK(*x2)) { 10 0 10
if (x2 && SvOK(*x2)) { 10 0 10
3620 STRLEN l;
3621 10 const char *p = SvPV(*x2, l);
3622 10 SV **s2 = hv_fetch(sym, p, (I32)l, 0);
3623 10 ▶ if (s2) bi = SvIV(*s2);
Branch: 1 branch
BranchTrueFalseTotal
if (s2) bi = SvIV(*s2); 10 0 10
3624 10 callee_name = newSVsv(*x2);
3625 }
3626 0 else callee_name = newSV(0);
3627  
3628 /* A node the layout dropped takes its edges with it, and
3629 * the index still advances - `back` counts every edge,
3630 * not every drawn one. */
3631 10 ▶ if (ai < 0 || bi < 0 || ai > nsym || bi > nsym
Branch: 4 branches
BranchTrueFalseTotal
if (ai < 0 || bi < 0 || ai > nsym || bi > nsym 10 0 10
if (ai < 0 || bi < 0 || ai > nsym || bi > nsym 10 0 10
if (ai < 0 || bi < 0 || ai > nsym || bi > nsym 10 0 10
if (ai < 0 || bi < 0 || ai > nsym || bi > nsym 10 0 10
3632 10 ▶ || !hasp[ai] || !hasp[bi]) {
Branch: 2 branches
BranchTrueFalseTotal
|| !hasp[ai] || !hasp[bi]) { 10 0 10
|| !hasp[ai] || !hasp[bi]) { 0 10 10
3633 0 SvREFCNT_dec(caller_name);
3634 0 SvREFCNT_dec(callee_name);
3635 0 continue;
3636 }
3637  
3638 10 o = newHV();
3639 10 mx = (px[ai] + px[bi]) / 2;
3640 {
3641 10 SV *d = newSVpvs("M");
3642 char f2[32];
3643 size_t fn;
3644 10 fn = po_fmt(px[ai] + 52, f2); sv_catpvn(d, f2, fn);
3645 10 sv_catpvs(d, ",");
3646 10 fn = po_fmt(py[ai], f2); sv_catpvn(d, f2, fn);
3647 10 sv_catpvs(d, " C");
3648 10 fn = po_fmt(mx, f2); sv_catpvn(d, f2, fn);
3649 10 sv_catpvs(d, ",");
3650 10 fn = po_fmt(py[ai], f2); sv_catpvn(d, f2, fn);
3651 10 sv_catpvs(d, " ");
3652 10 fn = po_fmt(mx, f2); sv_catpvn(d, f2, fn);
3653 10 sv_catpvs(d, ",");
3654 10 fn = po_fmt(py[bi], f2); sv_catpvn(d, f2, fn);
3655 10 sv_catpvs(d, " ");
3656 10 fn = po_fmt(px[bi] - 52, f2); sv_catpvn(d, f2, fn);
3657 10 sv_catpvs(d, ",");
3658 10 fn = po_fmt(py[bi], f2); sv_catpvn(d, f2, fn);
3659 10 hv_stores(o, "path", d);
3660 }
3661 10 x2 = hv_fetchs(eh, "count", 0);
3662 10 ▶ if (x2) (void)po_sv_to_u64(aTHX_ *x2, &cv);
Branch: 1 branch
BranchTrueFalseTotal
if (x2) (void)po_sv_to_u64(aTHX_ *x2, &cv); 10 0 10
3663 10 hv_stores(o, "weight", povw_fixed(aTHX_
3664 1 + 4 * ((double)cv / (double)heaviest), 1));
3665 {
3666 char kb[32];
3667 10 size_t kn = (size_t)my_snprintf(kb, sizeof(kb),
3668 PO_IVf, (IV)i);
3669 10 hv_stores(o, "back",
3670 newSViv(hv_fetch(back, kb, (I32)kn, 0) ? 1 : 0));
3671 }
3672 10 x2 = hv_fetchs(eh, "errors", 0);
3673 10 ▶ hv_stores(o, "errors", x2 ? newSVsv(*x2) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "errors", x2 ? newSVsv(*x2) : newSV(0)); 10 0 10
3674 10 ▶ hv_stores(o, "state", (x2 && SvTRUE(*x2))
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(o, "state", (x2 && SvTRUE(*x2)) 10 0 10
hv_stores(o, "state", (x2 && SvTRUE(*x2)) 5 5 10
3675 ? newSVpvs("error") : newSVpvs("ok"));
3676 10 hv_stores(o, "caller", newSVsv(caller_name));
3677 10 hv_stores(o, "callee", newSVsv(callee_name));
3678 /* TWO KEYS, BECAUSE THEY ARE TWO THINGS.
3679 *
3680 * The table wants "62.6k" and the flow diagram wants
3681 * 62577. This used to store only the formatted string
3682 * under `count`, which is the same key the store's own
3683 * edges use for the number - so the Sankey numified
3684 * "62.6k" to 62.6, drew a link a thousandth of its real
3685 * width, and labelled it "62 calls, 3121 in error". */
3686 {
3687 10 STRLEN cl = 0;
3688 10 SV **c = hv_fetchs(eh, "count", 0);
3689 20 ▶ const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : ""; 10 0 10
const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : ""; 10 0 10
3690 10 bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
3691 10 ▶ hv_stores(o, "count", c ? newSVsv(*c) : newSViv(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "count", c ? newSVsv(*c) : newSViv(0)); 10 0 10
3692 }
3693 10 hv_stores(o, "count_label", newSVpvn(b, bn));
3694 {
3695 10 SV *lab = newSVsv(caller_name);
3696 10 sv_catpvs(lab, " to ");
3697 10 sv_catsv(lab, callee_name);
3698 10 sv_catpvs(lab, ", ");
3699 10 sv_catpvn(lab, b, bn);
3700 10 sv_catpvs(lab, " calls");
3701 10 hv_stores(o, "label", lab);
3702 }
3703 10 SvREFCNT_dec(caller_name);
3704 10 SvREFCNT_dec(callee_name);
3705 10 av_push(edges_out, newRV_noinc((SV *)o));
3706 }
3707 5 SvREFCNT_dec((SV *)back);
3708 }
3709  
3710 5 hv_stores(v, "width", newSViv((IV)w));
3711 5 hv_stores(v, "height", povw_fixed(aTHX_ h, 0));
3712 5 x = hv_fetchs(lh, "back_edges", 0);
3713 5 ▶ hv_stores(v, "back_edges",
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "back_edges", 5 0 5
hv_stores(v, "back_edges", 0 5 5
3714 (x && SvTRUE(*x)) ? newSVsv(*x) : newSViv(0));
3715 }
3716  
3717 /* HOW MUCH, beside what-calls-what. Edge width carries volume on the
3718 * map above, which works for two edges and not for eight: a
3719 * four-pixel stroke against a six-pixel one does not read as three to
3720 * two. A flow diagram makes the volume the geometry rather than a
3721 * hint about it.
3722 *
3723 * Built from the same deduplicated list the layout saw and the table
3724 * shows, so all three agree by construction. */
3725 5 ▶ if (av_len(edges_out) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(edges_out) >= 0) { 0 5 5
3726 5 SV *fig = NULL, *enc = NULL;
3727 int n;
3728 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
3729 5 ▶ XPUSHs(sv_2mortal(newRV_inc((SV *)edges_out)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV *)edges_out))); 0 5 5
3730 5 PUTBACK;
3731 5 n = call_pv("Punk::Observe::Plot::service_flow", G_SCALAR);
3732 5 SPAGAIN;
3733 5 ▶ fig = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
fig = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
3734 5 PUTBACK;
3735 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
3736 5 SPAGAIN;
3737  
3738 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
3739 5 ▶ XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0))); 0 5 5
XPUSHs(sv_2mortal(fig ? newSVsv(fig) : newSV(0))); 5 0 5
3740 5 PUTBACK;
3741 5 n = call_pv("Punk::Observe::Plot::encode", G_SCALAR);
3742 5 SPAGAIN;
3743 5 ▶ enc = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
enc = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
3744 5 PUTBACK;
3745 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
3746 5 SPAGAIN;
3747 5 ▶ if (fig) SvREFCNT_dec(fig);
Branch: 1 branch
BranchTrueFalseTotal
if (fig) SvREFCNT_dec(fig); 5 0 5
3748 5 ▶ if (enc) hv_stores(v, "flow_plot", enc);
Branch: 1 branch
BranchTrueFalseTotal
if (enc) hv_stores(v, "flow_plot", enc); 0 5 5
3749 }
3750  
3751 0 done:
3752 6 ▶ if (gsv) SvREFCNT_dec(gsv);
Branch: 1 branch
BranchTrueFalseTotal
if (gsv) SvREFCNT_dec(gsv); 6 0 6
3753 6 ▶ if (lay) SvREFCNT_dec(lay);
Branch: 1 branch
BranchTrueFalseTotal
if (lay) SvREFCNT_dec(lay); 5 1 6
3754 6 SvREFCNT_dec((SV *)sym);
3755 6 SvREFCNT_dec((SV *)names);
3756 6 SvREFCNT_dec(from); SvREFCNT_dec(to); SvREFCNT_dec(range);
3757 6 Safefree(px); Safefree(py); Safefree(hasp);
3758 6 RETVAL = newRV_noinc((SV *)v);
3759 }
3760 OUTPUT:
3761 RETVAL
3762  
3763 # The metrics screen.
3764 SV *
3765 povw__page_metrics(SV *class, SV *store, SV *req)
3766 CODE:
3767 {
3768 9 HV *v = newHV();
3769 9 HV *rq = NULL;
3770 SV **f;
3771 9 SV *from = NULL, *to = NULL, *range = NULL, *res = NULL;
3772 9 HV *r = NULL;
3773 9 const char *q = "";
3774 9 STRLEN ql = 0;
3775 9 int has_q = 0;
3776 SSize_t i;
3777  
3778 PERL_UNUSED_VAR(class);
3779 9 ▶ if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 9 0 9
if (SvROK(req) && SvTYPE(SvRV(req)) == SVt_PVHV) rq = (HV *)SvRV(req); 9 0 9
3780  
3781 9 hv_stores(v, "heading", newSVpvs("Metrics"));
3782 9 hv_stores(v, "title", newSVpvs("Metrics"));
3783 9 hv_stores(v, "series", newRV_noinc((SV *)newAV()));
3784 9 hv_stores(v, "yticks", newRV_noinc((SV *)newAV()));
3785 9 hv_stores(v, "groups", newRV_noinc((SV *)newAV()));
3786 9 hv_stores(v, "width", newSViv(POVW_CHART_W));
3787 9 hv_stores(v, "height", newSViv(POVW_CHART_H));
3788  
3789 9 ▶ if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) {
Branch: 3 branches
BranchTrueFalseTotal
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 9 0 9
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 5 4 9
if (rq && (f = hv_fetchs(rq, "q", 0)) && SvOK(*f)) { 5 0 5
3790 5 q = SvPV(*f, ql);
3791 5 hv_stores(v, "query", newSVsv(*f));
3792 }
3793 4 else hv_stores(v, "query", newSVpvs(""));
3794 {
3795 9 ▶ const char *e = (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f))
Branch: 2 branches
BranchTrueFalseTotal
const char *e = (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) 5 4 9
const char *e = (rq && (f = hv_fetchs(rq, "q", 0)) && SvTRUE(*f)) 5 0 5
3796 18 ▶ ? q : "";
Branch: 1 branch
BranchTrueFalseTotal
? q : ""; 9 0 9
3797 9 ▶ STRLEN el = (e == q) ? ql : 0;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN el = (e == q) ? ql : 0; 9 0 9
3798 char *esc;
3799 size_t en;
3800 9 Newx(esc, el * 3 + 1, char);
3801 9 en = po_url_esc(e, (size_t)el, esc, el * 3 + 1);
3802 9 hv_stores(v, "query_esc", newSVpvn(esc, en));
3803 9 Safefree(esc);
3804 }
3805  
3806 9 range = povw_window_range(aTHX_ req, &from, &to);
3807 9 hv_stores(v, "from", newSVsv(from));
3808 9 hv_stores(v, "to", newSVsv(to));
3809 9 povw_range_vars(aTHX_ v, req, range);
3810  
3811 9 ▶ if (!SvOK(store) || !SvROK(store)) goto done;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(store) || !SvROK(store)) goto done; 9 0 9
if (!SvOK(store) || !SvROK(store)) goto done; 0 9 9
3812  
3813 9 ▶ for (i = 0; i < (SSize_t)ql; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (SSize_t)ql; i++) 5 4 9
3814 5 ▶ if (!isSPACE((U8)q[i])) { has_q = 1; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (!isSPACE((U8)q[i])) { has_q = 1; break; } 5 0 5
3815  
3816 9 ▶ if (!has_q) {
Branch: 1 branch
BranchTrueFalseTotal
if (!has_q) { 4 5 9
3817 /* With no query, the page offers what there is. An empty chart
3818 * and an empty box is a dead end; a list of the metric names the
3819 * store has seen is the next click.
3820 *
3821 * `metric_names` tallies the names during the scan - it used to
3822 * be a records() call with no limit, which built a Perl hash
3823 * for up to half a million points to read one field back out of
3824 * each: the single largest read in the UI, for a list of a few
3825 * dozen names. */
3826 4 HV *seen = newHV();
3827 4 AV *out = newAV();
3828 4 SV *names_rv = NULL;
3829 int n;
3830  
3831 4 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 4 4
3832 4 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 4 4
3833 4 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 4 4
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 4 4
3834 4 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 4 4
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 4 4
3835 4 PUTBACK;
3836 4 n = call_method("metric_names", G_LIST);
3837 4 SPAGAIN;
3838 {
3839 SSize_t k;
3840 8 ▶ for (k = n - 1; k > 0; k--) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
for (k = n - 1; k > 0; k--) (void)POPs; 4 4 8
3841 4 ▶ names_rv = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
names_rv = n ? SvREFCNT_inc(POPs) : NULL; 4 0 4
3842 }
3843 4 PUTBACK;
3844 4 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 4 0 4
3845 4 SPAGAIN;
3846  
3847 4 ▶ if (names_rv && SvROK(names_rv)
Branch: 2 branches
BranchTrueFalseTotal
if (names_rv && SvROK(names_rv) 4 0 4
if (names_rv && SvROK(names_rv) 4 0 4
3848 4 ▶ && SvTYPE(SvRV(names_rv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(names_rv)) == SVt_PVHV) { 4 0 4
3849 4 SvREFCNT_dec((SV *)seen);
3850 4 seen = (HV *)SvRV(names_rv);
3851 4 (void)SvREFCNT_inc((SV *)seen);
3852 }
3853 4 ▶ if (names_rv) SvREFCNT_dec(names_rv);
Branch: 1 branch
BranchTrueFalseTotal
if (names_rv) SvREFCNT_dec(names_rv); 4 0 4
3854  
3855 { /* sorted, so the list does not reshuffle between two loads */
3856 4 SSize_t nk = 0, k;
3857 SV **keys;
3858 HE *he;
3859 4 hv_iterinit(seen);
3860 4 ▶ Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *);
Branch: 7 branches
BranchTrueFalseTotal
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 0 4 4
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 3 1 4
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 0 3 3
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 0 3 3
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 0 4 4
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 3 1 4
Newx(keys, HvUSEDKEYS(seen) ? HvUSEDKEYS(seen) : 1, SV *); 0 3 3
3861 7 ▶ while ((he = hv_iternext(seen)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(seen))) 3 4 7
3862 3 keys[nk++] = newSVsv(hv_iterkeysv(he));
3863 4 ▶ for (k = 1; k < nk; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 1; k < nk; k++) { 0 4 4
3864 0 SV *key = keys[k];
3865 SSize_t j;
3866 STRLEN kl;
3867 0 const char *kp = SvPV(key, kl);
3868 0 ▶ for (j = k - 1; j >= 0; j--) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = k - 1; j >= 0; j--) { 0 0 0
3869 STRLEN jl;
3870 0 const char *jp = SvPV(keys[j], jl);
3871 0 size_t m = jl < kl ? jl : kl;
3872 0 ▶ int c = m ? memcmp(jp, kp, m) : 0;
Branch: 1 branch
BranchTrueFalseTotal
int c = m ? memcmp(jp, kp, m) : 0; 0 0 0
3873 0 ▶ if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1);
Branch: 3 branches
BranchTrueFalseTotal
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
if (!c) c = jl == kl ? 0 : (jl < kl ? -1 : 1); 0 0 0
3874 0 ▶ if (c <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (c <= 0) break; 0 0 0
3875 0 keys[j + 1] = keys[j];
3876 }
3877 0 keys[j + 1] = key;
3878 }
3879 7 ▶ for (k = 0; k < nk; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < nk; k++) { 3 4 7
3880 3 HV *o = newHV();
3881 STRLEN kl;
3882 3 const char *kp = SvPV(keys[k], kl);
3883 3 SV **c = hv_fetch(seen, kp, (I32)kl, 0);
3884 char b[32];
3885 3 STRLEN cl = 0;
3886 6 ▶ const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : ""; 3 0 3
const char *cp = (c && SvOK(*c)) ? SvPV(*c, cl) : ""; 3 0 3
3887 3 size_t bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
3888 3 SV *link = newSVpvs("metric ");
3889 char *esc;
3890 size_t en;
3891  
3892 3 sv_catpvn(link, kp, kl);
3893 3 Newx(esc, SvCUR(link) * 3 + 1, char);
3894 3 en = po_url_esc(SvPVX(link), SvCUR(link), esc,
3895 3 SvCUR(link) * 3 + 1);
3896 3 hv_stores(o, "name", keys[k]);
3897 3 hv_stores(o, "count", newSVpvn(b, bn));
3898 3 hv_stores(o, "query", newSVpvn(esc, en));
3899 3 Safefree(esc);
3900 3 SvREFCNT_dec(link);
3901 3 av_push(out, newRV_noinc((SV *)o));
3902 }
3903 4 Safefree(keys);
3904 }
3905 4 SvREFCNT_dec((SV *)seen);
3906 4 hv_stores(v, "empty", newSViv(av_len(out) >= 0 ? 0 : 1));
3907 4 hv_stores(v, "names", newRV_noinc((SV *)out));
3908 4 goto done;
3909 }
3910  
3911 {
3912 int n;
3913 5 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 5 5
3914 5 ▶ XPUSHs(store);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(store); 0 5 5
3915 5 ▶ XPUSHs(sv_2mortal(newSVpvn(q, ql)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(q, ql))); 0 5 5
3916 5 ▶ XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("from"))); XPUSHs(sv_2mortal(newSVsv(from))); 0 5 5
3917 5 ▶ XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 5 5
XPUSHs(sv_2mortal(newSVpvs("to"))); XPUSHs(sv_2mortal(newSVsv(to))); 0 5 5
3918 5 PUTBACK;
3919 5 n = call_method(povw_read_method(aTHX_ store), G_SCALAR);
3920 5 SPAGAIN;
3921 5 ▶ res = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
res = n ? SvREFCNT_inc(POPs) : NULL; 5 0 5
3922 5 PUTBACK;
3923 5 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 5 0 5
3924 5 SPAGAIN;
3925 }
3926 5 ▶ if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 5 0 5
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 5 0 5
if (!res || !SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVHV) { 0 5 5
3927 0 ▶ if (res) SvREFCNT_dec(res);
Branch: 1 branch
BranchTrueFalseTotal
if (res) SvREFCNT_dec(res); 0 0 0
3928 0 goto done;
3929 }
3930 5 r = (HV *)SvRV(res);
3931  
3932 5 f = hv_fetchs(r, "ok", 0);
3933 5 ▶ if (!f || !SvTRUE(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!f || !SvTRUE(*f)) { 5 0 5
if (!f || !SvTRUE(*f)) { 1 4 5
3934 1 SV **e = hv_fetchs(r, "error", 0);
3935 1 SV **st = hv_fetchs(r, "stage", 0);
3936 2 ▶ const char *stage = (st && SvOK(*st)) ? SvPV_nolen(*st) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *stage = (st && SvOK(*st)) ? SvPV_nolen(*st) : ""; 1 0 1
const char *stage = (st && SvOK(*st)) ? SvPV_nolen(*st) : ""; 1 0 1
3937 1 ▶ hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e)
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 1 0 1
hv_stores(v, "error", (e && SvOK(*e)) ? newSVsv(*e) 1 0 1
3938 : newSVpvs("that query could not be run"));
3939 {
3940 1 SV **ht = hv_fetchs(r, "hint", 0);
3941 1 ▶ hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht))
Branch: 4 branches
BranchTrueFalseTotal
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 1 1
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 0 0 0
hv_stores(v, "hint", (ht && SvOK(*ht) && SvCUR(*ht)) 1 0 1
3942 ? newSVsv(*ht)
3943 : strEQ(stage, "parse")
3944 ? newSVpvs("Check the stage after the pipe.")
3945 : newSVpvs("Narrow the range or add a filter."));
3946 }
3947 /* A PLAN refusal is the planner saying no to a query that would
3948 * have run: it is a different message from a typo, and the page
3949 * says which one it was. */
3950 1 ▶ if (strEQ(stage, "plan") && e && SvOK(*e))
Branch: 3 branches
BranchTrueFalseTotal
if (strEQ(stage, "plan") && e && SvOK(*e)) 0 1 1
if (strEQ(stage, "plan") && e && SvOK(*e)) 0 0 0
if (strEQ(stage, "plan") && e && SvOK(*e)) 0 0 0
3951 0 hv_stores(v, "refusal", newSVsv(*e));
3952 1 SvREFCNT_dec(res);
3953 1 goto done;
3954 }
3955  
3956 4 hv_stores(v, "title", newSVpvn(q, ql));
3957 {
3958 4 SV **meta = hv_fetchs(r, "meta", 0);
3959 4 ▶ HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 4 0 4
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 4 0 4
3960 8 ▶ ? (HV *)SvRV(*meta) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*meta) : NULL; 4 0 4
3961 4 ▶ if (mh) {
Branch: 1 branch
BranchTrueFalseTotal
if (mh) { 4 0 4
3962 4 povw_set_count(aTHX_ v, "scanned", mh, "scanned_rows");
3963 4 f = hv_fetchs(mh, "exact", 0);
3964 4 ▶ hv_stores(v, "exact", f ? newSVsv(*f) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "exact", f ? newSVsv(*f) : newSV(0)); 4 0 4
3965 }
3966 else {
3967 0 hv_stores(v, "scanned", newSVpvs("0"));
3968 0 hv_stores(v, "exact", newSV(0));
3969 }
3970 }
3971  
3972 {
3973 4 SV **sh = hv_fetchs(r, "shape", 0);
3974 8 ▶ const char *shape = (sh && SvOK(*sh)) ? SvPV_nolen(*sh) : "";
Branch: 2 branches
BranchTrueFalseTotal
const char *shape = (sh && SvOK(*sh)) ? SvPV_nolen(*sh) : ""; 4 0 4
const char *shape = (sh && SvOK(*sh)) ? SvPV_nolen(*sh) : ""; 4 0 4
3975  
3976 4 ▶ if (strEQ(shape, "buckets")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(shape, "buckets")) { 3 1 4
3977 /* A BUCKETED ANSWER IS A LINE OVER TIME, and it is the only
3978 * kind of aggregate that is. Until `bucket` existed every
3979 * aggregate collapsed to one number per group, which is why
3980 * this screen drew a chart from raw points and a table from
3981 * everything else. */
3982 3 int rate = povw_q_rate(q, (size_t)ql);
3983 SV *args[5];
3984 SV *enc;
3985 3 args[0] = sv_2mortal(newSVsv(res));
3986 3 args[1] = sv_2mortal(newSVpvs("zero_fill"));
3987 /* ONLY A COUNT MAY BE ZERO-FILLED. An absent bucket saw no
3988 * rows, which is nought arrivals and an UNDEFINED
3989 * percentile. */
3990 3 ▶ args[2] = sv_2mortal(newSViv(
Branch: 2 branches
BranchTrueFalseTotal
args[2] = sv_2mortal(newSViv( 2 1 3
args[2] = sv_2mortal(newSViv( 1 1 2
3991 (povw_q_bucket(q, (size_t)ql) || rate) ? 1 : 0));
3992 3 args[3] = sv_2mortal(newSVpvs("unit"));
3993 3 ▶ args[4] = sv_2mortal(rate ? newSVpvs("per second")
Branch: 1 branch
BranchTrueFalseTotal
args[4] = sv_2mortal(rate ? newSVpvs("per second") 1 2 3
3994 : newSVpvs(""));
3995 3 enc = povw_plot_encode(aTHX_
3996 "Punk::Observe::Plot::timeseries", args, 5);
3997 3 ▶ if (enc) hv_stores(v, "series_plot", enc);
Branch: 1 branch
BranchTrueFalseTotal
if (enc) hv_stores(v, "series_plot", enc); 3 0 3
3998 {
3999 3 SV **sv = hv_fetchs(r, "series", 0);
4000 3 ▶ int any = sv && SvROK(*sv)
Branch: 1 branch
BranchTrueFalseTotal
int any = sv && SvROK(*sv) 3 0 3
4001 3 ▶ && SvTYPE(SvRV(*sv)) == SVt_PVAV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(*sv)) == SVt_PVAV 3 0 3
4002 6 ▶ && av_len((AV *)SvRV(*sv)) >= 0;
Branch: 2 branches
BranchTrueFalseTotal
&& av_len((AV *)SvRV(*sv)) >= 0; 3 0 3
&& av_len((AV *)SvRV(*sv)) >= 0; 3 0 3
4003 3 hv_stores(v, "empty", newSViv(any ? 0 : 1));
4004 }
4005 3 SvREFCNT_dec(res);
4006 3 goto done;
4007 }
4008  
4009 1 ▶ if (!strEQ(shape, "") && !strEQ(shape, "rows")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!strEQ(shape, "") && !strEQ(shape, "rows")) { 1 0 1
if (!strEQ(shape, "") && !strEQ(shape, "rows")) { 0 1 1
4010 /* AN AGGREGATE WITH NO TIME DIMENSION IS A BAR PER GROUP.
4011 * `p95 by http.route` is one number per route; drawn as a
4012 * line it would be a chart lying about having a shape, and
4013 * the bar chart says exactly what the answer is. */
4014 0 SV **gv = hv_fetchs(r, "groups", 0);
4015 0 ▶ AV *ga = (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
AV *ga = (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) 0 0 0
AV *ga = (gv && SvROK(*gv) && SvTYPE(SvRV(*gv)) == SVt_PVAV) 0 0 0
4016 0 ▶ ? (AV *)SvRV(*gv) : newAV();
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(*gv) : newAV(); 0 0 0
4017 0 AV *out = newAV();
4018 SV *args[1];
4019 SV *enc;
4020 0 SSize_t j, cnt = av_len(ga) + 1;
4021  
4022 0 args[0] = sv_2mortal(newRV_inc((SV *)ga));
4023 0 enc = povw_plot_encode(aTHX_
4024 "Punk::Observe::Plot::bars", args, 1);
4025 0 ▶ if (enc) hv_stores(v, "groups_plot", enc);
Branch: 1 branch
BranchTrueFalseTotal
if (enc) hv_stores(v, "groups_plot", enc); 0 0 0
4026  
4027 0 ▶ for (j = 0; j < cnt; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < cnt; j++) { 0 0 0
4028 0 SV **e = av_fetch(ga, j, 0);
4029 HV *gh, *o;
4030 SV **x;
4031 char b[32];
4032 0 STRLEN cl = 0;
4033 const char *cp;
4034 size_t bn;
4035  
4036 0 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 0 0 0
if (!e || !SvROK(*e)) continue; 0 0 0
4037 0 gh = (HV *)SvRV(*e);
4038 0 o = newHV();
4039 0 x = hv_fetchs(gh, "key", 0);
4040 0 ▶ hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x))
Branch: 3 branches
BranchTrueFalseTotal
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 0 0 0
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 0 0 0
hv_stores(o, "key", (x && SvOK(*x) && SvCUR(*x)) 0 0 0
4041 ? newSVsv(*x) : newSVpvs("(none)"));
4042 0 x = hv_fetchs(gh, "value", 0);
4043 0 ▶ hv_stores(o, "value",
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(o, "value", 0 0 0
4044 povw_fmt_value(aTHX_ x ? (double)SvNV(*x) : 0));
4045 0 x = hv_fetchs(gh, "count", 0);
4046 0 ▶ cp = (x && SvOK(*x)) ? SvPV(*x, cl) : "";
Branch: 2 branches
BranchTrueFalseTotal
cp = (x && SvOK(*x)) ? SvPV(*x, cl) : ""; 0 0 0
cp = (x && SvOK(*x)) ? SvPV(*x, cl) : ""; 0 0 0
4047 0 bn = po_fmt_count(cp, (size_t)cl, b, sizeof(b));
4048 0 hv_stores(o, "count", newSVpvn(b, bn));
4049 0 av_push(out, newRV_noinc((SV *)o));
4050 }
4051 0 hv_stores(v, "groups", newRV_noinc((SV *)out));
4052 0 SvREFCNT_dec(res);
4053 0 goto done;
4054 }
4055 }
4056  
4057 { /* Raw metric points. Each series is already a line over time - a
4058 * metric row carries its own instant - so this needs no
4059 * bucketing. */
4060 1 SV **rv = hv_fetchs(r, "rows", 0);
4061 1 SV *shaped = NULL;
4062 int n;
4063  
4064 1 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 1 1
4065 1 ▶ XPUSHs(sv_2mortal((rv && SvROK(*rv)) ? newSVsv(*rv)
Branch: 3 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal((rv && SvROK(*rv)) ? newSVsv(*rv) 0 1 1
XPUSHs(sv_2mortal((rv && SvROK(*rv)) ? newSVsv(*rv) 1 0 1
XPUSHs(sv_2mortal((rv && SvROK(*rv)) ? newSVsv(*rv) 1 0 1
4066 : newRV_noinc((SV *)newAV())));
4067 1 ▶ XPUSHs(req);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(req); 0 1 1
4068 1 PUTBACK;
4069 1 n = call_pv("Punk::Observe::View::_rows_as_series", G_SCALAR);
4070 1 SPAGAIN;
4071 1 ▶ shaped = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
shaped = n ? SvREFCNT_inc(POPs) : NULL; 1 0 1
4072 1 PUTBACK;
4073 1 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 1 0 1
4074 1 SPAGAIN;
4075  
4076 1 ▶ if (shaped && SvROK(shaped) && SvTYPE(SvRV(shaped)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (shaped && SvROK(shaped) && SvTYPE(SvRV(shaped)) == SVt_PVHV) { 1 0 1
if (shaped && SvROK(shaped) && SvTYPE(SvRV(shaped)) == SVt_PVHV) { 1 0 1
if (shaped && SvROK(shaped) && SvTYPE(SvRV(shaped)) == SVt_PVHV) { 1 0 1
4077 1 HV *sh = (HV *)SvRV(shaped);
4078 1 SV **fig = hv_fetchs(sh, "figure", 0);
4079 1 SV **leg = hv_fetchs(sh, "legend", 0);
4080  
4081 1 ▶ if (fig && SvTRUE(*fig)) {
Branch: 2 branches
BranchTrueFalseTotal
if (fig && SvTRUE(*fig)) { 1 0 1
if (fig && SvTRUE(*fig)) { 1 0 1
4082 1 SV *enc = NULL;
4083 1 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 1 1
4084 1 ▶ XPUSHs(sv_2mortal(newSVsv(*fig)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(*fig))); 0 1 1
4085 1 PUTBACK;
4086 1 n = call_pv("Punk::Observe::Plot::encode", G_SCALAR);
4087 1 SPAGAIN;
4088 1 ▶ enc = n ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
enc = n ? SvREFCNT_inc(POPs) : NULL; 1 0 1
4089 1 PUTBACK;
4090 1 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 1 0 1
4091 1 SPAGAIN;
4092 1 ▶ if (enc) hv_stores(v, "series_plot", enc);
Branch: 1 branch
BranchTrueFalseTotal
if (enc) hv_stores(v, "series_plot", enc); 1 0 1
4093 }
4094 1 ▶ if (leg) {
Branch: 1 branch
BranchTrueFalseTotal
if (leg) { 1 0 1
4095 1 ▶ int any = SvROK(*leg) && SvTYPE(SvRV(*leg)) == SVt_PVAV
Branch: 1 branch
BranchTrueFalseTotal
int any = SvROK(*leg) && SvTYPE(SvRV(*leg)) == SVt_PVAV 1 0 1
4096 2 ▶ && av_len((AV *)SvRV(*leg)) >= 0;
Branch: 2 branches
BranchTrueFalseTotal
&& av_len((AV *)SvRV(*leg)) >= 0; 1 0 1
&& av_len((AV *)SvRV(*leg)) >= 0; 1 0 1
4097 1 hv_stores(v, "series", newSVsv(*leg));
4098 1 hv_stores(v, "empty", newSViv(any ? 0 : 1));
4099 }
4100 }
4101 1 ▶ if (shaped) SvREFCNT_dec(shaped);
Branch: 1 branch
BranchTrueFalseTotal
if (shaped) SvREFCNT_dec(shaped); 1 0 1
4102 }
4103 {
4104 1 SV **meta = hv_fetchs(r, "meta", 0);
4105 1 ▶ HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 1 0 1
HV *mh = (meta && SvROK(*meta) && SvTYPE(SvRV(*meta)) == SVt_PVHV) 1 0 1
4106 2 ▶ ? (HV *)SvRV(*meta) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*meta) : NULL; 1 0 1
4107 1 ▶ SV **t = mh ? hv_fetchs(mh, "truncated", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **t = mh ? hv_fetchs(mh, "truncated", 0) : NULL; 1 0 1
4108 1 ▶ hv_stores(v, "truncated", t ? newSVsv(*t) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(v, "truncated", t ? newSVsv(*t) : newSV(0)); 1 0 1
4109 }
4110 1 SvREFCNT_dec(res);
4111  
4112 9 done:
4113 9 SvREFCNT_dec(from); SvREFCNT_dec(to); SvREFCNT_dec(range);
4114 9 RETVAL = newRV_noinc((SV *)v);
4115 }
4116 OUTPUT:
4117 RETVAL
« xs/plot.xs ↑ Summary include/punk_observe/po_otlp_in.h »