| 1 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Alert PREFIX = poal_ |
| 2 |
|
| |
| 3 |
|
| # Drive a rule through a sequence of evaluations, moving the injected clock |
| 4 |
|
| # between them. Nothing here sleeps: every transition is a clock step. |
| 5 |
|
| void |
| 6 |
|
| poal_run(SV *rule, SV *ticks) |
| 7 |
|
| PPCODE: |
| 8 |
|
| { |
| 9 |
|
| po_al_rule r; |
| 10 |
|
| po_al_state st; |
| 11 |
|
| HV *rh; |
| 12 |
|
| SV **f; |
| 13 |
|
| AV *tv; |
| 14 |
|
| SSize_t t, nt; |
| 15 |
45 |
| AV *out = newAV(); |
| 16 |
|
| |
| 17 |
45 |
▶ | if (!SvROK(rule) || SvTYPE(SvRV(rule)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(rule) || SvTYPE(SvRV(rule)) != SVt_PVHV) |
45 |
0 |
45 |
| if (!SvROK(rule) || SvTYPE(SvRV(rule)) != SVt_PVHV) |
0 |
45 |
45 |
|
| 18 |
0 |
| croak("rule must be a hashref"); |
| 19 |
45 |
▶ | if (!SvROK(ticks) || SvTYPE(SvRV(ticks)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(ticks) || SvTYPE(SvRV(ticks)) != SVt_PVAV) |
45 |
0 |
45 |
| if (!SvROK(ticks) || SvTYPE(SvRV(ticks)) != SVt_PVAV) |
0 |
45 |
45 |
|
| 20 |
0 |
| croak("ticks must be an arrayref"); |
| 21 |
45 |
| rh = (HV *)SvRV(rule); |
| 22 |
45 |
| tv = (AV *)SvRV(ticks); |
| 23 |
|
| |
| 24 |
45 |
| memset(&r, 0, sizeof(r)); |
| 25 |
45 |
| r.op = PO_AL_GT; |
| 26 |
45 |
▶ | if ((f = hv_fetchs(rh, "op", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(rh, "op", 0))) { |
45 |
0 |
45 |
|
| 27 |
45 |
| STRLEN l; const char *o = SvPV(*f, l); |
| 28 |
45 |
▶ | if (l == 1 && o[0] == '>') r.op = PO_AL_GT; |
Branch: 2 branches
| Branch | True | False | Total |
| if (l == 1 && o[0] == '>') r.op = PO_AL_GT; |
40 |
5 |
45 |
| if (l == 1 && o[0] == '>') r.op = PO_AL_GT; |
39 |
1 |
40 |
|
| 29 |
6 |
▶ | else if (l == 2 && o[0] == '>' && o[1] == '=') r.op = PO_AL_GE; |
Branch: 3 branches
| Branch | True | False | Total |
| else if (l == 2 && o[0] == '>' && o[1] == '=') r.op = PO_AL_GE; |
5 |
1 |
6 |
| else if (l == 2 && o[0] == '>' && o[1] == '=') r.op = PO_AL_GE; |
2 |
3 |
5 |
| else if (l == 2 && o[0] == '>' && o[1] == '=') r.op = PO_AL_GE; |
2 |
0 |
2 |
|
| 30 |
4 |
▶ | else if (l == 1 && o[0] == '<') r.op = PO_AL_LT; |
Branch: 2 branches
| Branch | True | False | Total |
| else if (l == 1 && o[0] == '<') r.op = PO_AL_LT; |
1 |
3 |
4 |
| else if (l == 1 && o[0] == '<') r.op = PO_AL_LT; |
1 |
0 |
1 |
|
| 31 |
3 |
▶ | else if (l == 2 && o[0] == '<' && o[1] == '=') r.op = PO_AL_LE; |
Branch: 3 branches
| Branch | True | False | Total |
| else if (l == 2 && o[0] == '<' && o[1] == '=') r.op = PO_AL_LE; |
3 |
0 |
3 |
| else if (l == 2 && o[0] == '<' && o[1] == '=') r.op = PO_AL_LE; |
1 |
2 |
3 |
| else if (l == 2 && o[0] == '<' && o[1] == '=') r.op = PO_AL_LE; |
1 |
0 |
1 |
|
| 32 |
2 |
▶ | else if (l == 2 && o[0] == '=' && o[1] == '=') r.op = PO_AL_EQ; |
Branch: 3 branches
| Branch | True | False | Total |
| else if (l == 2 && o[0] == '=' && o[1] == '=') r.op = PO_AL_EQ; |
2 |
0 |
2 |
| else if (l == 2 && o[0] == '=' && o[1] == '=') r.op = PO_AL_EQ; |
1 |
1 |
2 |
| else if (l == 2 && o[0] == '=' && o[1] == '=') r.op = PO_AL_EQ; |
1 |
0 |
1 |
|
| 33 |
1 |
▶ | else if (l == 2 && o[0] == '!' && o[1] == '=') r.op = PO_AL_NE; |
Branch: 3 branches
| Branch | True | False | Total |
| else if (l == 2 && o[0] == '!' && o[1] == '=') r.op = PO_AL_NE; |
1 |
0 |
1 |
| else if (l == 2 && o[0] == '!' && o[1] == '=') r.op = PO_AL_NE; |
1 |
0 |
1 |
| else if (l == 2 && o[0] == '!' && o[1] == '=') r.op = PO_AL_NE; |
1 |
0 |
1 |
|
| 34 |
|
| } |
| 35 |
45 |
▶ | if ((f = hv_fetchs(rh, "threshold", 0))) r.threshold = SvNV(*f); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(rh, "threshold", 0))) r.threshold = SvNV(*f); |
45 |
0 |
45 |
|
| 36 |
45 |
▶ | if ((f = hv_fetchs(rh, "for", 0))) (void)po_sv_to_u64(aTHX_ *f, &r.for_ns); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(rh, "for", 0))) (void)po_sv_to_u64(aTHX_ *f, &r.for_ns); |
45 |
0 |
45 |
|
| 37 |
45 |
▶ | if ((f = hv_fetchs(rh, "every", 0))) (void)po_sv_to_u64(aTHX_ *f, &r.every_ns); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(rh, "every", 0))) (void)po_sv_to_u64(aTHX_ *f, &r.every_ns); |
45 |
0 |
45 |
|
| 38 |
45 |
▶ | if (!r.every_ns) r.every_ns = PO_NS_PER_SEC; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r.every_ns) r.every_ns = PO_NS_PER_SEC; |
0 |
45 |
45 |
|
| 39 |
|
| |
| 40 |
45 |
| po_al_init(&st); |
| 41 |
45 |
| nt = av_len(tv) + 1; |
| 42 |
|
| |
| 43 |
138 |
▶ | for (t = 0; t < nt; t++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (t = 0; t < nt; t++) { |
93 |
45 |
138 |
|
| 44 |
93 |
| SV **e = av_fetch(tv, t, 0); |
| 45 |
|
| HV *th; |
| 46 |
|
| po_al_row rows[64]; |
| 47 |
93 |
| uint32_t nrows = 0; |
| 48 |
93 |
| int status = PO_EVAL_OK; |
| 49 |
93 |
| po_u64 at = 0; |
| 50 |
|
| HV *res; |
| 51 |
|
| AV *notes, *states; |
| 52 |
|
| uint32_t i; |
| 53 |
|
| |
| 54 |
93 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
93 |
0 |
93 |
| if (!e || !SvROK(*e)) continue; |
0 |
93 |
93 |
|
| 55 |
93 |
| th = (HV *)SvRV(*e); |
| 56 |
|
| |
| 57 |
93 |
▶ | if ((f = hv_fetchs(th, "at", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(th, "at", 0))) { |
93 |
0 |
93 |
|
| 58 |
93 |
| (void)po_sv_to_u64(aTHX_ *f, &at); |
| 59 |
93 |
| po_clock_freeze(at); |
| 60 |
|
| } |
| 61 |
93 |
▶ | if ((f = hv_fetchs(th, "fail", 0)) && SvTRUE(*f)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(th, "fail", 0)) && SvTRUE(*f)) |
15 |
78 |
93 |
| if ((f = hv_fetchs(th, "fail", 0)) && SvTRUE(*f)) |
15 |
0 |
15 |
|
| 62 |
15 |
| status = PO_EVAL_FAIL; |
| 63 |
|
| |
| 64 |
93 |
▶ | if ((f = hv_fetchs(th, "rows", 0)) && SvROK(*f)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(th, "rows", 0)) && SvROK(*f)) { |
78 |
15 |
93 |
| if ((f = hv_fetchs(th, "rows", 0)) && SvROK(*f)) { |
78 |
0 |
78 |
|
| 65 |
78 |
| AV *ra = (AV *)SvRV(*f); |
| 66 |
78 |
| SSize_t j, nr = av_len(ra) + 1; |
| 67 |
158 |
▶ | for (j = 0; j < nr && nrows < 64; j += 2) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (j = 0; j < nr && nrows < 64; j += 2) { |
80 |
78 |
158 |
| for (j = 0; j < nr && nrows < 64; j += 2) { |
80 |
0 |
80 |
|
| 68 |
80 |
| SV **k = av_fetch(ra, j, 0); |
| 69 |
80 |
| SV **v = av_fetch(ra, j + 1, 0); |
| 70 |
80 |
▶ | if (!k || !v) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!k || !v) break; |
80 |
0 |
80 |
| if (!k || !v) break; |
80 |
0 |
80 |
|
| 71 |
80 |
| rows[nrows].key = SvPV(*k, rows[nrows].key_len); |
| 72 |
80 |
| rows[nrows].value = SvNV(*v); |
| 73 |
80 |
| nrows++; |
| 74 |
|
| } |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
93 |
| po_al_step(&st, &r, status, rows, nrows); |
| 78 |
|
| |
| 79 |
93 |
| res = newHV(); |
| 80 |
93 |
| notes = newAV(); |
| 81 |
93 |
| states = newAV(); |
| 82 |
132 |
▶ | for (i = 0; i < st.nnote; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < st.nnote; i++) { |
39 |
93 |
132 |
|
| 83 |
39 |
| HV *n = newHV(); |
| 84 |
39 |
| hv_stores(n, "series", newSVpvn(st.note[i].key, |
| 85 |
|
| st.note[i].key_len)); |
| 86 |
39 |
| hv_stores(n, "kind", newSViv(st.note[i].kind)); |
| 87 |
39 |
| hv_stores(n, "from", newSVpv(po_al_state_name(st.note[i].from), 0)); |
| 88 |
39 |
| hv_stores(n, "to", newSVpv(po_al_state_name(st.note[i].to), 0)); |
| 89 |
39 |
| hv_stores(n, "at", po_u64_to_sv(st.note[i].at)); |
| 90 |
39 |
| hv_stores(n, "fired_at", po_u64_to_sv(st.note[i].fired_at)); |
| 91 |
39 |
| av_push(notes, newRV_noinc((SV *)n)); |
| 92 |
|
| } |
| 93 |
192 |
▶ | for (i = 0; i < st.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < st.n; i++) { |
99 |
93 |
192 |
|
| 94 |
99 |
| HV *s = newHV(); |
| 95 |
99 |
| hv_stores(s, "series", newSVpvn(st.s[i].key, st.s[i].key_len)); |
| 96 |
99 |
| hv_stores(s, "state", newSVpv(po_al_state_name(st.s[i].state), 0)); |
| 97 |
99 |
| hv_stores(s, "since", po_u64_to_sv(st.s[i].since)); |
| 98 |
99 |
| hv_stores(s, "fired_at", po_u64_to_sv(st.s[i].fired_at)); |
| 99 |
99 |
| av_push(states, newRV_noinc((SV *)s)); |
| 100 |
|
| } |
| 101 |
93 |
| hv_stores(res, "notes", newRV_noinc((SV *)notes)); |
| 102 |
93 |
| hv_stores(res, "states", newRV_noinc((SV *)states)); |
| 103 |
93 |
| av_push(out, newRV_noinc((SV *)res)); |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
45 |
| po_clock_real(); |
| 107 |
45 |
▶ | mXPUSHs(newRV_noinc((SV *)out)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)out)); |
0 |
45 |
45 |
|
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Route PREFIX = poro_ |
| 111 |
|
| |
| 112 |
|
| # Grouping, silences and the outbox, driven by the same injected clock. |
| 113 |
|
| void |
| 114 |
|
| poro_run(SV *opts, SV *events) |
| 115 |
|
| PPCODE: |
| 116 |
|
| { |
| 117 |
|
| po_router rt; |
| 118 |
|
| po_outbox ob; |
| 119 |
|
| po_silences sl; |
| 120 |
|
| HV *o; |
| 121 |
|
| SV **f; |
| 122 |
|
| AV *ev; |
| 123 |
|
| SSize_t i, n; |
| 124 |
14 |
| po_u64 wait = 0, repeat = 0; |
| 125 |
14 |
| AV *sent = newAV(); |
| 126 |
14 |
| HV *res = newHV(); |
| 127 |
14 |
| IV enqueued = 0, deduped = 0; |
| 128 |
|
| |
| 129 |
14 |
▶ | if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV) |
14 |
0 |
14 |
| if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV) |
0 |
14 |
14 |
|
| 130 |
0 |
| croak("opts must be a hashref"); |
| 131 |
14 |
▶ | if (!SvROK(events) || SvTYPE(SvRV(events)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(events) || SvTYPE(SvRV(events)) != SVt_PVAV) |
14 |
0 |
14 |
| if (!SvROK(events) || SvTYPE(SvRV(events)) != SVt_PVAV) |
0 |
14 |
14 |
|
| 132 |
0 |
| croak("events must be an arrayref"); |
| 133 |
14 |
| o = (HV *)SvRV(opts); |
| 134 |
14 |
| ev = (AV *)SvRV(events); |
| 135 |
|
| |
| 136 |
14 |
▶ | if ((f = hv_fetchs(o, "group_wait", 0))) (void)po_sv_to_u64(aTHX_ *f, &wait); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(o, "group_wait", 0))) (void)po_sv_to_u64(aTHX_ *f, &wait); |
14 |
0 |
14 |
|
| 137 |
14 |
▶ | if ((f = hv_fetchs(o, "repeat_interval", 0))) (void)po_sv_to_u64(aTHX_ *f, &repeat); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(o, "repeat_interval", 0))) (void)po_sv_to_u64(aTHX_ *f, &repeat); |
1 |
13 |
14 |
|
| 138 |
14 |
| po_router_init(&rt, wait, repeat); |
| 139 |
14 |
| po_outbox_init(&ob); |
| 140 |
14 |
| po_silences_init(&sl); |
| 141 |
|
| |
| 142 |
14 |
▶ | if ((f = hv_fetchs(o, "silences", 0)) && SvROK(*f)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(o, "silences", 0)) && SvROK(*f)) { |
3 |
11 |
14 |
| if ((f = hv_fetchs(o, "silences", 0)) && SvROK(*f)) { |
3 |
0 |
3 |
|
| 143 |
3 |
| AV *sa = (AV *)SvRV(*f); |
| 144 |
3 |
| SSize_t j, ns = av_len(sa) + 1; |
| 145 |
6 |
▶ | for (j = 0; j < ns; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < ns; j++) { |
3 |
3 |
6 |
|
| 146 |
3 |
| SV **e = av_fetch(sa, j, 0); |
| 147 |
|
| HV *h; SV **g; |
| 148 |
3 |
| STRLEN pl = 0; |
| 149 |
3 |
| const char *pat = ""; |
| 150 |
3 |
| int prefix = 0; |
| 151 |
3 |
| po_u64 until = 0; |
| 152 |
3 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
3 |
0 |
3 |
| if (!e || !SvROK(*e)) continue; |
0 |
3 |
3 |
|
| 153 |
3 |
| h = (HV *)SvRV(*e); |
| 154 |
6 |
▶ | if ((g = hv_fetchs(h, "pattern", 0))) pat = SvPV(*g, pl); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "pattern", 0))) pat = SvPV(*g, pl); |
3 |
0 |
3 |
|
| 155 |
3 |
▶ | if ((g = hv_fetchs(h, "prefix", 0))) prefix = SvTRUE(*g); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "prefix", 0))) prefix = SvTRUE(*g); |
1 |
2 |
3 |
|
| 156 |
3 |
▶ | if ((g = hv_fetchs(h, "until", 0))) (void)po_sv_to_u64(aTHX_ *g, &until); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "until", 0))) (void)po_sv_to_u64(aTHX_ *g, &until); |
1 |
2 |
3 |
|
| 157 |
3 |
| po_silence_add(&sl, pat, (size_t)pl, prefix, until); |
| 158 |
|
| } |
| 159 |
|
| } |
| 160 |
|
| |
| 161 |
14 |
| n = av_len(ev) + 1; |
| 162 |
125 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
111 |
14 |
125 |
|
| 163 |
111 |
| SV **e = av_fetch(ev, i, 0); |
| 164 |
|
| HV *h; SV **g; |
| 165 |
111 |
| po_u64 at = 0, rule = 0, fired = 0; |
| 166 |
111 |
| STRLEN gl = 0, sn = 0; |
| 167 |
111 |
| const char *gk = "", *series = ""; |
| 168 |
|
| int silenced; |
| 169 |
|
| |
| 170 |
111 |
▶ | if (!e || !SvROK(*e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e)) continue; |
111 |
0 |
111 |
| if (!e || !SvROK(*e)) continue; |
0 |
111 |
111 |
|
| 171 |
111 |
| h = (HV *)SvRV(*e); |
| 172 |
111 |
▶ | if ((g = hv_fetchs(h, "at", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "at", 0))) { |
111 |
0 |
111 |
|
| 173 |
111 |
| (void)po_sv_to_u64(aTHX_ *g, &at); |
| 174 |
111 |
| po_clock_freeze(at); |
| 175 |
|
| } |
| 176 |
215 |
▶ | if ((g = hv_fetchs(h, "group", 0))) gk = SvPV(*g, gl); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "group", 0))) gk = SvPV(*g, gl); |
104 |
7 |
111 |
|
| 177 |
215 |
▶ | if ((g = hv_fetchs(h, "series", 0))) series = SvPV(*g, sn); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "series", 0))) series = SvPV(*g, sn); |
104 |
7 |
111 |
|
| 178 |
111 |
▶ | if ((g = hv_fetchs(h, "rule", 0))) (void)po_sv_to_u64(aTHX_ *g, &rule); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "rule", 0))) (void)po_sv_to_u64(aTHX_ *g, &rule); |
104 |
7 |
111 |
|
| 179 |
111 |
▶ | if ((g = hv_fetchs(h, "fired_at", 0))) (void)po_sv_to_u64(aTHX_ *g, &fired); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((g = hv_fetchs(h, "fired_at", 0))) (void)po_sv_to_u64(aTHX_ *g, &fired); |
104 |
7 |
111 |
|
| 180 |
|
| |
| 181 |
|
| /* A "drain" event carries no series: it is the sender waking |
| 182 |
|
| * up to see what is due, which is how group_wait is observed |
| 183 |
|
| * at all. */ |
| 184 |
111 |
▶ | if (sn) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sn) { |
104 |
7 |
111 |
|
| 185 |
104 |
| silenced = po_is_silenced(&sl, series, (size_t)sn); |
| 186 |
104 |
| po_route_add(&rt, gk, (size_t)gl, series, (size_t)sn, silenced); |
| 187 |
104 |
▶ | if (!silenced) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!silenced) { |
101 |
3 |
104 |
|
| 188 |
101 |
▶ | if (po_outbox_put(&ob, rule, series, (size_t)sn, fired)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (po_outbox_put(&ob, rule, series, (size_t)sn, fired)) |
98 |
3 |
101 |
|
| 189 |
98 |
| enqueued++; |
| 190 |
3 |
| else deduped++; |
| 191 |
|
| } |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
23 |
| for (;;) { |
| 195 |
134 |
| po_ngroup *due = po_router_next_due(&rt); |
| 196 |
|
| HV *m; |
| 197 |
|
| AV *mem; |
| 198 |
|
| uint32_t k; |
| 199 |
134 |
▶ | if (!due) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!due) break; |
111 |
23 |
134 |
|
| 200 |
23 |
| m = newHV(); |
| 201 |
23 |
| mem = newAV(); |
| 202 |
124 |
▶ | for (k = 0; k < due->nmember; k++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < due->nmember; k++) |
101 |
23 |
124 |
|
| 203 |
101 |
| av_push(mem, newSVpvn(due->member[k], due->member_len[k])); |
| 204 |
23 |
| hv_stores(m, "group", newSVpvn(due->key, due->key_len)); |
| 205 |
23 |
| hv_stores(m, "members", newRV_noinc((SV *)mem)); |
| 206 |
23 |
| hv_stores(m, "count", newSVuv((UV)due->nmember)); |
| 207 |
23 |
| hv_stores(m, "overflow", newSVuv((UV)due->overflow)); |
| 208 |
23 |
| hv_stores(m, "at", po_u64_to_sv(po_now_ns())); |
| 209 |
23 |
| av_push(sent, newRV_noinc((SV *)m)); |
| 210 |
23 |
| po_group_mark_sent(&rt, due); |
| 211 |
|
| } |
| 212 |
|
| } |
| 213 |
|
| |
| 214 |
14 |
| hv_stores(res, "sent", newRV_noinc((SV *)sent)); |
| 215 |
14 |
| hv_stores(res, "enqueued", newSViv(enqueued)); |
| 216 |
14 |
| hv_stores(res, "deduped", newSViv(deduped)); |
| 217 |
14 |
| hv_stores(res, "pending", newSVuv((UV)po_outbox_pending(&ob))); |
| 218 |
|
| { |
| 219 |
|
| /* pending is reported BEFORE the claim loop below, which is |
| 220 |
|
| * what an operator wants to see; pending_after is what is |
| 221 |
|
| * left once a sender has taken everything it can. */ |
| 222 |
|
| /* Claim everything once, then try again: a claimed row must |
| 223 |
|
| * not be claimable by a second sender. */ |
| 224 |
14 |
| IV first = 0, second = 0; |
| 225 |
112 |
▶ | while (po_outbox_claim(&ob)) first++; |
Branch: 1 branch
| Branch | True | False | Total |
| while (po_outbox_claim(&ob)) first++; |
98 |
14 |
112 |
|
| 226 |
14 |
▶ | while (po_outbox_claim(&ob)) second++; |
Branch: 1 branch
| Branch | True | False | Total |
| while (po_outbox_claim(&ob)) second++; |
0 |
14 |
14 |
|
| 227 |
14 |
| hv_stores(res, "claimed", newSViv(first)); |
| 228 |
14 |
| hv_stores(res, "reclaimed", newSViv(second)); |
| 229 |
14 |
| hv_stores(res, "pending_after", |
| 230 |
|
| newSVuv((UV)po_outbox_pending(&ob))); |
| 231 |
|
| } |
| 232 |
14 |
| po_clock_real(); |
| 233 |
14 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
14 |
14 |
|
| 234 |
|
| } |
| 235 |
|
| |
| 236 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Target PREFIX = potg_ |
| 237 |
|
| |
| 238 |
|
| void |
| 239 |
|
| potg_check(SV *url, SV *allow) |
| 240 |
|
| PPCODE: |
| 241 |
|
| { |
| 242 |
|
| STRLEN ul; |
| 243 |
56 |
| const char *u = SvPV(url, ul); |
| 244 |
|
| const char *list[32]; |
| 245 |
|
| SV *keep[32]; |
| 246 |
56 |
| int nallow = 0, rc; |
| 247 |
56 |
| HV *res = newHV(); |
| 248 |
|
| |
| 249 |
56 |
▶ | if (SvROK(allow) && SvTYPE(SvRV(allow)) == SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(allow) && SvTYPE(SvRV(allow)) == SVt_PVAV) { |
7 |
49 |
56 |
| if (SvROK(allow) && SvTYPE(SvRV(allow)) == SVt_PVAV) { |
7 |
0 |
7 |
|
| 250 |
7 |
| AV *av = (AV *)SvRV(allow); |
| 251 |
7 |
| SSize_t i, n = av_len(av) + 1; |
| 252 |
14 |
▶ | for (i = 0; i < n && nallow < 32; i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < n && nallow < 32; i++) { |
7 |
7 |
14 |
| for (i = 0; i < n && nallow < 32; i++) { |
7 |
0 |
7 |
|
| 253 |
7 |
| SV **e = av_fetch(av, i, 0); |
| 254 |
7 |
▶ | if (!e) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) continue; |
0 |
7 |
7 |
|
| 255 |
7 |
| keep[nallow] = *e; |
| 256 |
7 |
| list[nallow] = SvPV_nolen(keep[nallow]); |
| 257 |
7 |
| nallow++; |
| 258 |
|
| } |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
56 |
▶ | rc = po_target_ok(u, (size_t)ul, nallow ? list : NULL, nallow); |
Branch: 1 branch
| Branch | True | False | Total |
| rc = po_target_ok(u, (size_t)ul, nallow ? list : NULL, nallow); |
7 |
49 |
56 |
|
| 262 |
56 |
| hv_stores(res, "ok", newSViv(rc == PO_TGT_OK)); |
| 263 |
56 |
| hv_stores(res, "code", newSViv(rc)); |
| 264 |
56 |
| hv_stores(res, "reason", newSVpv(po_tgt_reason(rc), 0)); |
| 265 |
56 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
56 |
56 |
|
| 266 |
|
| } |
| 267 |
|
| |
| 268 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe::Dashboard PREFIX = podb_ |
| 269 |
|
| |
| 270 |
|
| # The chart kinds a panel may be, in the order po_panel.h declares them. |
| 271 |
|
| # |
| 272 |
|
| # From the C rather than a list in the editor, because the validator and the |
| 273 |
|
| # picker disagreeing is how a panel gets saved as something the renderer will |
| 274 |
|
| # not draw. |
| 275 |
|
| void |
| 276 |
|
| podb_viz_names() |
| 277 |
|
| PPCODE: |
| 278 |
|
| { |
| 279 |
|
| int i; |
| 280 |
168 |
▶ | for (i = 0; i <= PO_VIZ_TABLE; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= PO_VIZ_TABLE; i++) |
140 |
28 |
168 |
|
| 281 |
140 |
▶ | mXPUSHs(newSVpv(po_viz_name(i), 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVpv(po_viz_name(i), 0)); |
0 |
140 |
140 |
|
| 282 |
28 |
| XSRETURN(PO_VIZ_TABLE + 1); |
| 283 |
|
| } |
| 284 |
|
| |
| 285 |
|
| void |
| 286 |
|
| podb_check_panel(SV *spec) |
| 287 |
|
| PPCODE: |
| 288 |
|
| { |
| 289 |
|
| po_panel p; |
| 290 |
|
| HV *h; |
| 291 |
|
| SV **f; |
| 292 |
104 |
| STRLEN tl = 0, ql = 0, vl = 0; |
| 293 |
104 |
| const char *title = "", *query = "", *viz = ""; |
| 294 |
104 |
| IV position = 0, span = 1; |
| 295 |
|
| int rc; |
| 296 |
104 |
| HV *res = newHV(); |
| 297 |
|
| |
| 298 |
104 |
▶ | if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
104 |
0 |
104 |
| if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) |
0 |
104 |
104 |
|
| 299 |
0 |
| croak("spec must be a hashref"); |
| 300 |
104 |
| h = (HV *)SvRV(spec); |
| 301 |
207 |
▶ | if ((f = hv_fetchs(h, "title", 0)) && SvOK(*f)) title = SvPV(*f, tl); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "title", 0)) && SvOK(*f)) title = SvPV(*f, tl); |
104 |
0 |
104 |
| if ((f = hv_fetchs(h, "title", 0)) && SvOK(*f)) title = SvPV(*f, tl); |
103 |
1 |
104 |
|
| 302 |
208 |
▶ | if ((f = hv_fetchs(h, "query", 0)) && SvOK(*f)) query = SvPV(*f, ql); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "query", 0)) && SvOK(*f)) query = SvPV(*f, ql); |
104 |
0 |
104 |
| if ((f = hv_fetchs(h, "query", 0)) && SvOK(*f)) query = SvPV(*f, ql); |
104 |
0 |
104 |
|
| 303 |
175 |
▶ | if ((f = hv_fetchs(h, "viz", 0)) && SvOK(*f)) viz = SvPV(*f, vl); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "viz", 0)) && SvOK(*f)) viz = SvPV(*f, vl); |
71 |
33 |
104 |
| if ((f = hv_fetchs(h, "viz", 0)) && SvOK(*f)) viz = SvPV(*f, vl); |
71 |
0 |
71 |
|
| 304 |
104 |
▶ | if ((f = hv_fetchs(h, "position", 0))) position = SvIV(*f); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "position", 0))) position = SvIV(*f); |
47 |
57 |
104 |
|
| 305 |
104 |
▶ | if ((f = hv_fetchs(h, "span", 0))) span = SvIV(*f); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((f = hv_fetchs(h, "span", 0))) span = SvIV(*f); |
47 |
57 |
104 |
|
| 306 |
|
| |
| 307 |
104 |
| rc = po_panel_check(&p, title, (size_t)tl, query, (size_t)ql, |
| 308 |
|
| viz, (size_t)vl, (int)position, (int)span); |
| 309 |
104 |
| hv_stores(res, "ok", newSViv(rc == PO_PANEL_OK)); |
| 310 |
104 |
| hv_stores(res, "code", newSViv(rc)); |
| 311 |
104 |
| hv_stores(res, "error", newSVpv(p.err, 0)); |
| 312 |
104 |
| hv_stores(res, "viz", newSVpv(po_viz_name(p.viz), 0)); |
| 313 |
104 |
| hv_stores(res, "position", newSViv(p.position)); |
| 314 |
104 |
| hv_stores(res, "span", newSViv(p.span)); |
| 315 |
104 |
▶ | mXPUSHs(newRV_noinc((SV *)res)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)res)); |
0 |
104 |
104 |
|
| 316 |
|
| } |