xs/svg.xs

filter: Statementstmt 100% 106 / 106 Branchbran 67.6% 69 / 102 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 84.1% 175 / 208 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk_observe/po_segio.h ↑ Summary include/punk_observe/po_intern.h »
1 MODULE = Punk::Observe PACKAGE = Punk::Observe::SVG PREFIX = posv_
2  
3 # --- the formatter, which is the point of po_svg.h --------------------------
4  
5 SV *
6 posv_fmt(double v)
7 CODE:
8 {
9 char b[32];
10 2023 size_t n = po_fmt(v, b);
11 2023 RETVAL = newSVpvn(b, n);
12 }
13 OUTPUT:
14 RETVAL
15  
16 SV *
17 posv_esc_attr(SV *in)
18 CODE:
19 {
20 STRLEN len;
21 const char *p;
22 char out[PO_SVG_MAX];
23 size_t n;
24 9 p = SvPV(in, len);
25 9 n = po_esc_attr(p, (size_t)len, out, sizeof(out));
26 9 RETVAL = newSVpvn(out, n);
27 }
28 OUTPUT:
29 RETVAL
30  
31 # --- axes -------------------------------------------------------------------
32  
33 void
34 posv_axis(double min, double max, int want)
35 PPCODE:
36 {
37 po_axis a;
38 11 HV *res = newHV();
39 11 AV *ticks = newAV();
40 int i;
41 11 po_axis_make(&a, min, max, want);
42 88 ▶ for (i = 0; i < a.n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < a.n; i++) { 77 11 88
43 char b[32];
44 77 size_t n = po_fmt(a.tick[i], b);
45 77 av_push(ticks, newSVpvn(b, n));
46 }
47 11 hv_stores(res, "ticks", newRV_noinc((SV *)ticks));
48 11 hv_stores(res, "lo", newSVnv((NV)a.lo));
49 11 hv_stores(res, "hi", newSVnv((NV)a.hi));
50 11 hv_stores(res, "step", newSVnv((NV)a.step));
51 11 hv_stores(res, "n", newSViv(a.n));
52 11 ▶ mXPUSHs(newRV_noinc((SV *)res));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_noinc((SV *)res)); 0 11 11
53 }
54  
55 # --- a line path ------------------------------------------------------------
56  
57 SV *
58 posv_line(SV *xs, SV *ys, double w, double h)
59 CODE:
60 {
61 AV *ax, *ay;
62 SSize_t n, i;
63 3 double *x, *y, x0 = 0, x1 = 0, y0 = 0, y1 = 0;
64 po_svg s;
65  
66 3 ▶ if (!SvROK(xs) || !SvROK(ys)) croak("arrayrefs required");
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(xs) || !SvROK(ys)) croak("arrayrefs required"); 3 0 3
if (!SvROK(xs) || !SvROK(ys)) croak("arrayrefs required"); 0 3 3
67 3 ax = (AV *)SvRV(xs); ay = (AV *)SvRV(ys);
68 3 n = av_len(ax) + 1;
69 3 ▶ Newxz(x, n ? n : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newxz(x, n ? n : 1, double); 3 0 3
Newxz(x, n ? n : 1, double); 0 3 3
Newxz(x, n ? n : 1, double); 3 0 3
70 3 ▶ Newxz(y, n ? n : 1, double);
Branch: 3 branches
BranchTrueFalseTotal
Newxz(y, n ? n : 1, double); 3 0 3
Newxz(y, n ? n : 1, double); 0 3 3
Newxz(y, n ? n : 1, double); 3 0 3
71 11 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 8 3 11
72 8 SV **a = av_fetch(ax, i, 0);
73 8 SV **b = av_fetch(ay, i, 0);
74 8 ▶ x[i] = a ? SvNV(*a) : 0;
Branch: 1 branch
BranchTrueFalseTotal
x[i] = a ? SvNV(*a) : 0; 8 0 8
75 8 ▶ y[i] = b ? SvNV(*b) : 0;
Branch: 1 branch
BranchTrueFalseTotal
y[i] = b ? SvNV(*b) : 0; 8 0 8
76 8 ▶ if (i == 0 || x[i] < x0) x0 = x[i];
Branch: 2 branches
BranchTrueFalseTotal
if (i == 0 || x[i] < x0) x0 = x[i]; 5 3 8
if (i == 0 || x[i] < x0) x0 = x[i]; 0 5 5
77 8 ▶ if (i == 0 || x[i] > x1) x1 = x[i];
Branch: 2 branches
BranchTrueFalseTotal
if (i == 0 || x[i] > x1) x1 = x[i]; 5 3 8
if (i == 0 || x[i] > x1) x1 = x[i]; 5 0 5
78 8 ▶ if (i == 0 || y[i] < y0) y0 = y[i];
Branch: 2 branches
BranchTrueFalseTotal
if (i == 0 || y[i] < y0) y0 = y[i]; 5 3 8
if (i == 0 || y[i] < y0) y0 = y[i]; 0 5 5
79 8 ▶ if (i == 0 || y[i] > y1) y1 = y[i];
Branch: 2 branches
BranchTrueFalseTotal
if (i == 0 || y[i] > y1) y1 = y[i]; 5 3 8
if (i == 0 || y[i] > y1) y1 = y[i]; 2 3 5
80 }
81 3 ▶ if (!po_svg_init(&s, 256)) { Safefree(x); Safefree(y); croak("oom"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!po_svg_init(&s, 256)) { Safefree(x); Safefree(y); croak("oom"); } 0 3 3
82 3 po_svg_line(&s, x, y, (int)n, x0, x1, y0, y1, w, h);
83 3 RETVAL = newSVpvn(s.b, s.n);
84 3 po_svg_free(&s);
85 3 Safefree(x); Safefree(y);
86 }
87 OUTPUT:
88 RETVAL
89  
90 MODULE = Punk::Observe PACKAGE = Punk::Observe::Map PREFIX = pomap_
91  
92 # Lay a service graph out. Edges are (caller, callee, count, errors).
93 void
94 pomap_layout(SV *edges)
95 PPCODE:
96 {
97 po_sgraph g;
98 po_map m;
99 AV *av;
100 SSize_t i, n;
101 14 AV *nodes = newAV();
102 14 AV *backs = newAV();
103  
104 14 ▶ if (!SvROK(edges)) croak("arrayref required");
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(edges)) croak("arrayref required"); 0 14 14
105 14 av = (AV *)SvRV(edges);
106 14 n = av_len(av) + 1;
107 14 ▶ if (!po_sgraph_init(&g)) croak("oom");
Branch: 1 branch
BranchTrueFalseTotal
if (!po_sgraph_init(&g)) croak("oom"); 0 14 14
108  
109 47 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 33 14 47
110 33 SV **e = av_fetch(av, i, 0);
111 HV *h; SV **f;
112 po_edge *ed;
113 33 uint32_t caller = PO_SVC_UNKNOWN, callee = 0;
114 33 ▶ if (!e || !SvROK(*e)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !SvROK(*e)) continue; 33 0 33
if (!e || !SvROK(*e)) continue; 0 33 33
115 33 h = (HV *)SvRV(*e);
116 33 ▶ if ((f = hv_fetchs(h, "caller", 0)) && SvOK(*f)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((f = hv_fetchs(h, "caller", 0)) && SvOK(*f)) { 33 0 33
if ((f = hv_fetchs(h, "caller", 0)) && SvOK(*f)) { 33 0 33
117 33 STRLEN l; const char *p = SvPV(*f, l);
118 33 ▶ if (!(l == 1 && p[0] == '*')) caller = (uint32_t)SvUV(*f);
Branch: 2 branches
BranchTrueFalseTotal
if (!(l == 1 && p[0] == '*')) caller = (uint32_t)SvUV(*f); 33 0 33
if (!(l == 1 && p[0] == '*')) caller = (uint32_t)SvUV(*f); 21 12 33
119 }
120 33 ▶ if ((f = hv_fetchs(h, "callee", 0))) callee = (uint32_t)SvUV(*f);
Branch: 1 branch
BranchTrueFalseTotal
if ((f = hv_fetchs(h, "callee", 0))) callee = (uint32_t)SvUV(*f); 33 0 33
121 33 ed = po_sgraph_find(&g, caller, callee);
122 33 ▶ if (!ed) { po_sgraph_free(&g); croak("oom"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!ed) { po_sgraph_free(&g); croak("oom"); } 0 33 33
123 33 ▶ if ((f = hv_fetchs(h, "count", 0))) ed->count += SvUV(*f);
Branch: 1 branch
BranchTrueFalseTotal
if ((f = hv_fetchs(h, "count", 0))) ed->count += SvUV(*f); 33 0 33
124 33 ▶ if ((f = hv_fetchs(h, "errors", 0))) ed->errors += SvUV(*f);
Branch: 1 branch
BranchTrueFalseTotal
if ((f = hv_fetchs(h, "errors", 0))) ed->errors += SvUV(*f); 12 21 33
125 }
126  
127 14 ▶ if (!po_map_layout(&m, &g)) { po_sgraph_free(&g); croak("layout"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!po_map_layout(&m, &g)) { po_sgraph_free(&g); croak("layout"); } 0 14 14
128  
129 56 ▶ for (i = 0; i < m.n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < m.n; i++) { 42 14 56
130 42 HV *h = newHV();
131 42 ▶ hv_stores(h, "service", m.node[i].service == PO_SVC_UNKNOWN
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(h, "service", m.node[i].service == PO_SVC_UNKNOWN 10 32 42
132 ? newSVpvs("*") : newSVuv((UV)m.node[i].service));
133 42 hv_stores(h, "layer", newSViv(m.node[i].layer));
134 42 hv_stores(h, "slot", newSViv(m.node[i].slot));
135 42 hv_stores(h, "in", po_u64_to_sv(m.node[i].in_count));
136 42 hv_stores(h, "out", po_u64_to_sv(m.node[i].out_count));
137 42 hv_stores(h, "errors", po_u64_to_sv(m.node[i].errors));
138 42 av_push(nodes, newRV_noinc((SV *)h));
139 }
140 47 ▶ for (i = 0; i < (SSize_t)g.n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (SSize_t)g.n; i++) 33 14 47
141 33 ▶ if (po_map_is_back_edge(&m, g.e[i].caller, g.e[i].callee))
Branch: 1 branch
BranchTrueFalseTotal
if (po_map_is_back_edge(&m, g.e[i].caller, g.e[i].callee)) 3 30 33
142 3 av_push(backs, newSViv((IV)i));
143  
144 {
145 14 HV *res = newHV();
146 14 hv_stores(res, "nodes", newRV_noinc((SV *)nodes));
147 14 hv_stores(res, "layers", newSViv(m.layer_count));
148 14 hv_stores(res, "back_edges", newSViv(m.back_edges));
149 14 hv_stores(res, "back", newRV_noinc((SV *)backs));
150 14 ▶ mXPUSHs(newRV_noinc((SV *)res));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_noinc((SV *)res)); 0 14 14
151 }
152 14 po_sgraph_free(&g);
153 }
154  
155 MODULE = Punk::Observe PACKAGE = Punk::Observe::Flame PREFIX = pofl_
156  
157 # Build an aggregated self-time tree from spans.
158 void
159 pofl_build(SV *specs)
160 PPCODE:
161 {
162 po_span_w w;
163 po_flame fl;
164 10 AV *out = newAV();
165 uint32_t i;
166  
167 10 ▶ if (!po_span_w_init(&w)) croak("oom");
Branch: 1 branch
BranchTrueFalseTotal
if (!po_span_w_init(&w)) croak("oom"); 0 10 10
168 10 ▶ if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } 0 10 10
169 10 po_span_w_seal(&w);
170 10 ▶ if (!po_flame_init(&fl)) { po_span_w_free(&w); croak("oom"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!po_flame_init(&fl)) { po_span_w_free(&w); croak("oom"); } 0 10 10
171  
172 { /* one trace at a time, as the compactor does */
173 10 uint32_t a = 0;
174 29 ▶ while (a < w.n) {
Branch: 1 branch
BranchTrueFalseTotal
while (a < w.n) { 19 10 29
175 19 uint32_t b = a + 1;
176 po_tree t;
177 52 ▶ while (b < w.n && w.s[b].trace_hi == w.s[a].trace_hi
Branch: 1 branch
BranchTrueFalseTotal
while (b < w.n && w.s[b].trace_hi == w.s[a].trace_hi 24 9 33
178 43 ▶ && w.s[b].trace_lo == w.s[a].trace_lo) b++;
Branch: 2 branches
BranchTrueFalseTotal
&& w.s[b].trace_lo == w.s[a].trace_lo) b++; 33 10 43
&& w.s[b].trace_lo == w.s[a].trace_lo) b++; 24 0 24
179 19 ▶ if (po_tree_build(&t, w.s + a, b - a)) {
Branch: 1 branch
BranchTrueFalseTotal
if (po_tree_build(&t, w.s + a, b - a)) { 19 0 19
180 19 po_flame_add(&fl, w.s + a, b - a, &t);
181 19 po_tree_free(&t);
182 }
183 19 a = b;
184 }
185 }
186  
187 35 ▶ for (i = 0; i < fl.n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < fl.n; i++) { 25 10 35
188 25 HV *h = newHV();
189 25 hv_stores(h, "name", newSVuv((UV)fl.f[i].name_sym));
190 25 hv_stores(h, "service", newSVuv((UV)fl.f[i].service_sym));
191 25 hv_stores(h, "parent", newSViv((IV)fl.f[i].parent));
192 25 hv_stores(h, "depth", newSViv((IV)fl.f[i].depth));
193 25 hv_stores(h, "total", po_u64_to_sv(fl.f[i].total));
194 25 hv_stores(h, "self", po_u64_to_sv(fl.f[i].self));
195 25 hv_stores(h, "count", po_u64_to_sv(fl.f[i].count));
196 25 av_push(out, newRV_noinc((SV *)h));
197 }
198 {
199 10 HV *res = newHV();
200 10 hv_stores(res, "frames", newRV_noinc((SV *)out));
201 10 hv_stores(res, "total_self", po_u64_to_sv(po_flame_total_self(&fl)));
202 10 ▶ mXPUSHs(newRV_noinc((SV *)res));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_noinc((SV *)res)); 0 10 10
203 }
204 10 po_flame_free(&fl);
205 10 po_span_w_free(&w);
206 }
« include/punk_observe/po_segio.h ↑ Summary include/punk_observe/po_intern.h »