| 1 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Trace PREFIX = pot_ |
| 2 |
|
| |
| 3 |
|
| UV |
| 4 |
|
| pot_span_size(...) |
| 5 |
|
| CODE: |
| 6 |
1 |
▶ | RETVAL = (UV)sizeof(po_span); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)sizeof(po_span); |
0 |
1 |
1 |
|
| 7 |
|
| OUTPUT: |
| 8 |
|
| RETVAL |
| 9 |
|
| |
| 10 |
|
| |
| 11 |
|
| # --- the whole pipeline in one call ---------------------------------------- |
| 12 |
|
| # |
| 13 |
|
| # Add spans, seal (which sorts), index, summarise, graph. Returns everything a |
| 14 |
|
| # test needs to assert against, so no intermediate has to be trusted. |
| 15 |
|
| void |
| 16 |
|
| pot_analyse(SV *specs) |
| 17 |
|
| PPCODE: |
| 18 |
|
| { |
| 19 |
|
| po_span_w w; |
| 20 |
|
| po_traceidx idx; |
| 21 |
|
| po_tsum_set sums; |
| 22 |
|
| po_sgraph g; |
| 23 |
|
| HV *res; |
| 24 |
|
| |
| 25 |
16 |
▶ | if (!po_span_w_init(&w)) croak("oom"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_span_w_init(&w)) croak("oom"); |
0 |
16 |
16 |
|
| 26 |
16 |
▶ | if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
0 |
16 |
16 |
|
| 27 |
16 |
| po_span_w_seal(&w); |
| 28 |
|
| |
| 29 |
16 |
▶ | if (!po_traceidx_build(&idx, w.s, (uint32_t)w.n)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_traceidx_build(&idx, w.s, (uint32_t)w.n)) { |
0 |
16 |
16 |
|
| 30 |
0 |
| po_span_w_free(&w); croak("index"); |
| 31 |
|
| } |
| 32 |
16 |
▶ | if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
16 |
0 |
16 |
| if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
16 |
0 |
16 |
|
| 33 |
16 |
▶ | || !po_tsum_index(&sums)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !po_tsum_index(&sums)) { |
0 |
16 |
16 |
|
| 34 |
0 |
| po_traceidx_free(&idx); po_span_w_free(&w); croak("summaries"); |
| 35 |
|
| } |
| 36 |
16 |
▶ | if (!po_sgraph_init(&g) || !po_sgraph_build(&g, w.s, (uint32_t)w.n)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!po_sgraph_init(&g) || !po_sgraph_build(&g, w.s, (uint32_t)w.n)) { |
16 |
0 |
16 |
| if (!po_sgraph_init(&g) || !po_sgraph_build(&g, w.s, (uint32_t)w.n)) { |
0 |
16 |
16 |
|
| 37 |
0 |
| po_tsum_free(&sums); po_traceidx_free(&idx); |
| 38 |
0 |
| po_span_w_free(&w); croak("graph"); |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
16 |
| res = newHV(); |
| 42 |
16 |
| hv_stores(res, "spans", newSVuv((UV)w.n)); |
| 43 |
16 |
| hv_stores(res, "traces", newSVuv((UV)sums.n)); |
| 44 |
16 |
| hv_stores(res, "slots", newSVuv((UV)idx.slots)); |
| 45 |
16 |
| hv_stores(res, "clamped", newSVuv((UV)w.clamped)); |
| 46 |
16 |
| hv_stores(res, "any_error", newSViv(w.any_error)); |
| 47 |
16 |
▶ | hv_stores(res, "t_min", po_u64_to_sv(w.n ? w.t_min : 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_stores(res, "t_min", po_u64_to_sv(w.n ? w.t_min : 0)); |
15 |
1 |
16 |
|
| 48 |
16 |
| hv_stores(res, "t_max", po_u64_to_sv(w.t_max)); |
| 49 |
16 |
| hv_stores(res, "dur_max", po_u64_to_sv(w.dur_max)); |
| 50 |
|
| |
| 51 |
|
| { /* summaries, in duration order */ |
| 52 |
16 |
| AV *by = newAV(); |
| 53 |
|
| uint32_t i; |
| 54 |
278 |
▶ | for (i = 0; i < sums.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < sums.n; i++) { |
262 |
16 |
278 |
|
| 55 |
262 |
| const po_tsummary *t = &sums.t[sums.by_dur[i]]; |
| 56 |
262 |
| HV *h = newHV(); |
| 57 |
262 |
| hv_stores(h, "trace_hi", po_u64_to_sv(t->trace_hi)); |
| 58 |
262 |
| hv_stores(h, "trace_lo", po_u64_to_sv(t->trace_lo)); |
| 59 |
262 |
| hv_stores(h, "duration", po_u64_to_sv(t->dur_ns)); |
| 60 |
262 |
| hv_stores(h, "spans", newSVuv((UV)t->spans)); |
| 61 |
262 |
| hv_stores(h, "errors", newSVuv((UV)t->errors)); |
| 62 |
262 |
| hv_stores(h, "root_service", newSVuv((UV)t->root_service_sym)); |
| 63 |
262 |
| av_push(by, newRV_noinc((SV *)h)); |
| 64 |
|
| } |
| 65 |
16 |
| hv_stores(res, "by_duration", newRV_noinc((SV *)by)); |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
|
| { /* the service graph */ |
| 69 |
16 |
| AV *edges = newAV(); |
| 70 |
|
| uint32_t i; |
| 71 |
48 |
▶ | for (i = 0; i < g.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < g.n; i++) { |
32 |
16 |
48 |
|
| 72 |
32 |
| HV *h = newHV(); |
| 73 |
32 |
▶ | hv_stores(h, "caller", g.e[i].caller == PO_SVC_UNKNOWN |
Branch: 1 branch
| Branch | True | False | Total |
| hv_stores(h, "caller", g.e[i].caller == PO_SVC_UNKNOWN |
14 |
18 |
32 |
|
| 74 |
|
| ? newSVpvs("*") : newSVuv((UV)g.e[i].caller)); |
| 75 |
32 |
| hv_stores(h, "callee", newSVuv((UV)g.e[i].callee)); |
| 76 |
32 |
| hv_stores(h, "count", po_u64_to_sv(g.e[i].count)); |
| 77 |
32 |
| hv_stores(h, "errors", po_u64_to_sv(g.e[i].errors)); |
| 78 |
32 |
| hv_stores(h, "dur_max", po_u64_to_sv(g.e[i].dur_max)); |
| 79 |
32 |
| av_push(edges, newRV_noinc((SV *)h)); |
| 80 |
|
| } |
| 81 |
16 |
| hv_stores(res, "edges", newRV_noinc((SV *)edges)); |
| 82 |
|
| } |
| 83 |
|
| |
| 84 |
|
| { /* the assembled tree of the FIRST trace */ |
| 85 |
16 |
| AV *tree = newAV(); |
| 86 |
16 |
▶ | if (w.n) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (w.n) { |
15 |
1 |
16 |
|
| 87 |
15 |
| uint32_t j = 1; |
| 88 |
|
| po_tree t; |
| 89 |
88 |
▶ | while (j < w.n && w.s[j].trace_hi == w.s[0].trace_hi |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < w.n && w.s[j].trace_hi == w.s[0].trace_hi |
70 |
3 |
73 |
|
| 90 |
85 |
▶ | && w.s[j].trace_lo == w.s[0].trace_lo) j++; |
Branch: 2 branches
| Branch | True | False | Total |
| && w.s[j].trace_lo == w.s[0].trace_lo) j++; |
73 |
12 |
85 |
| && w.s[j].trace_lo == w.s[0].trace_lo) j++; |
70 |
0 |
70 |
|
| 91 |
15 |
▶ | if (po_tree_build(&t, w.s, j)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_tree_build(&t, w.s, j)) { |
15 |
0 |
15 |
|
| 92 |
|
| uint32_t i; |
| 93 |
100 |
▶ | for (i = 0; i < t.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < t.n; i++) { |
85 |
15 |
100 |
|
| 94 |
85 |
| HV *h = newHV(); |
| 95 |
85 |
| hv_stores(h, "span_id", po_u64_to_sv(w.s[i].span_id)); |
| 96 |
85 |
| hv_stores(h, "parent_index", newSViv((IV)t.parent[i])); |
| 97 |
85 |
| hv_stores(h, "depth", newSViv((IV)t.depth[i])); |
| 98 |
85 |
| av_push(tree, newRV_noinc((SV *)h)); |
| 99 |
|
| } |
| 100 |
15 |
| hv_stores(res, "roots", newSVuv((UV)t.roots)); |
| 101 |
15 |
| hv_stores(res, "cycles", newSVuv((UV)t.cycles)); |
| 102 |
15 |
| hv_stores(res, "orphans", newSVuv((UV)t.orphans)); |
| 103 |
15 |
| po_tree_free(&t); |
| 104 |
|
| } |
| 105 |
|
| } |
| 106 |
16 |
| hv_stores(res, "tree", newRV_noinc((SV *)tree)); |
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
16 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
16 |
16 |
|
| 110 |
16 |
| po_sgraph_free(&g); |
| 111 |
16 |
| po_tsum_free(&sums); |
| 112 |
16 |
| po_traceidx_free(&idx); |
| 113 |
16 |
| po_span_w_free(&w); |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| # --- the trace-id index, on its own ---------------------------------------- |
| 117 |
|
| |
| 118 |
|
| # Insert n traces, then look every one up, plus some absent ones. Reports the |
| 119 |
|
| # average probe count, which is the assertion that the table has not |
| 120 |
|
| # degenerated into a scan. |
| 121 |
|
| void |
| 122 |
|
| pot_index_probe(SV *specs, SV *lookups) |
| 123 |
|
| PPCODE: |
| 124 |
|
| { |
| 125 |
|
| po_span_w w; |
| 126 |
|
| po_traceidx idx; |
| 127 |
|
| AV *lk; |
| 128 |
|
| SSize_t i, n; |
| 129 |
5 |
| uint32_t found = 0, missing = 0; |
| 130 |
5 |
| AV *hits = newAV(); |
| 131 |
|
| |
| 132 |
5 |
▶ | if (!po_span_w_init(&w)) croak("oom"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_span_w_init(&w)) croak("oom"); |
0 |
5 |
5 |
|
| 133 |
5 |
▶ | if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
0 |
5 |
5 |
|
| 134 |
5 |
| po_span_w_seal(&w); |
| 135 |
5 |
▶ | if (!po_traceidx_build(&idx, w.s, (uint32_t)w.n)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_traceidx_build(&idx, w.s, (uint32_t)w.n)) { |
0 |
5 |
5 |
|
| 136 |
0 |
| po_span_w_free(&w); croak("index"); |
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
5 |
▶ | if (!SvROK(lookups)) croak("lookups must be an arrayref"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(lookups)) croak("lookups must be an arrayref"); |
0 |
5 |
5 |
|
| 140 |
5 |
| lk = (AV *)SvRV(lookups); |
| 141 |
5 |
| n = av_len(lk) + 1; |
| 142 |
1209 |
▶ | for (i = 0; i < n; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i += 2) { |
1204 |
5 |
1209 |
|
| 143 |
1204 |
| SV **a = av_fetch(lk, i, 0); |
| 144 |
1204 |
| SV **b = av_fetch(lk, i + 1, 0); |
| 145 |
1204 |
| po_u64 hi = 0, lo = 0; |
| 146 |
1204 |
| uint32_t first = 0, count = 0; |
| 147 |
1204 |
▶ | if (!a || !b) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!a || !b) break; |
1204 |
0 |
1204 |
| if (!a || !b) break; |
1204 |
0 |
1204 |
|
| 148 |
1204 |
| (void)po_sv_to_u64(aTHX_ *a, &hi); |
| 149 |
1204 |
| (void)po_sv_to_u64(aTHX_ *b, &lo); |
| 150 |
1204 |
▶ | if (po_traceidx_get(&idx, hi, lo, &first, &count)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_traceidx_get(&idx, hi, lo, &first, &count)) { |
1004 |
200 |
1204 |
|
| 151 |
1004 |
| found++; |
| 152 |
1004 |
| av_push(hits, newSVuv((UV)count)); |
| 153 |
|
| } |
| 154 |
200 |
| else { missing++; av_push(hits, newSViv(-1)); } |
| 155 |
|
| } |
| 156 |
|
| |
| 157 |
|
| { |
| 158 |
5 |
| HV *res = newHV(); |
| 159 |
5 |
| hv_stores(res, "found", newSVuv((UV)found)); |
| 160 |
5 |
| hv_stores(res, "missing", newSVuv((UV)missing)); |
| 161 |
5 |
| hv_stores(res, "counts", newRV_noinc((SV *)hits)); |
| 162 |
5 |
| hv_stores(res, "slots", newSVuv((UV)idx.slots)); |
| 163 |
5 |
| hv_stores(res, "distinct", newSVuv((UV)idx.n)); |
| 164 |
5 |
| hv_stores(res, "probes", po_u64_to_sv(idx.probes)); |
| 165 |
5 |
| hv_stores(res, "lookups", po_u64_to_sv(idx.lookups)); |
| 166 |
5 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
5 |
5 |
|
| 167 |
|
| } |
| 168 |
5 |
| po_traceidx_free(&idx); |
| 169 |
5 |
| po_span_w_free(&w); |
| 170 |
|
| } |
| 171 |
|
| |
| 172 |
|
| # --- duration search -------------------------------------------------------- |
| 173 |
|
| |
| 174 |
|
| # Everything at or above `min_dur`, from the ordinal array. Returns the |
| 175 |
|
| # ordinal where the range starts, so a test can assert it is a RANGE rather |
| 176 |
|
| # than a filtered scan. |
| 177 |
|
| void |
| 178 |
|
| pot_slower_than(SV *specs, SV *min_dur) |
| 179 |
|
| PPCODE: |
| 180 |
|
| { |
| 181 |
|
| po_span_w w; |
| 182 |
|
| po_tsum_set sums; |
| 183 |
3 |
| po_u64 want = 0; |
| 184 |
|
| uint32_t lo, i; |
| 185 |
3 |
| AV *out = newAV(); |
| 186 |
|
| |
| 187 |
3 |
| (void)po_sv_to_u64(aTHX_ min_dur, &want); |
| 188 |
3 |
▶ | if (!po_span_w_init(&w)) croak("oom"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_span_w_init(&w)) croak("oom"); |
0 |
3 |
3 |
|
| 189 |
3 |
▶ | if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pot_load(aTHX_ specs, &w)) { po_span_w_free(&w); croak("bad specs"); } |
0 |
3 |
3 |
|
| 190 |
3 |
| po_span_w_seal(&w); |
| 191 |
3 |
▶ | if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
3 |
0 |
3 |
| if (!po_tsum_init(&sums) || !po_tsum_build(&sums, w.s, (uint32_t)w.n) |
3 |
0 |
3 |
|
| 192 |
3 |
▶ | || !po_tsum_index(&sums)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !po_tsum_index(&sums)) { |
0 |
3 |
3 |
|
| 193 |
0 |
| po_span_w_free(&w); croak("summaries"); |
| 194 |
|
| } |
| 195 |
|
| |
| 196 |
3 |
| lo = po_tsum_lower_bound(&sums, want); |
| 197 |
64 |
▶ | for (i = lo; i < sums.n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = lo; i < sums.n; i++) |
61 |
3 |
64 |
|
| 198 |
61 |
| av_push(out, po_u64_to_sv(sums.t[sums.by_dur[i]].dur_ns)); |
| 199 |
|
| |
| 200 |
|
| { |
| 201 |
3 |
| HV *res = newHV(); |
| 202 |
3 |
| hv_stores(res, "durations", newRV_noinc((SV *)out)); |
| 203 |
3 |
| hv_stores(res, "from", newSVuv((UV)lo)); |
| 204 |
3 |
| hv_stores(res, "total", newSVuv((UV)sums.n)); |
| 205 |
3 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
3 |
3 |
|
| 206 |
|
| } |
| 207 |
3 |
| po_tsum_free(&sums); |
| 208 |
3 |
| po_span_w_free(&w); |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
|
| # --- segment pruning -------------------------------------------------------- |
| 212 |
|
| |
| 213 |
|
| int |
| 214 |
|
| pot_seg_may_match(SV *t_min, SV *t_max, SV *dur_max, SV *any_error, \ |
| 215 |
|
| SV *from, SV *to, SV *min_dur, SV *want_error) |
| 216 |
|
| CODE: |
| 217 |
|
| { |
| 218 |
|
| po_seg_trace_stats st; |
| 219 |
8 |
| po_u64 f = 0, t = 0, md = 0; |
| 220 |
8 |
| memset(&st, 0, sizeof(st)); |
| 221 |
8 |
| (void)po_sv_to_u64(aTHX_ t_min, &st.t_min); |
| 222 |
8 |
| (void)po_sv_to_u64(aTHX_ t_max, &st.t_max); |
| 223 |
8 |
| (void)po_sv_to_u64(aTHX_ dur_max, &st.dur_max); |
| 224 |
8 |
| st.any_error = (int)SvIV(any_error); |
| 225 |
8 |
| (void)po_sv_to_u64(aTHX_ from, &f); |
| 226 |
8 |
| (void)po_sv_to_u64(aTHX_ to, &t); |
| 227 |
8 |
| (void)po_sv_to_u64(aTHX_ min_dur, &md); |
| 228 |
8 |
| RETVAL = po_seg_may_match(&st, f, t, md, (int)SvIV(want_error)); |
| 229 |
|
| } |
| 230 |
|
| OUTPUT: |
| 231 |
|
| RETVAL |