| 1 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::SegIO PREFIX = psio_ |
| 2 |
|
| |
| 3 |
|
| # Write ONE segment carrying all three signals, then reopen it and read them |
| 4 |
|
| # all back. This is the join phases 5, 6 and 7 each deferred: their structures |
| 5 |
|
| # reach a disk here. |
| 6 |
|
| SV * |
| 7 |
|
| psio_write_all(SV *path, SV *spec) |
| 8 |
|
| CODE: |
| 9 |
|
| { |
| 10 |
|
| po_seg_w w; |
| 11 |
|
| HV *sp; |
| 12 |
|
| SV **f; |
| 13 |
|
| uint8_t ulid[16]; |
| 14 |
4 |
| int i, ok = 1; |
| 15 |
|
| |
| 16 |
4 |
▶ | if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
4 |
0 |
4 |
| if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
0 |
4 |
4 |
|
| 17 |
0 |
| croak("spec must be a hashref"); |
| 18 |
4 |
| sp = (HV *)SvRV(spec); |
| 19 |
|
| |
| 20 |
4 |
▶ | if (!po_seg_w_init(&w, PO_SIG_MIXED, 0, "acme", 4)) croak("oom"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_w_init(&w, PO_SIG_MIXED, 0, "acme", 4)) croak("oom"); |
0 |
4 |
4 |
|
| 21 |
|
| |
| 22 |
|
| /* one record so the segment has a time span */ |
| 23 |
|
| { |
| 24 |
|
| po_rec r; |
| 25 |
4 |
| po_rec_zero(&r); |
| 26 |
4 |
| r.kind = PO_SPAN; |
| 27 |
4 |
| r.t_unix_nano = 1000; |
| 28 |
4 |
| po_seg_w_add(&w, &r, "seed", 4, "l", 1, NULL); |
| 29 |
|
| } |
| 30 |
|
| |
| 31 |
|
| /* --- metrics --- */ |
| 32 |
4 |
▶ | if ((f = hv_fetchs(sp, "metrics", 0)) && SvROK(*f)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(sp, "metrics", 0)) && SvROK(*f)) { |
2 |
2 |
4 |
| if ((f = hv_fetchs(sp, "metrics", 0)) && SvROK(*f)) { |
2 |
0 |
2 |
|
| 33 |
2 |
| AV *av = (AV *)SvRV(*f); |
| 34 |
2 |
| SSize_t n = av_len(av) + 1, k; |
| 35 |
|
| po_chunk_hdr *hdrs; |
| 36 |
|
| char **streams; |
| 37 |
|
| po_u64 *series; |
| 38 |
|
| po_chunk_w *cw; |
| 39 |
|
| char *blob; size_t blen; |
| 40 |
|
| |
| 41 |
2 |
▶ | Newxz(hdrs, n ? n : 1, po_chunk_hdr); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(hdrs, n ? n : 1, po_chunk_hdr); |
2 |
0 |
2 |
| Newxz(hdrs, n ? n : 1, po_chunk_hdr); |
0 |
2 |
2 |
| Newxz(hdrs, n ? n : 1, po_chunk_hdr); |
2 |
0 |
2 |
|
| 42 |
2 |
▶ | Newxz(streams, n ? n : 1, char *); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(streams, n ? n : 1, char *); |
2 |
0 |
2 |
| Newxz(streams, n ? n : 1, char *); |
0 |
2 |
2 |
| Newxz(streams, n ? n : 1, char *); |
2 |
0 |
2 |
|
| 43 |
2 |
▶ | Newxz(series, n ? n : 1, po_u64); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(series, n ? n : 1, po_u64); |
2 |
0 |
2 |
| Newxz(series, n ? n : 1, po_u64); |
0 |
2 |
2 |
| Newxz(series, n ? n : 1, po_u64); |
2 |
0 |
2 |
|
| 44 |
2 |
▶ | Newxz(cw, n ? n : 1, po_chunk_w); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(cw, n ? n : 1, po_chunk_w); |
2 |
0 |
2 |
| Newxz(cw, n ? n : 1, po_chunk_w); |
0 |
2 |
2 |
| Newxz(cw, n ? n : 1, po_chunk_w); |
2 |
0 |
2 |
|
| 45 |
|
| |
| 46 |
6 |
▶ | for (k = 0; k < n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { |
4 |
2 |
6 |
|
| 47 |
4 |
| SV **e = av_fetch(av, k, 0); |
| 48 |
|
| HV *h; SV **g; |
| 49 |
|
| AV *pts; |
| 50 |
|
| SSize_t j, np; |
| 51 |
4 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
4 |
0 |
4 |
| if (!e || !SvROK(*e)) continue; |
0 |
4 |
4 |
|
| 52 |
4 |
| h = (HV *)SvRV(*e); |
| 53 |
4 |
▶ | if ((g = hv_fetchs(h, "series", 0))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "series", 0))) |
4 |
0 |
4 |
|
| 54 |
4 |
| (void)po_sv_to_u64(aTHX_ *g, &series[k]); |
| 55 |
4 |
| po_chunk_w_init(&cw[k], 0, 0); |
| 56 |
4 |
▶ | if ((g = hv_fetchs(h, "points", 0)) && SvROK(*g)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "points", 0)) && SvROK(*g)) { |
4 |
0 |
4 |
| if ((g = hv_fetchs(h, "points", 0)) && SvROK(*g)) { |
4 |
0 |
4 |
|
| 57 |
4 |
| pts = (AV *)SvRV(*g); |
| 58 |
4 |
| np = av_len(pts) + 1; |
| 59 |
64 |
▶ | for (j = 0; j + 1 < np; j += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j + 1 < np; j += 2) { |
60 |
4 |
64 |
|
| 60 |
60 |
| SV **t = av_fetch(pts, j, 0); |
| 61 |
60 |
| SV **v = av_fetch(pts, j + 1, 0); |
| 62 |
60 |
| po_u64 tt = 0; |
| 63 |
60 |
▶ | if (!t || !v) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!t || !v) break; |
60 |
0 |
60 |
| if (!t || !v) break; |
60 |
0 |
60 |
|
| 64 |
60 |
| (void)po_sv_to_u64(aTHX_ *t, &tt); |
| 65 |
60 |
| po_chunk_add(&cw[k], tt, po_d2b(SvNV(*v))); |
| 66 |
|
| } |
| 67 |
|
| } |
| 68 |
4 |
| hdrs[k] = cw[k].h; |
| 69 |
4 |
| streams[k] = (char *)cw[k].g.bw.buf; |
| 70 |
4 |
▶ | if (hdrs[k].count) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hdrs[k].count) |
4 |
0 |
4 |
|
| 71 |
4 |
| po_seg_w_span(&w, hdrs[k].t_first, hdrs[k].t_last); |
| 72 |
|
| } |
| 73 |
2 |
| blob = po_metric_serialise(hdrs, (const char *const *)streams, |
| 74 |
|
| series, (uint32_t)n, &blen); |
| 75 |
2 |
▶ | if (blob) po_seg_w_region(&w, PO_RGN_MCHUNKS, blob, blen, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (blob) po_seg_w_region(&w, PO_RGN_MCHUNKS, blob, blen, 1); |
2 |
0 |
2 |
|
| 76 |
0 |
| else ok = 0; |
| 77 |
6 |
▶ | for (k = 0; k < n; k++) po_chunk_w_free(&cw[k]); |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) po_chunk_w_free(&cw[k]); |
4 |
2 |
6 |
|
| 78 |
2 |
| Safefree(hdrs); Safefree(streams); Safefree(series); Safefree(cw); |
| 79 |
|
| } |
| 80 |
|
| |
| 81 |
|
| /* --- logs --- */ |
| 82 |
4 |
▶ | if (ok && (f = hv_fetchs(sp, "logs", 0)) && SvROK(*f)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ok && (f = hv_fetchs(sp, "logs", 0)) && SvROK(*f)) { |
4 |
0 |
4 |
| if (ok && (f = hv_fetchs(sp, "logs", 0)) && SvROK(*f)) { |
2 |
2 |
4 |
| if (ok && (f = hv_fetchs(sp, "logs", 0)) && SvROK(*f)) { |
2 |
0 |
2 |
|
| 83 |
2 |
| AV *av = (AV *)SvRV(*f); |
| 84 |
2 |
| SSize_t n = av_len(av) + 1, k; |
| 85 |
|
| po_block_w *bw; |
| 86 |
|
| po_block_hdr *hdrs; |
| 87 |
|
| char **comps; |
| 88 |
|
| unsigned char **blooms; |
| 89 |
|
| char *blob; size_t blen; |
| 90 |
|
| |
| 91 |
2 |
▶ | Newxz(bw, n ? n : 1, po_block_w); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(bw, n ? n : 1, po_block_w); |
2 |
0 |
2 |
| Newxz(bw, n ? n : 1, po_block_w); |
0 |
2 |
2 |
| Newxz(bw, n ? n : 1, po_block_w); |
2 |
0 |
2 |
|
| 92 |
2 |
▶ | Newxz(hdrs, n ? n : 1, po_block_hdr); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(hdrs, n ? n : 1, po_block_hdr); |
2 |
0 |
2 |
| Newxz(hdrs, n ? n : 1, po_block_hdr); |
0 |
2 |
2 |
| Newxz(hdrs, n ? n : 1, po_block_hdr); |
2 |
0 |
2 |
|
| 93 |
2 |
▶ | Newxz(comps, n ? n : 1, char *); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(comps, n ? n : 1, char *); |
2 |
0 |
2 |
| Newxz(comps, n ? n : 1, char *); |
0 |
2 |
2 |
| Newxz(comps, n ? n : 1, char *); |
2 |
0 |
2 |
|
| 94 |
2 |
▶ | Newxz(blooms, n ? n : 1, unsigned char *); |
Branch: 3 branches
| Branch | True | False | Total |
| Newxz(blooms, n ? n : 1, unsigned char *); |
2 |
0 |
2 |
| Newxz(blooms, n ? n : 1, unsigned char *); |
0 |
2 |
2 |
| Newxz(blooms, n ? n : 1, unsigned char *); |
2 |
0 |
2 |
|
| 95 |
|
| |
| 96 |
6 |
▶ | for (k = 0; k < n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { |
4 |
2 |
6 |
|
| 97 |
4 |
| SV **e = av_fetch(av, k, 0); |
| 98 |
|
| AV *lines; |
| 99 |
|
| SSize_t j, nl; |
| 100 |
4 |
| size_t clen = 0; |
| 101 |
4 |
| po_u64 t0 = 1000, stream = (po_u64)(k + 1); |
| 102 |
4 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
4 |
0 |
4 |
| if (!e || !SvROK(*e)) continue; |
0 |
4 |
4 |
|
| 103 |
|
| /* Either a plain arrayref of lines, or a hashref carrying |
| 104 |
|
| * a start time and a stream: pruning by TIME cannot be |
| 105 |
|
| * tested against blocks that all share one. */ |
| 106 |
4 |
▶ | if (SvTYPE(SvRV(*e)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(*e)) == SVt_PVHV) { |
2 |
2 |
4 |
|
| 107 |
2 |
| HV *lh = (HV *)SvRV(*e); |
| 108 |
|
| SV **g; |
| 109 |
2 |
▶ | if ((g = hv_fetchs(lh, "t0", 0))) (void)po_sv_to_u64(aTHX_ *g, &t0); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(lh, "t0", 0))) (void)po_sv_to_u64(aTHX_ *g, &t0); |
2 |
0 |
2 |
|
| 110 |
2 |
▶ | if ((g = hv_fetchs(lh, "stream", 0))) (void)po_sv_to_u64(aTHX_ *g, &stream); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(lh, "stream", 0))) (void)po_sv_to_u64(aTHX_ *g, &stream); |
2 |
0 |
2 |
|
| 111 |
2 |
| g = hv_fetchs(lh, "lines", 0); |
| 112 |
2 |
▶ | if (!g || !SvROK(*g)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!g || !SvROK(*g)) continue; |
2 |
0 |
2 |
| if (!g || !SvROK(*g)) continue; |
0 |
2 |
2 |
|
| 113 |
2 |
| lines = (AV *)SvRV(*g); |
| 114 |
|
| } |
| 115 |
2 |
| else lines = (AV *)SvRV(*e); |
| 116 |
4 |
| nl = av_len(lines) + 1; |
| 117 |
4 |
| po_block_w_init(&bw[k], stream); |
| 118 |
14 |
▶ | for (j = 0; j < nl; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < nl; j++) { |
10 |
4 |
14 |
|
| 119 |
10 |
| SV **l = av_fetch(lines, j, 0); |
| 120 |
|
| STRLEN bl; |
| 121 |
|
| const char *body; |
| 122 |
10 |
▶ | if (!l) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!l) continue; |
0 |
10 |
10 |
|
| 123 |
10 |
| body = SvPV(*l, bl); |
| 124 |
10 |
| po_block_add(&bw[k], t0 + (po_u64)j * 10, 9, |
| 125 |
|
| body, (size_t)bl, 0, 0, 0); |
| 126 |
|
| } |
| 127 |
4 |
▶ | if (!po_block_seal(&bw[k], &comps[k], &clen)) { ok = 0; break; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_block_seal(&bw[k], &comps[k], &clen)) { ok = 0; break; } |
0 |
4 |
4 |
|
| 128 |
4 |
| hdrs[k] = bw[k].h; |
| 129 |
4 |
| blooms[k] = bw[k].bloom.bits; |
| 130 |
4 |
▶ | if (hdrs[k].lines) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hdrs[k].lines) |
4 |
0 |
4 |
|
| 131 |
4 |
| po_seg_w_span(&w, hdrs[k].t_min, hdrs[k].t_max); |
| 132 |
|
| } |
| 133 |
2 |
▶ | if (ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) { |
2 |
0 |
2 |
|
| 134 |
2 |
| blob = po_log_serialise(hdrs, (const char *const *)comps, |
| 135 |
|
| (const unsigned char *const *)blooms, |
| 136 |
|
| (uint32_t)n, &blen); |
| 137 |
2 |
▶ | if (blob) po_seg_w_region(&w, PO_RGN_LOGBLOCKS, blob, blen, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (blob) po_seg_w_region(&w, PO_RGN_LOGBLOCKS, blob, blen, 1); |
2 |
0 |
2 |
|
| 138 |
0 |
| else ok = 0; |
| 139 |
|
| } |
| 140 |
6 |
▶ | for (k = 0; k < n; k++) { free(comps[k]); po_block_w_free(&bw[k]); } |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { free(comps[k]); po_block_w_free(&bw[k]); } |
4 |
2 |
6 |
|
| 141 |
2 |
| Safefree(bw); Safefree(hdrs); Safefree(comps); Safefree(blooms); |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
|
| /* --- spans --- */ |
| 145 |
4 |
▶ | if (ok && (f = hv_fetchs(sp, "spans", 0)) && SvROK(*f)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ok && (f = hv_fetchs(sp, "spans", 0)) && SvROK(*f)) { |
4 |
0 |
4 |
| if (ok && (f = hv_fetchs(sp, "spans", 0)) && SvROK(*f)) { |
3 |
1 |
4 |
| if (ok && (f = hv_fetchs(sp, "spans", 0)) && SvROK(*f)) { |
3 |
0 |
3 |
|
| 146 |
|
| po_span_w sw; |
| 147 |
3 |
| AV *av = (AV *)SvRV(*f); |
| 148 |
3 |
| SSize_t n = av_len(av) + 1, k; |
| 149 |
|
| char *blob; size_t blen; |
| 150 |
|
| |
| 151 |
3 |
▶ | if (!po_span_w_init(&sw)) croak("oom"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_span_w_init(&sw)) croak("oom"); |
0 |
3 |
3 |
|
| 152 |
11 |
▶ | for (k = 0; k < n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { |
8 |
3 |
11 |
|
| 153 |
8 |
| SV **e = av_fetch(av, k, 0); |
| 154 |
|
| HV *h; SV **g; |
| 155 |
|
| po_span s; |
| 156 |
8 |
| po_u64 endv = 0; |
| 157 |
8 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
8 |
0 |
8 |
| if (!e || !SvROK(*e)) continue; |
0 |
8 |
8 |
|
| 158 |
8 |
| h = (HV *)SvRV(*e); |
| 159 |
8 |
| memset(&s, 0, sizeof(s)); |
| 160 |
8 |
▶ | if ((g = hv_fetchs(h, "trace_hi", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.trace_hi); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "trace_hi", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.trace_hi); |
8 |
0 |
8 |
|
| 161 |
8 |
▶ | if ((g = hv_fetchs(h, "trace_lo", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.trace_lo); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "trace_lo", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.trace_lo); |
8 |
0 |
8 |
|
| 162 |
8 |
▶ | if ((g = hv_fetchs(h, "span_id", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.span_id); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "span_id", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.span_id); |
8 |
0 |
8 |
|
| 163 |
8 |
▶ | if ((g = hv_fetchs(h, "parent", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.parent_span_id); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "parent", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.parent_span_id); |
8 |
0 |
8 |
|
| 164 |
8 |
▶ | if ((g = hv_fetchs(h, "start", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.start_ns); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "start", 0))) (void)po_sv_to_u64(aTHX_ *g, &s.start_ns); |
8 |
0 |
8 |
|
| 165 |
8 |
▶ | if ((g = hv_fetchs(h, "end", 0))) (void)po_sv_to_u64(aTHX_ *g, &endv); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "end", 0))) (void)po_sv_to_u64(aTHX_ *g, &endv); |
8 |
0 |
8 |
|
| 166 |
8 |
▶ | if ((g = hv_fetchs(h, "service", 0))) s.service_sym = (uint32_t)SvUV(*g); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "service", 0))) s.service_sym = (uint32_t)SvUV(*g); |
8 |
0 |
8 |
|
| 167 |
8 |
▶ | if ((g = hv_fetchs(h, "status", 0))) s.status = (uint8_t)SvUV(*g); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "status", 0))) s.status = (uint8_t)SvUV(*g); |
0 |
8 |
8 |
|
| 168 |
8 |
▶ | s.dur_ns = endv >= s.start_ns ? endv - s.start_ns : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| s.dur_ns = endv >= s.start_ns ? endv - s.start_ns : 0; |
8 |
0 |
8 |
|
| 169 |
8 |
| po_seg_w_span(&w, s.start_ns, s.start_ns + s.dur_ns); |
| 170 |
8 |
| po_span_add(&sw, &s); |
| 171 |
|
| } |
| 172 |
3 |
| po_span_w_seal(&sw); |
| 173 |
3 |
| blob = po_span_serialise(sw.s, (uint32_t)sw.n, &blen); |
| 174 |
3 |
▶ | if (blob) po_seg_w_region(&w, PO_RGN_SPANS, blob, blen, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (blob) po_seg_w_region(&w, PO_RGN_SPANS, blob, blen, 1); |
3 |
0 |
3 |
|
| 175 |
0 |
| else ok = 0; |
| 176 |
|
| |
| 177 |
3 |
▶ | if (ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) { |
3 |
0 |
3 |
|
| 178 |
|
| po_tsum_set sums; |
| 179 |
3 |
▶ | if (po_tsum_init(&sums) |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_tsum_init(&sums) |
3 |
0 |
3 |
|
| 180 |
3 |
▶ | && po_tsum_build(&sums, sw.s, (uint32_t)sw.n)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && po_tsum_build(&sums, sw.s, (uint32_t)sw.n)) { |
3 |
0 |
3 |
|
| 181 |
|
| char *tb; size_t tl; |
| 182 |
3 |
| tb = po_tsum_serialise(sums.t, sums.n, &tl); |
| 183 |
3 |
▶ | if (tb) po_seg_w_region(&w, PO_RGN_TRACESUM, tb, tl, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (tb) po_seg_w_region(&w, PO_RGN_TRACESUM, tb, tl, 1); |
3 |
0 |
3 |
|
| 184 |
|
| } |
| 185 |
3 |
| po_tsum_free(&sums); |
| 186 |
|
| } |
| 187 |
3 |
| po_span_w_free(&sw); |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
68 |
▶ | for (i = 0; i < 16; i++) ulid[i] = (uint8_t)(i * 5 + 1); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < 16; i++) ulid[i] = (uint8_t)(i * 5 + 1); |
64 |
4 |
68 |
|
| 191 |
8 |
▶ | if (ok) ok = po_seg_write(&w, SvPV_nolen(path), ulid); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) ok = po_seg_write(&w, SvPV_nolen(path), ulid); |
4 |
0 |
4 |
|
| 192 |
4 |
| po_seg_w_free(&w); |
| 193 |
4 |
| RETVAL = newSViv(ok ? 1 : 0); |
| 194 |
|
| } |
| 195 |
|
| OUTPUT: |
| 196 |
|
| RETVAL |
| 197 |
|
| |
| 198 |
|
| # Reopen and read every signal back out of the mapping. |
| 199 |
|
| void |
| 200 |
|
| psio_read_all(SV *path) |
| 201 |
|
| PPCODE: |
| 202 |
|
| { |
| 203 |
|
| po_seg_r s; |
| 204 |
|
| HV *res; |
| 205 |
|
| const char *p; |
| 206 |
|
| size_t len; |
| 207 |
|
| |
| 208 |
3 |
▶ | if (!po_seg_open(&s, SvPV_nolen(path))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_open(&s, SvPV_nolen(path))) { |
0 |
3 |
3 |
|
| 209 |
0 |
▶ | mXPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(&PL_sv_undef); |
0 |
0 |
0 |
|
| 210 |
0 |
| XSRETURN(1); |
| 211 |
|
| } |
| 212 |
3 |
| res = newHV(); |
| 213 |
3 |
| hv_stores(res, "regions", newSViv(s.nrgn)); |
| 214 |
|
| |
| 215 |
|
| /* --- metrics --- */ |
| 216 |
3 |
▶ | if ((p = po_seg_region_ptr(&s, PO_RGN_MCHUNKS, &len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((p = po_seg_region_ptr(&s, PO_RGN_MCHUNKS, &len))) { |
1 |
2 |
3 |
|
| 217 |
|
| po_mchunk_ref refs[64]; |
| 218 |
1 |
| int n = po_metric_open(p, len, refs, 64); |
| 219 |
1 |
| AV *out = newAV(); |
| 220 |
|
| int k; |
| 221 |
3 |
▶ | for (k = 0; k < n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { |
2 |
1 |
3 |
|
| 222 |
2 |
| HV *h = newHV(); |
| 223 |
|
| po_chunk_r rd; |
| 224 |
|
| po_u64 t, bits; |
| 225 |
2 |
| AV *pts = newAV(); |
| 226 |
2 |
| hv_stores(h, "series", po_u64_to_sv(refs[k].series)); |
| 227 |
2 |
| hv_stores(h, "count", newSVuv((UV)refs[k].h.count)); |
| 228 |
2 |
| po_chunk_r_init(&rd, &refs[k].h, refs[k].bits); |
| 229 |
32 |
▶ | while (po_chunk_next(&rd, &t, &bits)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (po_chunk_next(&rd, &t, &bits)) { |
30 |
2 |
32 |
|
| 230 |
30 |
| av_push(pts, po_u64_to_sv(t)); |
| 231 |
30 |
| av_push(pts, newSVnv((NV)po_b2d(bits))); |
| 232 |
|
| } |
| 233 |
2 |
| hv_stores(h, "points", newRV_noinc((SV *)pts)); |
| 234 |
2 |
| av_push(out, newRV_noinc((SV *)h)); |
| 235 |
|
| } |
| 236 |
1 |
| hv_stores(res, "metrics", newRV_noinc((SV *)out)); |
| 237 |
1 |
| hv_stores(res, "metrics_ok", newSViv(n >= 0)); |
| 238 |
|
| } |
| 239 |
|
| |
| 240 |
|
| /* --- logs --- */ |
| 241 |
3 |
▶ | if ((p = po_seg_region_ptr(&s, PO_RGN_LOGBLOCKS, &len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((p = po_seg_region_ptr(&s, PO_RGN_LOGBLOCKS, &len))) { |
1 |
2 |
3 |
|
| 242 |
|
| po_lblock_ref refs[64]; |
| 243 |
1 |
| int n = po_log_open(p, len, refs, 64); |
| 244 |
1 |
| AV *out = newAV(); |
| 245 |
|
| int k; |
| 246 |
3 |
▶ | for (k = 0; k < n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < n; k++) { |
2 |
1 |
3 |
|
| 247 |
2 |
| char *raw = NULL; |
| 248 |
2 |
| AV *lines = newAV(); |
| 249 |
2 |
▶ | if (po_block_inflate(&refs[k].h, refs[k].comp, |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_block_inflate(&refs[k].h, refs[k].comp, |
2 |
0 |
2 |
|
| 250 |
2 |
| refs[k].h.comp_len, &raw)) { |
| 251 |
|
| po_line_r r; po_line ln; |
| 252 |
2 |
| po_line_r_init(&r, &refs[k].h, raw); |
| 253 |
7 |
▶ | while (po_line_next(&r, &ln)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (po_line_next(&r, &ln)) |
5 |
2 |
7 |
|
| 254 |
5 |
| av_push(lines, newSVpvn(ln.body, ln.body_len)); |
| 255 |
2 |
| free(raw); |
| 256 |
|
| } |
| 257 |
2 |
| av_push(out, newRV_noinc((SV *)lines)); |
| 258 |
|
| } |
| 259 |
1 |
| hv_stores(res, "logs", newRV_noinc((SV *)out)); |
| 260 |
1 |
| hv_stores(res, "logs_ok", newSViv(n >= 0)); |
| 261 |
|
| } |
| 262 |
|
| |
| 263 |
|
| /* --- spans, read straight out of the mapping --- */ |
| 264 |
3 |
▶ | if ((p = po_seg_region_ptr(&s, PO_RGN_SPANS, &len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((p = po_seg_region_ptr(&s, PO_RGN_SPANS, &len))) { |
2 |
1 |
3 |
|
| 265 |
2 |
| uint32_t n = 0; |
| 266 |
2 |
| const po_span *sp = po_span_open(p, len, &n); |
| 267 |
2 |
| AV *out = newAV(); |
| 268 |
|
| uint32_t k; |
| 269 |
8 |
▶ | for (k = 0; sp && k < n; k++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = 0; sp && k < n; k++) { |
8 |
0 |
8 |
| for (k = 0; sp && k < n; k++) { |
6 |
2 |
8 |
|
| 270 |
6 |
| HV *h = newHV(); |
| 271 |
6 |
| hv_stores(h, "trace_hi", po_u64_to_sv(sp[k].trace_hi)); |
| 272 |
6 |
| hv_stores(h, "trace_lo", po_u64_to_sv(sp[k].trace_lo)); |
| 273 |
6 |
| hv_stores(h, "span_id", po_u64_to_sv(sp[k].span_id)); |
| 274 |
6 |
| hv_stores(h, "start", po_u64_to_sv(sp[k].start_ns)); |
| 275 |
6 |
| hv_stores(h, "duration", po_u64_to_sv(sp[k].dur_ns)); |
| 276 |
6 |
| hv_stores(h, "service", newSVuv((UV)sp[k].service_sym)); |
| 277 |
6 |
| av_push(out, newRV_noinc((SV *)h)); |
| 278 |
|
| } |
| 279 |
2 |
| hv_stores(res, "spans", newRV_noinc((SV *)out)); |
| 280 |
2 |
| hv_stores(res, "spans_ok", newSViv(sp ? 1 : 0)); |
| 281 |
|
| } |
| 282 |
|
| |
| 283 |
|
| /* --- trace summaries --- */ |
| 284 |
3 |
▶ | if ((p = po_seg_region_ptr(&s, PO_RGN_TRACESUM, &len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((p = po_seg_region_ptr(&s, PO_RGN_TRACESUM, &len))) { |
2 |
1 |
3 |
|
| 285 |
2 |
| uint32_t n = 0; |
| 286 |
2 |
| const po_tsummary *t = po_tsum_open(p, len, &n); |
| 287 |
2 |
| AV *out = newAV(); |
| 288 |
|
| uint32_t k; |
| 289 |
6 |
▶ | for (k = 0; t && k < n; k++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = 0; t && k < n; k++) { |
6 |
0 |
6 |
| for (k = 0; t && k < n; k++) { |
4 |
2 |
6 |
|
| 290 |
4 |
| HV *h = newHV(); |
| 291 |
4 |
| hv_stores(h, "trace_hi", po_u64_to_sv(t[k].trace_hi)); |
| 292 |
4 |
| hv_stores(h, "duration", po_u64_to_sv(t[k].dur_ns)); |
| 293 |
4 |
| hv_stores(h, "spans", newSVuv((UV)t[k].spans)); |
| 294 |
4 |
| av_push(out, newRV_noinc((SV *)h)); |
| 295 |
|
| } |
| 296 |
2 |
| hv_stores(res, "summaries", newRV_noinc((SV *)out)); |
| 297 |
|
| } |
| 298 |
|
| |
| 299 |
3 |
| po_seg_close(&s); |
| 300 |
3 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
3 |
3 |
|
| 301 |
|
| } |