lib/Net/Prometheus/PerlCollector.xs

filter: Statementstmt 92.5% 50 / 54 Branchbran 78.5% 33 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 86.4% 83 / 96 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Net/Prometheus/Summary.pm ↑ Summary blib/lib/Net/Prometheus/Types.pm »
1 /* You may distribute under the terms of either the GNU General Public License
2 * or the Artistic License (the same terms as Perl itself)
3 *
4 * (C) Paul Evans, 2018 -- leonerd@leonerd.org.uk
5 */
6  
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10  
11 208455 static char *sv_typename(U8 svt)
12 {
13 208455 switch(svt) {
14 66524 case SVt_NULL:
15 66524 return "NULL";
16 84144 case SVt_IV:
17 case SVt_NV:
18 case SVt_PV:
19 case SVt_PVIV:
20 case SVt_PVNV:
21 case SVt_PVMG:
22 #if PERL_VERSION < 12
23 /* SVt_RV was removed after 5.10 */
24 case SVt_RV:
25 #endif
26 84144 return "SCALAR";
27 #if PERL_VERSION >= 12
28 /* SVt_REGEXP was added in perl 5.12 */
29 1884 case SVt_REGEXP:
30 1884 return "REGEXP";
31 #endif
32 16183 case SVt_PVGV:
33 16183 return "GLOB";
34 22129 case SVt_PVAV:
35 22129 return "ARRAY";
36 4210 case SVt_PVHV:
37 4210 return "HASH";
38 13097 case SVt_PVCV:
39 13097 return "CODE";
40 0 case SVt_PVFM:
41 0 return "FORMAT";
42 24 case SVt_PVIO:
43 24 return "IO";
44 #if PERL_VERSION >= 20
45 /* SVt_INVLIST was added in perl 5.20 */
46 208 case SVt_INVLIST:
47 208 return "INVLIST";
48 #endif
49 #if PERL_VERSION >= 38
50 52 case SVt_PVOBJ:
51 52 return "OBJECT";
52 #endif
53 0 default:
54 0 return "UNKNOWN";
55 }
56 }
57  
58 MODULE = Net::Prometheus::PerlCollector PACKAGE = Net::Prometheus::PerlCollector
59  
60 void
61 count_heap(detail)
62 int detail
63 INIT:
64 SV *arena;
65 7 STRLEN arenas = 0, svs = 0;
66 7 HV *svs_by_type = NULL, *svs_by_class = NULL;
67 PPCODE:
68 7 ▶ if(detail)
Branch: 1 branch
BranchTrueFalseTotal
if(detail) 2 5 7
69 2 svs_by_type = newHV();
70 7 ▶ if(detail > 1)
Branch: 1 branch
BranchTrueFalseTotal
if(detail > 1) 1 6 7
71 1 svs_by_class = newHV();
72  
73 4380 ▶ for(arena = PL_sv_arenaroot; arena; arena = (SV *)SvANY(arena)) {
Branch: 1 branch
BranchTrueFalseTotal
for(arena = PL_sv_arenaroot; arena; arena = (SV *)SvANY(arena)) { 4373 7 4380
74 4373 const SV *arenaend = &arena[SvREFCNT(arena)];
75 SV *sv;
76  
77 4373 arenas++;
78  
79 743410 ▶ for(sv = arena + 1; sv < arenaend; sv++)
Branch: 1 branch
BranchTrueFalseTotal
for(sv = arena + 1; sv < arenaend; sv++) 739037 4373 743410
80 739037 ▶ if(SvTYPE(sv) != 0xFF && SvREFCNT(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if(SvTYPE(sv) != 0xFF && SvREFCNT(sv)) { 737986 1051 739037
if(SvTYPE(sv) != 0xFF && SvREFCNT(sv)) { 737986 0 737986
81 737986 svs++;
82  
83 737986 ▶ if(svs_by_type) {
Branch: 1 branch
BranchTrueFalseTotal
if(svs_by_type) { 208455 529531 737986
84 208455 char *type = sv_typename(SvTYPE(sv));
85 208455 SV **countp = hv_fetch(svs_by_type, type, strlen(type), 1);
86 208455 ▶ sv_setiv(*countp, SvIOK(*countp) ? SvIV(*countp) + 1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
sv_setiv(*countp, SvIOK(*countp) ? SvIV(*countp) + 1 : 1); 208435 20 208455
87  
88 208455 ▶ if(svs_by_class && SvOBJECT(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if(svs_by_class && SvOBJECT(sv)) { 104922 103533 208455
if(svs_by_class && SvOBJECT(sv)) { 309 104613 104922
89 309 ▶ char *class = HvNAME(SvSTASH(sv));
Branch: 6 branches
BranchTrueFalseTotal
char *class = HvNAME(SvSTASH(sv)); 309 0 309
char *class = HvNAME(SvSTASH(sv)); 309 0 309
char *class = HvNAME(SvSTASH(sv)); 0 309 309
char *class = HvNAME(SvSTASH(sv)); 0 0 0
char *class = HvNAME(SvSTASH(sv)); 309 0 309
char *class = HvNAME(SvSTASH(sv)); 0 309 309
90 309 SV **countp = hv_fetch(svs_by_class, class, strlen(class), 1);
91 309 ▶ sv_setiv(*countp, SvIOK(*countp) ? SvIV(*countp) + 1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
sv_setiv(*countp, SvIOK(*countp) ? SvIV(*countp) + 1 : 1); 286 23 309
92 }
93 }
94 }
95 }
96  
97 7 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 7 7
98 7 mPUSHu(arenas);
99 7 mPUSHu(svs);
100 7 ▶ if(svs_by_type)
Branch: 1 branch
BranchTrueFalseTotal
if(svs_by_type) 2 5 7
101 2 mPUSHs(newRV_noinc((SV *)svs_by_type));
102 7 ▶ if(svs_by_class)
Branch: 1 branch
BranchTrueFalseTotal
if(svs_by_class) 1 6 7
103 1 mPUSHs(newRV_noinc((SV *)svs_by_class));
104 7 ▶ XSRETURN(2 + !!svs_by_type + !!svs_by_class);
Branch: 1 branch
BranchTrueFalseTotal
XSRETURN(2 + !!svs_by_type + !!svs_by_class); 2 5 7
« blib/lib/Net/Prometheus/Summary.pm ↑ Summary blib/lib/Net/Prometheus/Types.pm »