Mallinfo.xs

filter: Statementstmt 86.2% 25 / 29 Branchbran 53.1% 17 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 68.8% 42 / 61 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Devel/config.pl ↑ Summary blib/lib/Devel/Mallinfo.pm »
1 /* Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde
2  
3 This file is part of Devel-Mallinfo.
4  
5 Devel-Mallinfo is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any later
8 version.
9  
10 Devel-Mallinfo is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14  
15 You should have received a copy of the GNU General Public License along
16 with Devel-Mallinfo. If not, see <http://www.gnu.org/licenses/>. */
17  
18 #include "config.h"
19  
20 #include <stdlib.h>
21 #if HAVE_MALLOC_H
22 #include <malloc.h>
23 #endif
24  
25 #include "EXTERN.h"
26 #include "perl.h"
27 #include "XSUB.h"
28  
29 #include "ppport.h"
30  
31 /* for testing ... */
32 /* #define tmpfile() fopen("/tmp/fullfs/tmp/tmpfile","w+b") */
33  
34  
35 #if HAVE_MALLOC_INFO
36 static void
37 2 slurp_fp_to_sv (FILE *fp, SV *sv)
38 {
39 char buf[256];
40 int got;
41 2 sv_setpvn (sv, "", 0);
42 for (;;) {
43 9 got = fread (buf, 1, sizeof(buf), fp);
44 9 ▶ if (got == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (got == 0) 2 7 9
45 2 return;
46 7 sv_catpvn (sv, buf, got);
47 }
48 }
49 #endif
50  
51 MODULE = Devel::Mallinfo PACKAGE = Devel::Mallinfo
52  
53 HV *
54 mallinfo ()
55 CODE:
56 {
57 #if HAVE_MALLINFO
58 struct mallinfo m;
59  
60 /* grab the info before building the hash return, so as not to include
61 that in "current" usage */
62 6 m = mallinfo();
63 #endif
64 6 RETVAL = newHV();
65 6 sv_2mortal((SV*)RETVAL);
66 /**/
67 #if HAVE_MALLINFO
68 #define FIELD(field) \
69 do { \
70 SV *val = newSViv (m.field); \
71 if (! hv_stores (RETVAL, #field, val)) \
72 goto store_error; \
73 } while (0)
74  
75 6 ▶ STRUCT_MALLINFO_FIELDS;
Branch: 10 branches
BranchTrueFalseTotal
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
STRUCT_MALLINFO_FIELDS; 0 6 6
76 6 goto done;
77  
78 0 store_error:
79 0 croak ("cannot store to hash");
80 6 done:
81 ;
82 #endif
83 }
84 OUTPUT:
85 RETVAL
86  
87  
88 #if HAVE_MALLOC_INFO
89  
90 int
91 malloc_info (options, fp)
92 int options
93 FILE *fp
94  
95 void
96 malloc_info_string (options)
97 int options
98 PPCODE:
99 {
100 FILE *fp;
101 2 SV *ret = &PL_sv_undef;
102 int err;
103  
104 2 fp = tmpfile();
105 2 ▶ if (fp != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (fp != NULL) { 2 0 2
106 2 err = malloc_info (options, fp);
107 2 ▶ if (err != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (err != 0) { 0 2 2
108 0 errno = err;
109 2 ▶ } else if (ferror (fp)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ferror (fp)) { 2 0 2
110 /* write error to fp */
111 } else {
112 SV *sv;
113 2 rewind (fp);
114 2 sv = sv_newmortal();
115 2 slurp_fp_to_sv (fp, sv);
116 2 ▶ if (! ferror (fp))
Branch: 1 branch
BranchTrueFalseTotal
if (! ferror (fp)) 2 0 2
117 2 ret = sv;
118 }
119 2 ▶ if (fclose (fp) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (fclose (fp) != 0) { 0 2 2
120 0 ret = &PL_sv_undef;
121 }
122 }
123 2 PUSHs(ret);
124 }
125  
126 #endif
127  
128 #if HAVE_MALLOC_STATS
129  
130 void
131 malloc_stats ()
132  
133 #endif
134  
135 #if HAVE_MALLOC_TRIM
136  
137 int
138 malloc_trim (leave)
139 size_t leave
140  
141 #endif
« blib/lib/Devel/config.pl ↑ Summary blib/lib/Devel/Mallinfo.pm »