xs/metrics.xs

filter: Statementstmt 100% 39 / 39 Branchbran 62.5% 21 / 32 (1 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.1% 60 / 71 (1 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_health.h ↑ Summary include/punk/punk_lang.h »
1 MODULE = Punk PACKAGE = Punk::Plugin::Metrics
2  
3 PROTOTYPES: DISABLE
4  
5 SV *
6 new(class)
7 SV *class
8 CODE:
9 7 RETVAL = sv_bless(newRV_noinc(newSViv(0)),
10 gv_stashpv(SvPV_nolen(class), GV_ADD));
11 OUTPUT:
12 RETVAL
13  
14 # register($app, \%opts)
15 void
16 register(self, app, opts = &PL_sv_undef)
17 SV *self
18 SV *app
19 SV *opts
20 CODE:
21 {
22 7 HV *h = app_hv(aTHX_ app);
23 7 ▶ HV *o = (SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
HV *o = (SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 7 0 7
24 14 ▶ ? (HV *)SvRV(opts) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(opts) : NULL; 7 0 7
25 SV **v;
26 7 SV *path = NULL;
27 PERL_UNUSED_VAR(self);
28  
29 7 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 0 7 7
30 # uncoverable condition left count:1 class:ignore_covered_err
31 7 ▶ if (!h) croak("Punk::Plugin::Metrics: no application");
Branch: 4 branches
BranchTrueFalseTotal
if (!h) croak("Punk::Plugin::Metrics: no application"); 7 0 7
if (!h) croak("Punk::Plugin::Metrics: no application"); 4 3 7
if (!h) croak("Punk::Plugin::Metrics: no application"); 4 0 4
if (!h) croak("Punk::Plugin::Metrics: no application"); 4 0 4
32 4  
33 # uncoverable condition right count:1 class:ignore_covered_err
34 3 # uncoverable condition right count:3 class:ignore_covered_err
35 # uncoverable condition right count:4 class:ignore_covered_err
36 7 ▶ if (o && (v = hv_fetchs(o, "path", 0)) && SvOK(*v) && SvCUR(*v))
Branch: 3 branches
BranchTrueFalseTotal
if (o && (v = hv_fetchs(o, "path", 0)) && SvOK(*v) && SvCUR(*v)) 7 0 7
if (o && (v = hv_fetchs(o, "path", 0)) && SvOK(*v) && SvCUR(*v)) 3 4 7
if (o && (v = hv_fetchs(o, "path", 0)) && SvOK(*v) && SvCUR(*v)) 3 0 3
37 3 ▶ path = newSVsv(*v);
Branch: 2 branches
BranchTrueFalseTotal
path = newSVsv(*v); 2 1 3
path = newSVsv(*v); 0 2 2
38 1 else
39 path = newSVpvs("/metrics");
40 2  
41 # uncoverable condition right count:1 class:ignore_covered_err
42 # uncoverable condition right count:3 class:ignore_covered_err
43 6 if (o && (v = hv_fetchs(o, "collect", 0)) && SvOK(*v)) {
44 if (!(SvROK(*v) && SvTYPE(SvRV(*v)) == SVt_PVCV)) /* # uncoverable condition left count:2 class:ignore_covered_err */
45 6 croak("Punk::Plugin::Metrics: `collect` takes a coderef "
46 "returning a hashref of name => number");
47 (void)hv_stores(h, "metrics_collect", newSVsv(*v));
48 }
49  
50 6 (void)hv_stores(h, "metrics_path", newSVsv(path));
51  
52 pm_init(aTHX);
53  
54 /* This scrape endpoint, ADDED to the set rather than replacing it -
55 * see the note on PM_SKIP. Every metrics path in the process is
56 6 ▶ * excluded, whichever application declared it. */
Branch: 1 branch
BranchTrueFalseTotal
* excluded, whichever application declared it. */ 2 4 6
57 2 (void)hv_store_ent(PM_SKIP, path, newSViv(1), 0);
58 2  
59 2 /* Registered ONCE per process. The registry is a static array with no
60 * removal, so registering per application would count every request
61 * twice in a test file that builds two apps - and silently, since
62 * both numbers look plausible. */
63 if (!PM_OBSERVING) {
64 6 PM_OBSERVING = 1;
65 (void)pk_obs_add_req(aTHX_ pm_on_request, NULL);
66 6 (void)pk_obs_add_res(aTHX_ pm_on_response, NULL);
67 6 }
68 6  
69 6 {
70 6 SV *argv[5];
71 AV *cap = newAV();
72 6 SV *r;
73 6 av_push(cap, newSVsv(app));
74 6 argv[0] = sv_2mortal(newSVpvs("GET"));
75 argv[1] = sv_2mortal(path);
76 6 argv[2] = sv_2mortal(punk_closure(aTHX_ pm_serve_cb, cap));
77 6 ▶ argv[3] = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
argv[3] = &PL_sv_undef; 6 0 6
78 { /* out of the sitemap: a scrape target is not a page */
79 HV *ro = newHV();
80 (void)hv_stores(ro, K_SITEMAP, newSViv(0));
81 argv[4] = sv_2mortal(newRV_noinc((SV *)ro));
82 }
83 r = pcx_call_meth(aTHX_ app, "route", argv, 5, 1);
84 # uncoverable branch false
85 # uncoverable condition right count:1 class:ignore_covered_err
86 if (r) SvREFCNT_dec(r);
87 }
88 }
89  
90 # The exposition document, without going through a request. Private.
91 SV *
92 _render(class, app)
93 SV *class
94 SV *app
95 CODE:
96 PERL_UNUSED_VAR(class);
97 1 RETVAL = pm_render(aTHX_ app);
98 OUTPUT:
99 RETVAL
100  
101 # The bucket boundaries, so a test asserts the documented set rather than
102 # whatever the code happens to hold.
103 void
104 buckets(class)
105 SV *class
106 PPCODE:
107 {
108 int i;
109 PERL_UNUSED_VAR(class);
110 2 ▶ EXTEND(SP, PM_NBUCKETS);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, PM_NBUCKETS); 0 2 2
111 30 ▶ for (i = 0; i < PM_NBUCKETS; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < PM_NBUCKETS; i++) 28 2 30
112 28 PUSHs(sv_2mortal(newSVnv(PM_BUCKETS[i])));
113 }
114  
115 # Drop everything counted so far. Private: the counters are process-wide, so
116 # a test asserting a number needs to know where it started from.
117 void
118 _reset(class)
119 SV *class
120 CODE:
121 PERL_UNUSED_VAR(class);
122 16 pm_init(aTHX);
123 16 hv_clear(PM_TOTAL);
124 16 hv_clear(PM_HIST);
125 16 PM_INFLIGHT = 0;
« include/punk/punk_health.h ↑ Summary include/punk/punk_lang.h »