| 1 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Segment PREFIX = pos_ |
| 2 |
|
| |
| 3 |
|
| # --- the hash, against published vectors ----------------------------------- |
| 4 |
|
| |
| 5 |
|
| void |
| 6 |
|
| pos_murmur128(SV *buf, SV *seed) |
| 7 |
|
| PPCODE: |
| 8 |
|
| { |
| 9 |
|
| STRLEN len; const char *p; |
| 10 |
|
| po_h128 h; |
| 11 |
218 |
| p = SvPV(buf, len); |
| 12 |
218 |
| h = po_murmur3_128(p, (size_t)len, (uint32_t)SvUV(seed)); |
| 13 |
218 |
▶ | mXPUSHs(po_u64_to_sv(h.hi)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(po_u64_to_sv(h.hi)); |
0 |
218 |
218 |
|
| 14 |
218 |
▶ | mXPUSHs(po_u64_to_sv(h.lo)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(po_u64_to_sv(h.lo)); |
0 |
218 |
218 |
|
| 15 |
|
| } |
| 16 |
|
| |
| 17 |
|
| # --- series ids ------------------------------------------------------------- |
| 18 |
|
| |
| 19 |
|
| # Intern a list of canonical blocks, returning the slot each got. Two calls |
| 20 |
|
| # with the same blocks in different ORDERS must give each block the same id, |
| 21 |
|
| # which is the property per-worker writing rests on. |
| 22 |
|
| void |
| 23 |
|
| pos_intern_series(SV *blocks) |
| 24 |
|
| PPCODE: |
| 25 |
|
| { |
| 26 |
|
| po_arena ar; |
| 27 |
|
| po_series_tab t; |
| 28 |
|
| AV *av; |
| 29 |
|
| SSize_t i, n; |
| 30 |
11 |
| AV *slots = newAV(); |
| 31 |
11 |
| AV *ids = newAV(); |
| 32 |
|
| |
| 33 |
11 |
▶ | if (!SvROK(blocks) || SvTYPE(SvRV(blocks)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(blocks) || SvTYPE(SvRV(blocks)) != SVt_PVAV) |
11 |
0 |
11 |
| if (!SvROK(blocks) || SvTYPE(SvRV(blocks)) != SVt_PVAV) |
0 |
11 |
11 |
|
| 34 |
0 |
| croak("blocks must be an arrayref"); |
| 35 |
11 |
| av = (AV *)SvRV(blocks); |
| 36 |
11 |
| n = av_len(av) + 1; |
| 37 |
|
| |
| 38 |
11 |
▶ | if (!po_arena_init(&ar, 256)) croak("arena"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_arena_init(&ar, 256)) croak("arena"); |
0 |
11 |
11 |
|
| 39 |
11 |
▶ | if (!po_series_tab_init(&t, &ar, 16)) { po_arena_free(&ar); croak("tab"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_series_tab_init(&t, &ar, 16)) { po_arena_free(&ar); croak("tab"); } |
0 |
11 |
11 |
|
| 40 |
|
| |
| 41 |
14573 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
14562 |
11 |
14573 |
|
| 42 |
14562 |
| SV **e = av_fetch(av, i, 0); |
| 43 |
|
| STRLEN l; const char *p; |
| 44 |
|
| po_h128 id; |
| 45 |
14562 |
| int created = 0; |
| 46 |
|
| uint32_t slot; |
| 47 |
14562 |
▶ | if (!e) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) continue; |
0 |
14562 |
14562 |
|
| 48 |
14562 |
| p = SvPV(*e, l); |
| 49 |
14562 |
| slot = po_series_intern(&t, p, (uint32_t)l, &id, &created); |
| 50 |
14562 |
▶ | if (slot == PO_SERIES_ERR) { po_series_tab_free(&t); |
Branch: 1 branch
| Branch | True | False | Total |
| if (slot == PO_SERIES_ERR) { po_series_tab_free(&t); |
0 |
14562 |
14562 |
|
| 51 |
0 |
| po_arena_free(&ar); croak("intern"); } |
| 52 |
14562 |
| av_push(slots, newSVuv((UV)slot)); |
| 53 |
|
| { |
| 54 |
|
| char hex[33]; |
| 55 |
|
| static const char H[] = "0123456789abcdef"; |
| 56 |
|
| int k; |
| 57 |
131058 |
▶ | for (k = 0; k < 8; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < 8; k++) { |
116496 |
14562 |
131058 |
|
| 58 |
116496 |
| unsigned b = (unsigned)((id.hi >> (56 - k * 8)) & 0xFF); |
| 59 |
116496 |
| hex[k * 2] = H[b >> 4]; hex[k * 2 + 1] = H[b & 15]; |
| 60 |
|
| } |
| 61 |
131058 |
▶ | for (k = 0; k < 8; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < 8; k++) { |
116496 |
14562 |
131058 |
|
| 62 |
116496 |
| unsigned b = (unsigned)((id.lo >> (56 - k * 8)) & 0xFF); |
| 63 |
116496 |
| hex[16 + k * 2] = H[b >> 4]; hex[16 + k * 2 + 1] = H[b & 15]; |
| 64 |
|
| } |
| 65 |
14562 |
| av_push(ids, newSVpvn(hex, 32)); |
| 66 |
|
| } |
| 67 |
|
| } |
| 68 |
|
| { |
| 69 |
11 |
| HV *res = newHV(); |
| 70 |
11 |
| hv_stores(res, "slots", newRV_noinc((SV *)slots)); |
| 71 |
11 |
| hv_stores(res, "ids", newRV_noinc((SV *)ids)); |
| 72 |
11 |
| hv_stores(res, "count", newSVuv((UV)t.n)); |
| 73 |
11 |
| hv_stores(res, "collisions", newSVuv((UV)t.collisions)); |
| 74 |
11 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
11 |
11 |
|
| 75 |
|
| } |
| 76 |
11 |
| po_series_tab_free(&t); |
| 77 |
11 |
| po_arena_free(&ar); |
| 78 |
|
| } |
| 79 |
|
| |
| 80 |
|
| # --- the symbol table ------------------------------------------------------- |
| 81 |
|
| |
| 82 |
|
| void |
| 83 |
|
| pos_intern_strings(SV *strings) |
| 84 |
|
| PPCODE: |
| 85 |
|
| { |
| 86 |
|
| po_intern t; |
| 87 |
|
| AV *av; |
| 88 |
|
| SSize_t i, n; |
| 89 |
2 |
| AV *ids = newAV(); |
| 90 |
|
| char *img; |
| 91 |
|
| size_t imglen; |
| 92 |
|
| |
| 93 |
2 |
▶ | if (!SvROK(strings) || SvTYPE(SvRV(strings)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(strings) || SvTYPE(SvRV(strings)) != SVt_PVAV) |
2 |
0 |
2 |
| if (!SvROK(strings) || SvTYPE(SvRV(strings)) != SVt_PVAV) |
0 |
2 |
2 |
|
| 94 |
0 |
| croak("strings must be an arrayref"); |
| 95 |
2 |
| av = (AV *)SvRV(strings); |
| 96 |
2 |
| n = av_len(av) + 1; |
| 97 |
2 |
▶ | if (!po_intern_init(&t, 16)) croak("intern"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_intern_init(&t, 16)) croak("intern"); |
0 |
2 |
2 |
|
| 98 |
|
| |
| 99 |
1011 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
1009 |
2 |
1011 |
|
| 100 |
1009 |
| SV **e = av_fetch(av, i, 0); |
| 101 |
|
| STRLEN l; const char *p; |
| 102 |
|
| uint32_t id; |
| 103 |
1009 |
▶ | if (!e) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) continue; |
0 |
1009 |
1009 |
|
| 104 |
1009 |
| p = SvPV(*e, l); |
| 105 |
1009 |
| id = po_intern_put(&t, p, (size_t)l); |
| 106 |
1009 |
▶ | if (id == PO_SYM_NONE) { po_intern_free(&t); croak("intern full"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (id == PO_SYM_NONE) { po_intern_free(&t); croak("intern full"); } |
0 |
1009 |
1009 |
|
| 107 |
1009 |
| av_push(ids, newSVuv((UV)id)); |
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
|
| /* Round-trip through the serialised form, which is what a reader |
| 111 |
|
| * actually sees out of an mmap. */ |
| 112 |
2 |
| imglen = po_intern_size(&t); |
| 113 |
2 |
| img = (char *)malloc(imglen); |
| 114 |
2 |
▶ | if (!img) { po_intern_free(&t); croak("oom"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!img) { po_intern_free(&t); croak("oom"); } |
0 |
2 |
2 |
|
| 115 |
2 |
| po_intern_write(&t, img); |
| 116 |
|
| |
| 117 |
|
| { |
| 118 |
|
| po_intern_view v; |
| 119 |
2 |
| AV *back = newAV(); |
| 120 |
2 |
| HV *res = newHV(); |
| 121 |
2 |
▶ | if (po_intern_open(&v, img, imglen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_intern_open(&v, img, imglen)) { |
2 |
0 |
2 |
|
| 122 |
|
| uint32_t k; |
| 123 |
8 |
▶ | for (k = 0; k < v.n; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < v.n; k++) { |
6 |
2 |
8 |
|
| 124 |
6 |
| uint32_t l; const char *p = po_intern_view_get(&v, k, &l); |
| 125 |
6 |
▶ | av_push(back, p ? newSVpvn(p, l) : newSVpvs("")); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(back, p ? newSVpvn(p, l) : newSVpvs("")); |
6 |
0 |
6 |
|
| 126 |
|
| } |
| 127 |
|
| } |
| 128 |
2 |
| hv_stores(res, "ids", newRV_noinc((SV *)ids)); |
| 129 |
2 |
| hv_stores(res, "count", newSVuv((UV)t.n)); |
| 130 |
2 |
| hv_stores(res, "decoded", newRV_noinc((SV *)back)); |
| 131 |
2 |
| hv_stores(res, "bytes", newSVuv((UV)imglen)); |
| 132 |
2 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
2 |
2 |
|
| 133 |
|
| } |
| 134 |
2 |
| free(img); |
| 135 |
2 |
| po_intern_free(&t); |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
|
| # --- segments --------------------------------------------------------------- |
| 139 |
|
| |
| 140 |
|
| # Build a segment from record specs and write it. Returns the path written. |
| 141 |
|
| SV * |
| 142 |
|
| pos_write(SV *path, SV *specs, SV *tenant, SV *slot) |
| 143 |
|
| CODE: |
| 144 |
|
| { |
| 145 |
|
| po_seg_w w; |
| 146 |
|
| AV *av; |
| 147 |
|
| SSize_t i, n; |
| 148 |
|
| STRLEN plen, tlen; |
| 149 |
|
| const char *p, *tn; |
| 150 |
|
| uint8_t ulid[16]; |
| 151 |
23 |
| int ok = 1; |
| 152 |
|
| |
| 153 |
23 |
▶ | p = SvPV(path, plen); |
Branch: 1 branch
| Branch | True | False | Total |
| p = SvPV(path, plen); |
23 |
0 |
23 |
|
| 154 |
23 |
| tn = SvPV(tenant, tlen); |
| 155 |
23 |
▶ | if (!SvROK(specs) || SvTYPE(SvRV(specs)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(specs) || SvTYPE(SvRV(specs)) != SVt_PVAV) |
23 |
0 |
23 |
| if (!SvROK(specs) || SvTYPE(SvRV(specs)) != SVt_PVAV) |
0 |
23 |
23 |
|
| 156 |
0 |
| croak("specs must be an arrayref"); |
| 157 |
23 |
| av = (AV *)SvRV(specs); |
| 158 |
23 |
| n = av_len(av) + 1; |
| 159 |
|
| |
| 160 |
23 |
▶ | if (!po_seg_w_init(&w, PO_SIG_TRACE, (uint32_t)SvUV(slot), tn, (size_t)tlen)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_w_init(&w, PO_SIG_TRACE, (uint32_t)SvUV(slot), tn, (size_t)tlen)) |
0 |
23 |
23 |
|
| 161 |
0 |
| croak("seg init"); |
| 162 |
|
| |
| 163 |
734 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
711 |
23 |
734 |
|
| 164 |
711 |
| SV **e = av_fetch(av, i, 0); |
| 165 |
|
| HV *h; SV **f; |
| 166 |
|
| po_rec r; |
| 167 |
711 |
| const char *body = NULL, *labels = NULL; |
| 168 |
711 |
| STRLEN bl = 0, ll = 0; |
| 169 |
711 |
| po_u64 t = 0; |
| 170 |
711 |
| int created = 0; |
| 171 |
711 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
711 |
0 |
711 |
| if (!e || !SvROK(*e)) continue; |
0 |
711 |
711 |
|
| 172 |
711 |
| h = (HV *)SvRV(*e); |
| 173 |
711 |
| po_rec_zero(&r); |
| 174 |
711 |
| r.kind = PO_SPAN; |
| 175 |
711 |
▶ | if ((f = hv_fetchs(h, "t", 0)) && po_sv_to_u64(aTHX_ *f, &t)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "t", 0)) && po_sv_to_u64(aTHX_ *f, &t)) |
711 |
0 |
711 |
| if ((f = hv_fetchs(h, "t", 0)) && po_sv_to_u64(aTHX_ *f, &t)) |
711 |
0 |
711 |
|
| 176 |
711 |
| r.t_unix_nano = t; |
| 177 |
1422 |
▶ | if ((f = hv_fetchs(h, "body", 0))) body = SvPV(*f, bl); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "body", 0))) body = SvPV(*f, bl); |
711 |
0 |
711 |
|
| 178 |
1422 |
▶ | if ((f = hv_fetchs(h, "labels", 0))) labels = SvPV(*f, ll); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "labels", 0))) labels = SvPV(*f, ll); |
711 |
0 |
711 |
|
| 179 |
711 |
▶ | if (!po_seg_w_add(&w, &r, body, (uint32_t)bl, |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_w_add(&w, &r, body, (uint32_t)bl, |
0 |
711 |
711 |
|
| 180 |
0 |
| labels, (uint32_t)ll, &created)) { ok = 0; break; } |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
391 |
▶ | for (i = 0; i < 16; i++) ulid[i] = (uint8_t)(i * 7 + 3); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < 16; i++) ulid[i] = (uint8_t)(i * 7 + 3); |
368 |
23 |
391 |
|
| 184 |
23 |
▶ | if (ok) ok = po_seg_write(&w, p, ulid); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) ok = po_seg_write(&w, p, ulid); |
23 |
0 |
23 |
|
| 185 |
23 |
| po_seg_w_free(&w); |
| 186 |
23 |
▶ | RETVAL = ok ? newSVpv(p, 0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ok ? newSVpv(p, 0) : &PL_sv_undef; |
23 |
0 |
23 |
|
| 187 |
|
| } |
| 188 |
|
| OUTPUT: |
| 189 |
|
| RETVAL |
| 190 |
|
| |
| 191 |
|
| # Parse an in-memory image. Separated from mmap so a test can hand it a |
| 192 |
|
| # deliberately damaged buffer with no filesystem in the way. |
| 193 |
|
| SV * |
| 194 |
|
| pos_parse(SV *buf) |
| 195 |
|
| CODE: |
| 196 |
|
| { |
| 197 |
|
| po_seg_r s; |
| 198 |
|
| STRLEN len; |
| 199 |
|
| const char *p; |
| 200 |
1458 |
| p = SvPV(buf, len); |
| 201 |
1458 |
| memset(&s, 0, sizeof(s)); |
| 202 |
1458 |
| s.fd = -1; |
| 203 |
1458 |
▶ | if (!po_seg_parse(&s, p, (size_t)len)) RETVAL = &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_parse(&s, p, (size_t)len)) RETVAL = &PL_sv_undef; |
1454 |
4 |
1458 |
|
| 204 |
|
| else { |
| 205 |
4 |
| HV *res = newHV(); |
| 206 |
4 |
| hv_stores(res, "records", po_u64_to_sv((po_u64)s.n)); |
| 207 |
4 |
| hv_stores(res, "t_min", po_u64_to_sv(s.hdr.t_min)); |
| 208 |
4 |
| hv_stores(res, "t_max", po_u64_to_sv(s.hdr.t_max)); |
| 209 |
4 |
| hv_stores(res, "signal", newSVuv((UV)s.hdr.signal)); |
| 210 |
4 |
| hv_stores(res, "slot", newSVuv((UV)s.hdr.worker_slot)); |
| 211 |
4 |
| hv_stores(res, "symbols", newSVuv((UV)s.sym.n)); |
| 212 |
4 |
| RETVAL = newRV_noinc((SV *)res); |
| 213 |
|
| } |
| 214 |
|
| } |
| 215 |
|
| OUTPUT: |
| 216 |
|
| RETVAL |
| 217 |
|
| |
| 218 |
|
| # mmap a segment and read its bodies back through the symbol table. |
| 219 |
|
| void |
| 220 |
|
| pos_read(SV *path) |
| 221 |
|
| PPCODE: |
| 222 |
|
| { |
| 223 |
|
| po_seg_r s; |
| 224 |
|
| STRLEN plen; |
| 225 |
6 |
| const char *p = SvPV(path, plen); |
| 226 |
6 |
| AV *out = newAV(); |
| 227 |
6 |
▶ | if (!po_seg_open(&s, p)) { mXPUSHs(&PL_sv_undef); XSRETURN(1); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (!po_seg_open(&s, p)) { mXPUSHs(&PL_sv_undef); XSRETURN(1); } |
2 |
4 |
6 |
| if (!po_seg_open(&s, p)) { mXPUSHs(&PL_sv_undef); XSRETURN(1); } |
0 |
2 |
2 |
|
| 228 |
|
| { |
| 229 |
|
| size_t i; |
| 230 |
81 |
▶ | for (i = 0; i < s.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < s.n; i++) { |
77 |
4 |
81 |
|
| 231 |
77 |
| HV *h = newHV(); |
| 232 |
77 |
| uint32_t l = 0; |
| 233 |
77 |
| const char *b = po_intern_view_get(&s.sym, s.rec[i].body_off, &l); |
| 234 |
77 |
| hv_stores(h, "t", po_u64_to_sv(s.rec[i].t_unix_nano)); |
| 235 |
77 |
| hv_stores(h, "series", po_u64_to_sv(s.rec[i].series)); |
| 236 |
77 |
▶ | hv_stores(h, "body", b ? newSVpvn(b, l) : newSVpvs("")); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_stores(h, "body", b ? newSVpvn(b, l) : newSVpvs("")); |
77 |
0 |
77 |
|
| 237 |
77 |
| av_push(out, newRV_noinc((SV *)h)); |
| 238 |
|
| } |
| 239 |
|
| } |
| 240 |
|
| { |
| 241 |
4 |
| HV *res = newHV(); |
| 242 |
4 |
| hv_stores(res, "records", newRV_noinc((SV *)out)); |
| 243 |
4 |
| hv_stores(res, "t_min", po_u64_to_sv(s.hdr.t_min)); |
| 244 |
4 |
| hv_stores(res, "t_max", po_u64_to_sv(s.hdr.t_max)); |
| 245 |
4 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
4 |
4 |
|
| 246 |
|
| } |
| 247 |
4 |
| po_seg_close(&s); |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
|
| # Does a segment's span overlap a range? The pruning that makes a query over |
| 251 |
|
| # an hour not open a week. |
| 252 |
|
| int |
| 253 |
|
| pos_overlaps(SV *path, SV *from, SV *to) |
| 254 |
|
| CODE: |
| 255 |
|
| { |
| 256 |
|
| po_seg_r s; |
| 257 |
|
| STRLEN plen; |
| 258 |
6 |
| const char *p = SvPV(path, plen); |
| 259 |
6 |
| po_u64 a = 0, b = 0; |
| 260 |
6 |
| (void)po_sv_to_u64(aTHX_ from, &a); |
| 261 |
6 |
| (void)po_sv_to_u64(aTHX_ to, &b); |
| 262 |
6 |
▶ | if (!po_seg_open(&s, p)) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_seg_open(&s, p)) XSRETURN_UNDEF; |
0 |
6 |
6 |
|
| 263 |
6 |
| RETVAL = po_seg_overlaps(&s, a, b); |
| 264 |
6 |
| po_seg_close(&s); |
| 265 |
|
| } |
| 266 |
|
| OUTPUT: |
| 267 |
|
| RETVAL |
| 268 |
|
| |
| 269 |
|
| # --- the shared arena ------------------------------------------------------- |
| 270 |
|
| |
| 271 |
|
| SV * |
| 272 |
|
| pos_shm_new(SV *cap) |
| 273 |
|
| CODE: |
| 274 |
|
| { |
| 275 |
|
| po_shared *s; |
| 276 |
32 |
| po_u64 c = 0; |
| 277 |
32 |
| (void)po_sv_to_u64(aTHX_ cap, &c); |
| 278 |
32 |
| Newxz(s, 1, po_shared); |
| 279 |
32 |
▶ | if (!po_shared_init(s, c)) { Safefree(s); XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_shared_init(s, c)) { Safefree(s); XSRETURN_UNDEF; } |
0 |
32 |
32 |
|
| 280 |
32 |
| RETVAL = newSViv(PTR2IV(s)); |
| 281 |
|
| } |
| 282 |
|
| OUTPUT: |
| 283 |
|
| RETVAL |
| 284 |
|
| |
| 285 |
|
| void |
| 286 |
|
| pos_shm_rotate(SV *h) |
| 287 |
|
| CODE: |
| 288 |
|
| { |
| 289 |
2 |
| po_shared *s = INT2PTR(po_shared *, SvIV(h)); |
| 290 |
|
| #if defined(PO_HAVE_ATOMICS) && !defined(_WIN32) |
| 291 |
2 |
▶ | if (s->ok && s->m) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->ok && s->m) { |
2 |
0 |
2 |
| if (s->ok && s->m) { |
2 |
0 |
2 |
|
| 292 |
2 |
| __atomic_store_n(&s->m->epoch_start, po_now_ns(), |
| 293 |
|
| __ATOMIC_SEQ_CST); |
| 294 |
2 |
| po_shm_rotate(s->m); |
| 295 |
|
| } |
| 296 |
|
| #endif |
| 297 |
|
| } |
| 298 |
|
| |
| 299 |
|
| void |
| 300 |
|
| pos_shm_window(SV *h, SV *ns) |
| 301 |
|
| CODE: |
| 302 |
|
| { |
| 303 |
0 |
| po_shared *s = INT2PTR(po_shared *, SvIV(h)); |
| 304 |
0 |
| po_u64 w = 0; |
| 305 |
0 |
| (void)po_sv_to_u64(aTHX_ ns, &w); |
| 306 |
0 |
▶ | if (s->ok && s->m) s->m->window_ns = w; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->ok && s->m) s->m->window_ns = w; |
0 |
0 |
0 |
| if (s->ok && s->m) s->m->window_ns = w; |
0 |
0 |
0 |
|
| 307 |
|
| } |
| 308 |
|
| |
| 309 |
|
| int |
| 310 |
|
| pos_shm_admit(SV *h) |
| 311 |
|
| CODE: |
| 312 |
128 |
| RETVAL = po_shared_admit_series(INT2PTR(po_shared *, SvIV(h))); |
| 313 |
|
| OUTPUT: |
| 314 |
|
| RETVAL |
| 315 |
|
| |
| 316 |
|
| void |
| 317 |
|
| pos_shm_stats(SV *h) |
| 318 |
|
| PPCODE: |
| 319 |
|
| { |
| 320 |
50 |
| po_shared *s = INT2PTR(po_shared *, SvIV(h)); |
| 321 |
50 |
| HV *res = newHV(); |
| 322 |
50 |
| hv_stores(res, "series", po_u64_to_sv(s->m->series)); |
| 323 |
50 |
| hv_stores(res, "series_cap", po_u64_to_sv(s->m->series_cap)); |
| 324 |
50 |
| hv_stores(res, "rejected", po_u64_to_sv(s->m->rejected)); |
| 325 |
50 |
| hv_stores(res, "overflow", po_u64_to_sv(s->m->overflow)); |
| 326 |
|
| /* ACCEPTED, which is not what the store holds: the store's own |
| 327 |
|
| * count is what survived retention, and this is what arrived. A |
| 328 |
|
| * receiver that is refusing everything and a receiver that is |
| 329 |
|
| * being sent nothing look identical in the store and different |
| 330 |
|
| * here. */ |
| 331 |
50 |
| hv_stores(res, "records", po_u64_to_sv(s->m->records)); |
| 332 |
50 |
| hv_stores(res, "bytes", po_u64_to_sv(s->m->bytes)); |
| 333 |
50 |
| hv_stores(res, "rate_window_start", |
| 334 |
|
| po_u64_to_sv(s->m->rate_window_start)); |
| 335 |
50 |
| hv_stores(res, "rate_records", po_u64_to_sv(s->m->rate_records)); |
| 336 |
50 |
| hv_stores(res, "rate_bytes", po_u64_to_sv(s->m->rate_bytes)); |
| 337 |
50 |
| hv_stores(res, "rate_rejected", po_u64_to_sv(s->m->rate_rejected)); |
| 338 |
50 |
| hv_stores(res, "series_window", po_u64_to_sv(s->m->window_ns)); |
| 339 |
50 |
| hv_stores(res, "live_gaps", po_u64_to_sv(s->m->live_gaps)); |
| 340 |
50 |
| hv_stores(res, "shared", newSViv(po_shared_is_shared(s))); |
| 341 |
50 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
50 |
50 |
|
| 342 |
|
| } |
| 343 |
|
| |
| 344 |
|
| void |
| 345 |
|
| pos_shm_free(SV *h) |
| 346 |
|
| CODE: |
| 347 |
|
| { |
| 348 |
14 |
| po_shared *s = INT2PTR(po_shared *, SvIV(h)); |
| 349 |
14 |
| po_shared_free(s); |
| 350 |
14 |
| Safefree(s); |
| 351 |
|
| } |
| 352 |
|
| |
| 353 |
|
| # --- the manifest ----------------------------------------------------------- |
| 354 |
|
| |
| 355 |
|
| int |
| 356 |
|
| pos_manifest_append(SV *path, SV *gen, SV *names) |
| 357 |
|
| CODE: |
| 358 |
|
| { |
| 359 |
|
| STRLEN plen; |
| 360 |
4 |
| const char *p = SvPV(path, plen); |
| 361 |
|
| AV *av; |
| 362 |
|
| SSize_t i, n; |
| 363 |
|
| const char **list; |
| 364 |
4 |
| po_u64 g = 0; |
| 365 |
4 |
| (void)po_sv_to_u64(aTHX_ gen, &g); |
| 366 |
4 |
▶ | if (!SvROK(names) || SvTYPE(SvRV(names)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(names) || SvTYPE(SvRV(names)) != SVt_PVAV) |
4 |
0 |
4 |
| if (!SvROK(names) || SvTYPE(SvRV(names)) != SVt_PVAV) |
0 |
4 |
4 |
|
| 367 |
0 |
| croak("names must be an arrayref"); |
| 368 |
4 |
| av = (AV *)SvRV(names); |
| 369 |
4 |
| n = av_len(av) + 1; |
| 370 |
4 |
▶ | Newx(list, n ? n : 1, const char *); |
Branch: 3 branches
| Branch | True | False | Total |
| Newx(list, n ? n : 1, const char *); |
4 |
0 |
4 |
| Newx(list, n ? n : 1, const char *); |
0 |
4 |
4 |
| Newx(list, n ? n : 1, const char *); |
4 |
0 |
4 |
|
| 371 |
11 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
7 |
4 |
11 |
|
| 372 |
7 |
| SV **e = av_fetch(av, i, 0); |
| 373 |
14 |
▶ | list[i] = e ? SvPV_nolen(*e) : ""; |
Branch: 1 branch
| Branch | True | False | Total |
| list[i] = e ? SvPV_nolen(*e) : ""; |
7 |
0 |
7 |
|
| 374 |
|
| } |
| 375 |
4 |
| RETVAL = po_manifest_append(p, g, list, (size_t)n); |
| 376 |
4 |
| Safefree(list); |
| 377 |
|
| } |
| 378 |
|
| OUTPUT: |
| 379 |
|
| RETVAL |
| 380 |
|
| |
| 381 |
|
| void |
| 382 |
|
| pos_manifest_latest(SV *buf) |
| 383 |
|
| PPCODE: |
| 384 |
|
| { |
| 385 |
|
| STRLEN len; |
| 386 |
15 |
| const char *p = SvPV(buf, len); |
| 387 |
15 |
| size_t off = 0, nlen = 0, count = 0; |
| 388 |
15 |
| po_u64 g = po_manifest_latest(p, (size_t)len, &off, &nlen, &count); |
| 389 |
15 |
| HV *res = newHV(); |
| 390 |
15 |
| AV *names = newAV(); |
| 391 |
15 |
▶ | if (g) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (g) { |
13 |
2 |
15 |
|
| 392 |
13 |
| size_t i = off, end = off + nlen; |
| 393 |
38 |
▶ | while (i < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < end) { |
25 |
13 |
38 |
|
| 394 |
25 |
| size_t e = i; |
| 395 |
157 |
▶ | while (e < end && p[e] != '\n') e++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (e < end && p[e] != '\n') e++; |
157 |
0 |
157 |
| while (e < end && p[e] != '\n') e++; |
132 |
25 |
157 |
|
| 396 |
25 |
| av_push(names, newSVpvn(p + i, e - i)); |
| 397 |
25 |
| i = e + 1; |
| 398 |
|
| } |
| 399 |
|
| } |
| 400 |
15 |
| hv_stores(res, "generation", po_u64_to_sv(g)); |
| 401 |
15 |
| hv_stores(res, "names", newRV_noinc((SV *)names)); |
| 402 |
15 |
| hv_stores(res, "count", newSVuv((UV)count)); |
| 403 |
15 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
15 |
15 |
|
| 404 |
|
| } |