FileHandle.xs

filter: Statementstmt 69.4% 414 / 596 Branchbran 52.5% 163 / 310 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.6% 577 / 906 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« t/test03.p ↑ Summary NYTProf.xs »
1 /* vim: ts=8 sw=4 expandtab:
2 * ************************************************************************
3 * This file is part of the Devel::NYTProf package.
4 * See http://metacpan.org/release/Devel-NYTProf/
5 * For Copyright see lib/Devel/NYTProf.pm
6 * For contribution history see repository logs.
7 * ************************************************************************
8 */
9  
10 #define PERL_NO_GET_CONTEXT /* we want efficiency */
11 #include "EXTERN.h"
12 #include "perl.h"
13 #include "XSUB.h"
14 #if defined(PERL_IMPLICIT_SYS) && !defined(NO_XSLOCKS)
15 # ifndef fgets
16 # define fgets PerlSIO_fgets
17 # endif
18 #endif
19  
20 #include "FileHandle.h"
21 #include "NYTProf.h"
22  
23 #define NEED_sv_2pvbyte
24 #include "ppport.h"
25  
26 #ifdef HAS_ZLIB
27 # include <zlib.h>
28 #endif
29  
30 #define NYTP_FILE_STDIO 0
31 #define NYTP_FILE_DEFLATE 1
32 #define NYTP_FILE_INFLATE 2
33  
34 /* to help find places in NYTProf.xs where we don't save/restore errno */
35 #if 0
36 #define ERRNO_PROBE errno=__LINE__
37 #else
38 #define ERRNO_PROBE (void)0
39 #endif
40  
41 /* During profiling the large buffer collects the raw data until full.
42 * Then flush_output zips it into the small buffer and writes it to disk.
43 * A scale factor of ~90 makes the large buffer usually almost fill the small
44 * one when zipped (so calls to flush_output() almost always trigger one fwrite()).
45 * We use a lower number to save some memory as there's little performance
46 * impact either way.
47 */
48 #define NYTP_FILE_SMALL_BUFFER_SIZE 4096
49 #define NYTP_FILE_LARGE_BUFFER_SIZE (NYTP_FILE_SMALL_BUFFER_SIZE * 40)
50  
51 #ifdef HAS_ZLIB
52 # define FILE_STATE(f) ((f)->state)
53 #else
54 # define FILE_STATE(f) NYTP_FILE_STDIO
55 #endif
56  
57 #if defined(PERL_IMPLICIT_CONTEXT) && ! defined(tTHX)
58 # define tTHX PerlInterpreter*
59 #endif
60  
61 struct NYTP_file_t {
62 FILE *file;
63 #ifdef PERL_IMPLICIT_CONTEXT
64 tTHX aTHX; /* on 5.8 and older, pTHX contains a "register" which is not
65 compatible with a struct def, so use something else */
66 #endif
67 #ifdef HAS_ZLIB
68 unsigned char state;
69 bool stdio_at_eof;
70 bool zlib_at_eof;
71 /* For input only, the position we are in large_buffer. */
72 unsigned int count;
73 z_stream zs;
74 unsigned char small_buffer[NYTP_FILE_SMALL_BUFFER_SIZE];
75 unsigned char large_buffer[NYTP_FILE_LARGE_BUFFER_SIZE];
76 #endif
77 };
78  
79 /* unlike dTHX which contains a function call, and therefore can never be
80 optimized away, even if return value isn't used, the below will optimize away
81 if NO_XSLOCKS is defined and PerlIO is not being used (i.e. native C lib
82 IO is being used on Win32 )*/
83 #ifdef PERL_IMPLICIT_CONTEXT
84 # define dNFTHX(x) dTHXa((x)->aTHX)
85 #else
86 # define dNFTHX(x) dNOOP
87 #endif
88  
89 /* XXX The proper return value would be Off_t */
90 long
91 0 NYTP_tell(NYTP_file file) {
92 ERRNO_PROBE;
93  
94 #ifdef HAS_ZLIB
95 /* This has to work with compressed files as it's used in the croaking
96 routine. */
97 0 ▶ if (FILE_STATE(file) != NYTP_FILE_STDIO) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(file) != NYTP_FILE_STDIO) { 0 0 0
98 0 return FILE_STATE(file) == NYTP_FILE_INFLATE
99 0 ▶ ? file->zs.total_out : file->zs.total_in;
Branch: 1 branch
BranchTrueFalseTotal
? file->zs.total_out : file->zs.total_in; 0 0 0
100 }
101 #endif
102 {
103 dNFTHX(file);
104 0 return (long)ftell(file->file);
105 }
106 }
107  
108 #ifdef HAS_ZLIB
109 const char *
110 0 NYTP_type_of_offset(NYTP_file file) {
111 0 switch (FILE_STATE(file)) {
112 0 case NYTP_FILE_STDIO:
113 0 return "";
114 0 case NYTP_FILE_DEFLATE:
115 0 return " in compressed output data";
116 break;
117 0 case NYTP_FILE_INFLATE:
118 0 return " in compressed input data";
119 break;
120 0 default:
121 0 return Perl_form_nocontext(" in stream in unknown state %d",
122 0 FILE_STATE(file));
123 }
124 }
125 #endif
126  
127 #ifdef HAS_ZLIB
128 # define CROAK_IF_NOT_STDIO(file, where) \
129 STMT_START { \
130 if (FILE_STATE(file) != NYTP_FILE_STDIO) { \
131 compressed_io_croak((file), (where)); \
132 } \
133 } STMT_END
134 #else
135 # define CROAK_IF_NOT_STDIO(file, where)
136 #endif
137  
138 #ifdef HAS_ZLIB
139 #ifdef HASATTRIBUTE_NORETURN
140 __attribute__noreturn__
141 #endif
142 static void
143 0 compressed_io_croak(NYTP_file file, const char *function) {
144 const char *what;
145  
146 0 switch (FILE_STATE(file)) {
147 0 case NYTP_FILE_STDIO:
148 0 what = "stdio";
149 0 break;
150 0 case NYTP_FILE_DEFLATE:
151 0 what = "compressed output";
152 0 break;
153 0 case NYTP_FILE_INFLATE:
154 0 what = "compressed input";
155 0 break;
156 0 default:
157 0 croak("Can't use function %s() on a stream of type %d at offset %ld",
158 function, FILE_STATE(file), NYTP_tell(file));
159 }
160 0 croak("Can't use function %s() on a %s stream at offset %ld", function,
161 what, NYTP_tell(file));
162 }
163  
164 void
165 370 NYTP_start_deflate(NYTP_file file, int compression_level) {
166 int status;
167 ERRNO_PROBE;
168  
169 370 ▶ CROAK_IF_NOT_STDIO(file, "NYTP_start_deflate");
Branch: 1 branch
BranchTrueFalseTotal
CROAK_IF_NOT_STDIO(file, "NYTP_start_deflate"); 0 370 370
170 370 FILE_STATE(file) = NYTP_FILE_DEFLATE;
171 370 file->zs.next_in = (Bytef *) file->large_buffer;
172 370 file->zs.avail_in = 0;
173 370 file->zs.next_out = (Bytef *) file->small_buffer;
174 370 file->zs.avail_out = NYTP_FILE_SMALL_BUFFER_SIZE;
175 370 file->zs.zalloc = (alloc_func) 0;
176 370 file->zs.zfree = (free_func) 0;
177 370 file->zs.opaque = 0;
178  
179 370 status = deflateInit2(&(file->zs), compression_level, Z_DEFLATED,
180 15 /* windowBits */,
181 9 /* memLevel */, Z_DEFAULT_STRATEGY);
182 370 ▶ if (status != Z_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (status != Z_OK) { 0 370 370
183 0 croak("deflateInit2 failed, error %d (%s)", status, file->zs.msg);
184 }
185 370 }
186  
187 void
188 732 NYTP_start_inflate(NYTP_file file) {
189 int status;
190 ERRNO_PROBE;
191  
192 732 ▶ CROAK_IF_NOT_STDIO(file, "NYTP_start_inflate");
Branch: 1 branch
BranchTrueFalseTotal
CROAK_IF_NOT_STDIO(file, "NYTP_start_inflate"); 0 732 732
193 732 FILE_STATE(file) = NYTP_FILE_INFLATE;
194  
195 732 file->zs.next_in = (Bytef *) file->small_buffer;
196 732 file->zs.avail_in = 0;
197 732 file->zs.next_out = (Bytef *) file->large_buffer;
198 732 file->zs.avail_out = NYTP_FILE_LARGE_BUFFER_SIZE;
199 732 file->zs.zalloc = (alloc_func) 0;
200 732 file->zs.zfree = (free_func) 0;
201 732 file->zs.opaque = 0;
202  
203 732 status = inflateInit2(&(file->zs), 15);
204 732 ▶ if (status != Z_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (status != Z_OK) { 0 732 732
205 0 croak("inflateInit2 failed, error %d (%s)", status, file->zs.msg);
206 }
207 732 }
208 #endif
209  
210 NYTP_file
211 1972 NYTP_open(const char *name, const char *mode) {
212 dTHX;
213 1972 FILE *raw_file = fopen(name, mode);
214 NYTP_file file;
215 ERRNO_PROBE;
216  
217 1972 ▶ if (!raw_file)
Branch: 1 branch
BranchTrueFalseTotal
if (!raw_file) 0 1972 1972
218 0 return NULL;
219  
220 /* MS libc has 4096 as default, this is too slow for GB size profiling data */
221 1972 ▶ if (setvbuf(raw_file, NULL, _IOFBF, 16384))
Branch: 1 branch
BranchTrueFalseTotal
if (setvbuf(raw_file, NULL, _IOFBF, 16384)) 0 1972 1972
222 0 return NULL;
223 1972 Newx(file, 1, struct NYTP_file_t);
224 1972 file->file = raw_file;
225  
226 #ifdef PERL_IMPLICIT_CONTEXT
227 file->aTHX = aTHX;
228 #endif
229 #ifdef HAS_ZLIB
230 1972 file->state = NYTP_FILE_STDIO;
231 1972 file->count = 0;
232 1972 file->stdio_at_eof = FALSE;
233 1972 file->zlib_at_eof = FALSE;
234  
235 1972 file->zs.msg = (char *)"[Oops. zlib hasn't updated this error string]";
236 #endif
237  
238 1972 return file;
239 }
240  
241 #ifdef HAS_ZLIB
242  
243 static void
244 46834 grab_input(NYTP_file ifile) {
245 dNFTHX(ifile);
246 ERRNO_PROBE;
247  
248 46834 ifile->count = 0;
249 46834 ifile->zs.next_out = (Bytef *) ifile->large_buffer;
250 46834 ifile->zs.avail_out = NYTP_FILE_LARGE_BUFFER_SIZE;
251  
252 #ifdef DEBUG_INFLATE
253 fprintf(stderr, "grab_input enter\n");
254 #endif
255  
256 238615 while (1) {
257 int status;
258  
259 285449 ▶ if (ifile->zs.avail_in == 0 && !ifile->stdio_at_eof) {
Branch: 2 branches
BranchTrueFalseTotal
if (ifile->zs.avail_in == 0 && !ifile->stdio_at_eof) { 239357 46092 285449
if (ifile->zs.avail_in == 0 && !ifile->stdio_at_eof) { 239357 0 239357
260 239357 size_t got = fread(ifile->small_buffer, 1,
261 NYTP_FILE_SMALL_BUFFER_SIZE, ifile->file);
262  
263 239357 ▶ if (got == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (got == 0) { 0 239357 239357
264 0 ▶ if (!feof(ifile->file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!feof(ifile->file)) { 0 0 0
265 0 int eno = errno;
266 0 croak("grab_input failed: %d (%s)", eno, strerror(eno));
267 }
268 0 ifile->stdio_at_eof = TRUE;
269 }
270  
271 239357 ifile->zs.avail_in = got;
272 239357 ifile->zs.next_in = (Bytef *) ifile->small_buffer;
273 }
274  
275 #ifdef DEBUG_INFLATE
276 fprintf(stderr, "grab_input predef next_in= %p avail_in= %08x\n"
277 " next_out=%p avail_out=%08x"
278 " eof=%d,%d\n", ifile->zs.next_in, ifile->zs.avail_in,
279 ifile->zs.next_out, ifile->zs.avail_out, ifile->stdio_at_eof,
280 ifile->zlib_at_eof);
281 #endif
282  
283 285449 status = inflate(&(ifile->zs), Z_NO_FLUSH);
284  
285 #ifdef DEBUG_INFLATE
286 fprintf(stderr, "grab_input postdef next_in= %p avail_in= %08x\n"
287 " next_out=%p avail_out=%08x "
288 "status=%d\n", ifile->zs.next_in, ifile->zs.avail_in,
289 ifile->zs.next_out, ifile->zs.avail_out, status);
290 #endif
291  
292 285449 ▶ if (!(status == Z_OK || status == Z_STREAM_END)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(status == Z_OK || status == Z_STREAM_END)) { 732 284717 285449
if (!(status == Z_OK || status == Z_STREAM_END)) { 0 732 732
293 0 ▶ if (ifile->stdio_at_eof)
Branch: 1 branch
BranchTrueFalseTotal
if (ifile->stdio_at_eof) 0 0 0
294 0 croak("Profile data incomplete, inflate error %d (%s) at end of input file,"
295 " perhaps the process didn't exit cleanly or the file has been truncated "
296 " (refer to TROUBLESHOOTING in the documentation)\n",
297 status, ifile->zs.msg);
298 0 croak("Error reading file: inflate failed, error %d (%s) at offset %ld in input file",
299 status, ifile->zs.msg, (long)ftell(ifile->file));
300 }
301  
302 285449 ▶ if (ifile->zs.avail_out == 0 || status == Z_STREAM_END) {
Branch: 2 branches
BranchTrueFalseTotal
if (ifile->zs.avail_out == 0 || status == Z_STREAM_END) { 239347 46102 285449
if (ifile->zs.avail_out == 0 || status == Z_STREAM_END) { 732 238615 239347
303 46834 ▶ if (status == Z_STREAM_END) {
Branch: 1 branch
BranchTrueFalseTotal
if (status == Z_STREAM_END) { 732 46102 46834
304 732 ifile->zlib_at_eof = TRUE;
305 }
306 46834 return;
307 }
308 }
309 }
310  
311 #endif
312  
313  
314 size_t
315 5338011685 NYTP_read_unchecked(NYTP_file ifile, void *buffer, size_t len) {
316 dNFTHX(ifile);
317 #ifdef HAS_ZLIB
318 5338011685 size_t result = 0;
319 #endif
320 ERRNO_PROBE;
321 5338011685 ▶ if (FILE_STATE(ifile) == NYTP_FILE_STDIO) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(ifile) == NYTP_FILE_STDIO) { 2062731045 3275280640 5338011685
322 2062731045 return fread(buffer, 1, len, ifile->file);
323 }
324 #ifdef HAS_ZLIB
325 3275280640 ▶ else if (FILE_STATE(ifile) != NYTP_FILE_INFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
else if (FILE_STATE(ifile) != NYTP_FILE_INFLATE) { 3275280640 0 3275280640
326 0 compressed_io_croak(ifile, "NYTP_read");
327 return 0;
328 }
329 46834 while (1) {
330 3275327474 unsigned char *p = ifile->large_buffer + ifile->count;
331 3275327474 int remaining = ((unsigned char *) ifile->zs.next_out) - p;
332  
333 3275327474 ▶ if (remaining >= len) {
Branch: 1 branch
BranchTrueFalseTotal
if (remaining >= len) { 3275279908 47566 3275327474
334 3275279908 Copy(p, buffer, len, unsigned char);
335 3275279908 ifile->count += len;
336 3275279908 result += len;
337 3275279908 return result;
338 }
339 47566 Copy(p, buffer, remaining, unsigned char);
340 47566 ifile->count = NYTP_FILE_LARGE_BUFFER_SIZE;
341 47566 result += remaining;
342 47566 len -= remaining;
343 47566 buffer = (void *)(remaining + (char *)buffer);
344 47566 ▶ if (ifile->zlib_at_eof)
Branch: 1 branch
BranchTrueFalseTotal
if (ifile->zlib_at_eof) 732 46834 47566
345 732 return result;
346 46834 grab_input(ifile);
347 }
348 #endif
349 }
350  
351  
352 size_t
353 4637388459 NYTP_read(NYTP_file ifile, void *buffer, size_t len, const char *what) {
354 4637388459 size_t got = NYTP_read_unchecked(ifile, buffer, len);
355 4637388459 ▶ if (got != len) {
Branch: 1 branch
BranchTrueFalseTotal
if (got != len) { 0 4637388459 4637388459
356 0 ▶ croak("Profile format error whilst reading %s at %ld%s: expected %ld got %ld, %s (see TROUBLESHOOTING in docs)",
Branch: 1 branch
BranchTrueFalseTotal
croak("Profile format error whilst reading %s at %ld%s: expected %ld got %ld, %s (see TROUBLESHOOTING in docs)", 0 0 0
357 what, NYTP_tell(ifile), NYTP_type_of_offset(ifile), (long)len, (long)got,
358 (NYTP_eof(ifile)) ? "end of file" : NYTP_fstrerror(ifile));
359 }
360 4637388459 return len;
361 }
362  
363 /* This isn't exactly fgets. It will resize the buffer as needed, and returns
364 a pointer to one beyond the read data (usually the terminating '\0'), or
365 NULL if it hit error/EOF */
366  
367 char *
368 38345 NYTP_gets(NYTP_file ifile, char **buffer_p, size_t *len_p) {
369 38345 char *buffer = *buffer_p;
370 38345 size_t len = *len_p;
371 38345 size_t prev_len = 0;
372 ERRNO_PROBE;
373  
374 #ifdef HAS_ZLIB
375 38345 ▶ if (FILE_STATE(ifile) == NYTP_FILE_INFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(ifile) == NYTP_FILE_INFLATE) { 732 37613 38345
376 0 while (1) {
377 732 const unsigned char *const p = ifile->large_buffer + ifile->count;
378 732 const unsigned int remaining = ((unsigned char *) ifile->zs.next_out) - p;
379 732 unsigned char *const nl = (unsigned char *)memchr(p, '\n', remaining);
380 size_t got;
381 size_t want;
382 size_t extra;
383  
384 732 ▶ if (nl) {
Branch: 1 branch
BranchTrueFalseTotal
if (nl) { 732 0 732
385 732 want = nl + 1 - p;
386 732 extra = want + 1; /* 1 more to add a \0 */
387 } else {
388 0 want = extra = remaining;
389 }
390  
391 732 ▶ if (extra > len - prev_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (extra > len - prev_len) { 0 732 732
392 0 prev_len = len;
393 0 len += extra;
394 0 buffer = (char *)saferealloc(buffer, len);
395 }
396  
397 732 got = NYTP_read_unchecked(ifile, buffer + prev_len, want);
398 732 ▶ if (got != want)
Branch: 1 branch
BranchTrueFalseTotal
if (got != want) 0 732 732
399 0 croak("NYTP_gets unexpected short read. got %lu, expected %lu\n",
400 (unsigned long)got, (unsigned long)want);
401  
402 732 ▶ if (nl) {
Branch: 1 branch
BranchTrueFalseTotal
if (nl) { 732 0 732
403 732 buffer[prev_len + want] = '\0';
404 732 *buffer_p = buffer;
405 732 *len_p = len;
406 732 return buffer + prev_len + want;
407 }
408 0 ▶ if (ifile->zlib_at_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (ifile->zlib_at_eof) { 0 0 0
409 0 *buffer_p = buffer;
410 0 *len_p = len;
411 0 return NULL;
412 }
413 0 grab_input(ifile);
414 }
415 }
416 #endif
417 37613 ▶ CROAK_IF_NOT_STDIO(ifile, "NYTP_gets");
Branch: 1 branch
BranchTrueFalseTotal
CROAK_IF_NOT_STDIO(ifile, "NYTP_gets"); 0 37613 37613
418  
419 {
420 dNFTHX(ifile);
421 37613 ▶ while(fgets(buffer + prev_len, (int)(len - prev_len), ifile->file)) {
Branch: 1 branch
BranchTrueFalseTotal
while(fgets(buffer + prev_len, (int)(len - prev_len), ifile->file)) { 37613 0 37613
422 /* We know that there are no '\0' bytes in the part we've already
423 read, so don't bother running strlen() over that part. */
424 37613 char *end = buffer + prev_len + strlen(buffer + prev_len);
425 37613 ▶ if (end[-1] == '\n') {
Branch: 1 branch
BranchTrueFalseTotal
if (end[-1] == '\n') { 37613 0 37613
426 37613 *buffer_p = buffer;
427 37613 *len_p = len;
428 37613 return end;
429 }
430 0 prev_len = len - 1; /* -1 to take off the '\0' at the end */
431 0 len *= 2;
432 0 buffer = (char *)saferealloc(buffer, len);
433 }
434 }
435 0 *buffer_p = buffer;
436 0 *len_p = len;
437 0 return NULL;
438 }
439  
440  
441 #ifdef HAS_ZLIB
442 /* Cheat, by telling zlib about a reduced amount of available output space,
443 such that our next write of the (slightly underused) output buffer will
444 align the underlying file pointer back with the size of our output buffer
445 (and hopefully the underlying OS block writes). */
446 static void
447 726 sync_avail_out_to_ftell(NYTP_file ofile) {
448 dNFTHX(ofile);
449 726 const long result = ftell(ofile->file);
450 726 const unsigned long where = result < 0 ? 0 : result;
451 ERRNO_PROBE;
452 726 ofile->zs.avail_out =
453 726 NYTP_FILE_SMALL_BUFFER_SIZE - where % NYTP_FILE_SMALL_BUFFER_SIZE;
454 #ifdef DEBUG_DEFLATE
455 fprintf(stderr, "sync_avail_out_to_ftell pos=%ld, avail_out=%lu\n",
456 result, (unsigned long) ofile->zs.avail_out);
457 #endif
458 726 }
459  
460 /* flush has values as described for "allowed flush values" in zlib.h */
461 static void
462 23695 flush_output(NYTP_file ofile, int flush) {
463 dNFTHX(ofile);
464 ERRNO_PROBE;
465  
466 23695 ofile->zs.next_in = (Bytef *) ofile->large_buffer;
467  
468 #ifdef DEBUG_DEFLATE
469 fprintf(stderr, "flush_output enter flush = %d\n", flush);
470 #endif
471 115625 while (1) {
472 int status;
473 #ifdef DEBUG_DEFLATE
474 fprintf(stderr, "flush_output predef next_in= %p avail_in= %08x\n"
475 " next_out=%p avail_out=%08x"
476 " flush=%d\n", ofile->zs.next_in, ofile->zs.avail_in,
477 ofile->zs.next_out, ofile->zs.avail_out, flush);
478 #endif
479 139320 status = deflate(&(ofile->zs), flush);
480  
481 /* workaround for RT#50851 */
482 139320 ▶ if (status == Z_BUF_ERROR && flush != Z_NO_FLUSH
Branch: 2 branches
BranchTrueFalseTotal
if (status == Z_BUF_ERROR && flush != Z_NO_FLUSH 0 139320 139320
if (status == Z_BUF_ERROR && flush != Z_NO_FLUSH 0 0 0
483 0 ▶ && !ofile->zs.avail_in && ofile->zs.avail_out)
Branch: 2 branches
BranchTrueFalseTotal
&& !ofile->zs.avail_in && ofile->zs.avail_out) 0 0 0
&& !ofile->zs.avail_in && ofile->zs.avail_out) 0 0 0
484 0 status = Z_OK;
485  
486 #ifdef DEBUG_DEFLATE
487 fprintf(stderr, "flush_output postdef next_in= %p avail_in= %08x\n"
488 " next_out=%p avail_out=%08x "
489 "status=%d\n", ofile->zs.next_in, ofile->zs.avail_in,
490 ofile->zs.next_out, ofile->zs.avail_out, status);
491 #endif
492
493 139320 ▶ if (status == Z_OK || status == Z_STREAM_END) {
Branch: 2 branches
BranchTrueFalseTotal
if (status == Z_OK || status == Z_STREAM_END) { 348 138972 139320
if (status == Z_OK || status == Z_STREAM_END) { 348 0 348
494 254945 ▶ if (ofile->zs.avail_out == 0 || flush != Z_NO_FLUSH) {
Branch: 2 branches
BranchTrueFalseTotal
if (ofile->zs.avail_out == 0 || flush != Z_NO_FLUSH) { 23695 115625 139320
if (ofile->zs.avail_out == 0 || flush != Z_NO_FLUSH) { 1074 22621 23695
495 116699 int terminate
496 116699 ▶ = ofile->zs.avail_in == 0 && ofile->zs.avail_out > 0;
Branch: 2 branches
BranchTrueFalseTotal
= ofile->zs.avail_in == 0 && ofile->zs.avail_out > 0; 5994 110705 116699
= ofile->zs.avail_in == 0 && ofile->zs.avail_out > 0; 1074 4920 5994
497 116699 size_t avail = ((unsigned char *) ofile->zs.next_out)
498 116699 - ofile->small_buffer;
499 116699 const unsigned char *where = ofile->small_buffer;
500  
501 233398 ▶ while (avail > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (avail > 0) { 116699 116699 233398
502 116699 size_t count = fwrite(where, 1, avail, ofile->file);
503  
504 116699 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 116699 0 116699
505 116699 where += count;
506 116699 avail -= count;
507 } else {
508 0 int eno = errno;
509 0 croak("fwrite in flush error %d: %s", eno,
510 strerror(eno));
511 }
512 }
513 116699 ofile->zs.next_out = (Bytef *) ofile->small_buffer;
514 116699 ofile->zs.avail_out = NYTP_FILE_SMALL_BUFFER_SIZE;
515 116699 ▶ if (terminate) {
Branch: 1 branch
BranchTrueFalseTotal
if (terminate) { 1074 115625 116699
516 1074 ofile->zs.avail_in = 0;
517 1074 ▶ if (flush == Z_SYNC_FLUSH) {
Branch: 1 branch
BranchTrueFalseTotal
if (flush == Z_SYNC_FLUSH) { 726 348 1074
518 726 sync_avail_out_to_ftell(ofile);
519 }
520 1074 return;
521 }
522 } else {
523 22621 ofile->zs.avail_in = 0;
524 22621 return;
525 }
526 } else {
527 0 croak("deflate(%ld,%d) failed, error %d (%s) in pid %d",
528 (long)ofile->zs.avail_in, flush, status, ofile->zs.msg, getpid());
529 }
530 }
531 }
532 #endif
533  
534 size_t
535 1561633000 NYTP_write(NYTP_file ofile, const void *buffer, size_t len) {
536 #ifdef HAS_ZLIB
537 1561633000 size_t result = 0;
538 #endif
539 ERRNO_PROBE;
540  
541 1561633000 ▶ if (FILE_STATE(ofile) == NYTP_FILE_STDIO) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(ofile) == NYTP_FILE_STDIO) { 606358733 955274267 1561633000
542 /* fwrite with len==0 is problematic */
543 /* http://www.opengroup.org/platform/resolutions/bwg98-007.html */
544 606358733 ▶ if (len == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) 0 606358733 606358733
545 0 return len;
546 {
547 dNFTHX(ofile);
548 606358733 ▶ if (fwrite(buffer, 1, len, ofile->file) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (fwrite(buffer, 1, len, ofile->file) < 1) { 0 606358733 606358733
549 0 int eno = errno;
550 0 croak("fwrite error %d writing %ld bytes to fd%d: %s",
551 eno, (long)len, fileno(ofile->file), strerror(eno));
552 }
553 }
554 606358733 return len;
555 }
556 #ifdef HAS_ZLIB
557 955274267 ▶ else if (FILE_STATE(ofile) != NYTP_FILE_DEFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
else if (FILE_STATE(ofile) != NYTP_FILE_DEFLATE) { 0 955274267 955274267
558 0 compressed_io_croak(ofile, "NYTP_write");
559 return 0;
560 }
561 22621 while (1) {
562 955296888 int remaining = NYTP_FILE_LARGE_BUFFER_SIZE - ofile->zs.avail_in;
563 955296888 unsigned char *p = ofile->large_buffer + ofile->zs.avail_in;
564  
565 955296888 ▶ if (remaining >= len) {
Branch: 1 branch
BranchTrueFalseTotal
if (remaining >= len) { 955274267 22621 955296888
566 955274267 Copy(buffer, p, len, unsigned char);
567 955274267 ofile->zs.avail_in += len;
568 955274267 result += len;
569 955274267 return result;
570 } else {
571 /* Copy what we can, then flush the buffer. Lather, rinse, repeat.
572 */
573 22621 Copy(buffer, p, remaining, unsigned char);
574 22621 ofile->zs.avail_in = NYTP_FILE_LARGE_BUFFER_SIZE;
575 22621 result += remaining;
576 22621 len -= remaining;
577 22621 buffer = (void *)(remaining + (char *)buffer);
578 22621 flush_output(ofile, Z_NO_FLUSH);
579 }
580 }
581 #endif
582 }
583  
584 int
585 675 NYTP_printf(NYTP_file ofile, const char *format, ...) {
586 int retval;
587 va_list args;
588 ERRNO_PROBE;
589  
590 675 ▶ CROAK_IF_NOT_STDIO(ofile, "NYTP_printf");
Branch: 1 branch
BranchTrueFalseTotal
CROAK_IF_NOT_STDIO(ofile, "NYTP_printf"); 0 675 675
591  
592 675 va_start(args, format);
593 {
594 dNFTHX(ofile);
595 675 retval = vfprintf(ofile->file, format, args);
596 }
597 675 va_end(args);
598  
599 675 return retval;
600 }
601  
602 int
603 1336 NYTP_flush(NYTP_file file) {
604 ERRNO_PROBE;
605 #ifdef HAS_ZLIB
606 1336 ▶ if (FILE_STATE(file) == NYTP_FILE_DEFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(file) == NYTP_FILE_DEFLATE) { 726 610 1336
607 726 flush_output(file, Z_SYNC_FLUSH);
608 }
609 #endif
610 {
611 dNFTHX(file);
612 1336 return fflush(file->file);
613 }
614 }
615  
616 int
617 1297 NYTP_eof(NYTP_file ifile) {
618 ERRNO_PROBE;
619 #ifdef HAS_ZLIB
620 1297 ▶ if (FILE_STATE(ifile) == NYTP_FILE_INFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(ifile) == NYTP_FILE_INFLATE) { 732 565 1297
621 732 return ifile->zlib_at_eof;
622 }
623 #endif
624 {
625 dNFTHX(ifile);
626 565 return feof(ifile->file);
627 }
628 }
629  
630 const char *
631 0 NYTP_fstrerror(NYTP_file file) {
632 #ifdef HAS_ZLIB
633 0 ▶ if (FILE_STATE(file) == NYTP_FILE_DEFLATE || FILE_STATE(file) == NYTP_FILE_INFLATE) {
Branch: 2 branches
BranchTrueFalseTotal
if (FILE_STATE(file) == NYTP_FILE_DEFLATE || FILE_STATE(file) == NYTP_FILE_INFLATE) { 0 0 0
if (FILE_STATE(file) == NYTP_FILE_DEFLATE || FILE_STATE(file) == NYTP_FILE_INFLATE) { 0 0 0
634 0 return file->zs.msg;
635 }
636 #endif
637 {
638 dNFTHX(file);
639 PERL_UNUSED_ARG(file);
640 0 return strerror(errno);
641 }
642 }
643  
644 int
645 1972 NYTP_close(NYTP_file file, int discard) {
646 1972 FILE *raw_file = file->file;
647 int result;
648 dNFTHX(file);
649 ERRNO_PROBE;
650  
651 #ifdef HAS_ZLIB
652 1972 ▶ if (!discard && FILE_STATE(file) == NYTP_FILE_DEFLATE) {
Branch: 2 branches
BranchTrueFalseTotal
if (!discard && FILE_STATE(file) == NYTP_FILE_DEFLATE) { 1942 30 1972
if (!discard && FILE_STATE(file) == NYTP_FILE_DEFLATE) { 348 1594 1942
653 348 const double ratio = file->zs.total_in / (double) file->zs.total_out;
654 348 flush_output(file, Z_FINISH);
655 348 fprintf(raw_file, "#\n"
656 "# Compressed %lu bytes to %lu, ratio %f:1, data shrunk by %f%%\n",
657 348 (long)file->zs.total_in, (long)file->zs.total_out, ratio,
658 348 100 * (1 - 1 / ratio));
659 }
660  
661 1972 ▶ if (FILE_STATE(file) == NYTP_FILE_DEFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (FILE_STATE(file) == NYTP_FILE_DEFLATE) { 370 1602 1972
662 370 int status = deflateEnd(&(file->zs));
663 370 ▶ if (status != Z_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (status != Z_OK) { 22 348 370
664 22 ▶ if (discard && status == Z_DATA_ERROR) {
Branch: 2 branches
BranchTrueFalseTotal
if (discard && status == Z_DATA_ERROR) { 22 0 22
if (discard && status == Z_DATA_ERROR) { 22 0 22
665 /* deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
666 stream state was inconsistent, Z_DATA_ERROR if the stream
667 was freed prematurely (some input or output was discarded).
668 */
669 } else {
670 0 croak("deflateEnd failed, error %d (%s) in %d", status,
671 file->zs.msg, getpid());
672 }
673 }
674 }
675 1602 ▶ else if (FILE_STATE(file) == NYTP_FILE_INFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
else if (FILE_STATE(file) == NYTP_FILE_INFLATE) { 732 870 1602
676 732 int err = inflateEnd(&(file->zs));
677 732 ▶ if (err != Z_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (err != Z_OK) { 0 732 732
678 0 croak("inflateEnd failed, error %d (%s)", err, file->zs.msg);
679 }
680 }
681 #endif
682  
683 1972 Safefree(file);
684  
685 1972 ▶ result = ferror(raw_file) ? errno : 0;
Branch: 1 branch
BranchTrueFalseTotal
result = ferror(raw_file) ? errno : 0; 0 1972 1972
686  
687 1972 ▶ if (discard) {
Branch: 1 branch
BranchTrueFalseTotal
if (discard) { 30 1942 1972
688 /* close the underlying fd first so any buffered data gets discarded
689 * when fclose is called below */
690 30 close(fileno(raw_file));
691 }
692  
693 1972 ▶ if (result || discard) {
Branch: 2 branches
BranchTrueFalseTotal
if (result || discard) { 1972 0 1972
if (result || discard) { 30 1942 1972
694 /* Something has already gone wrong, so try to preserve its error */
695 30 fclose(raw_file);
696 30 return result;
697 }
698 1942 ▶ return fclose(raw_file) == 0 ? 0 : errno;
Branch: 1 branch
BranchTrueFalseTotal
return fclose(raw_file) == 0 ? 0 : errno; 0 1942 1942
699 }
700  
701  
702 /* ====== Low-level element I/O functions ====== */
703  
704 /**
705 * Output an integer in bytes, optionally preceded by a tag. Use the special tag
706 * NYTP_TAG_NO_TAG to suppress the tag output. A wrapper macro output_u32(fh, i)
707 * does this for you.
708 * "In bytes" means output the number in binary, using the least number of bytes
709 * possible. All numbers are positive. Use sign slot as a marker
710 */
711 static size_t
712 1245677357 output_tag_u32(NYTP_file file, unsigned char tag, U32 i)
713 {
714 U8 buffer[6];
715 1245677357 U8 *p = buffer;
716  
717 1245677357 ▶ if (tag != NYTP_TAG_NO_TAG)
Branch: 1 branch
BranchTrueFalseTotal
if (tag != NYTP_TAG_NO_TAG) 436985124 808692233 1245677357
718 436985124 *p++ = tag;
719  
720 /* general case. handles all integers */
721 1245677357 ▶ if (i < 0x80) { /* < 8 bits */
Branch: 1 branch
BranchTrueFalseTotal
if (i < 0x80) { /* < 8 bits */ 646894326 598783031 1245677357
722 646894326 *p++ = (U8)i;
723 }
724 598783031 ▶ else if (i < 0x4000) { /* < 16 bits */
Branch: 1 branch
BranchTrueFalseTotal
else if (i < 0x4000) { /* < 16 bits */ 598771851 11180 598783031
725 598771851 *p++ = (U8)((i >> 8) | 0x80);
726 598771851 *p++ = (U8)i;
727 }
728 11180 ▶ else if (i < 0x200000) { /* < 24 bits */
Branch: 1 branch
BranchTrueFalseTotal
else if (i < 0x200000) { /* < 24 bits */ 11091 89 11180
729 11091 *p++ = (U8)((i >> 16) | 0xC0);
730 11091 *p++ = (U8)(i >> 8);
731 11091 *p++ = (U8)i;
732 }
733 89 ▶ else if (i < 0x10000000) { /* < 32 bits */
Branch: 1 branch
BranchTrueFalseTotal
else if (i < 0x10000000) { /* < 32 bits */ 89 0 89
734 89 *p++ = (U8)((i >> 24) | 0xE0);
735 89 *p++ = (U8)(i >> 16);
736 89 *p++ = (U8)(i >> 8);
737 89 *p++ = (U8)i;
738 }
739 else { /* need all the bytes. */
740 0 *p++ = 0xFF;
741 0 *p++ = (U8)(i >> 24);
742 0 *p++ = (U8)(i >> 16);
743 0 *p++ = (U8)(i >> 8);
744 0 *p++ = (U8)i;
745 }
746 1245677357 return NYTP_write(file, buffer, p - buffer);
747 }
748  
749 static size_t
750 197866018 output_tag_i32(NYTP_file file, unsigned char tag, I32 i)
751 {
752 197866018 return output_tag_u32(file, tag, *( (U32*) &i ) );
753 }
754  
755 #define output_u32(fh, i) output_tag_u32((fh), NYTP_TAG_NO_TAG, (i))
756 #define output_i32(fh, i) output_tag_i32((fh), NYTP_TAG_NO_TAG, (i))
757  
758  
759 /**
760 * Read an integer by decompressing the next 1 to 4 bytes of binary into a 32-
761 * bit integer. See output_int() for the compression details.
762 */
763 U32
764 2549316940 read_u32(NYTP_file ifile)
765 {
766 unsigned char d;
767 U32 newint;
768  
769 2549316940 NYTP_read(ifile, &d, sizeof(d), "integer prefix");
770  
771 2549316940 ▶ if (d < 0x80) { /* < 8 bits */
Branch: 1 branch
BranchTrueFalseTotal
if (d < 0x80) { /* < 8 bits */ 1314163080 1235153860 2549316940
772 1314163080 newint = d;
773 }
774 else {
775 unsigned char buffer[4];
776 1235153860 unsigned char *p = buffer;
777 unsigned int length;
778  
779 1235153860 ▶ if (d < 0xC0) { /* < 16 bits */
Branch: 1 branch
BranchTrueFalseTotal
if (d < 0xC0) { /* < 16 bits */ 1235134742 19118 1235153860
780 1235134742 newint = d & 0x7F;
781 1235134742 length = 1;
782 }
783 19118 ▶ else if (d < 0xE0) { /* < 24 bits */
Branch: 1 branch
BranchTrueFalseTotal
else if (d < 0xE0) { /* < 24 bits */ 18946 172 19118
784 18946 newint = d & 0x1F;
785 18946 length = 2;
786 }
787 172 ▶ else if (d < 0xFF) { /* < 32 bits */
Branch: 1 branch
BranchTrueFalseTotal
else if (d < 0xFF) { /* < 32 bits */ 172 0 172
788 172 newint = d & 0xF;
789 172 length = 3;
790 }
791 else { /* d == 0xFF */ /* = 32 bits */
792 0 newint = 0;
793 0 length = 4;
794 }
795 1235153860 NYTP_read(ifile, buffer, length, "integer");
796 2470327010 ▶ while (length--) {
Branch: 1 branch
BranchTrueFalseTotal
while (length--) { 1235173150 1235153860 2470327010
797 1235173150 newint <<= 8;
798 1235173150 newint |= *p++;
799 }
800 }
801 2549316940 return newint;
802 }
803  
804 I32
805 393426154 read_i32(NYTP_file ifile) {
806 393426154 U32 u = read_u32(ifile);
807 393426154 return *( (I32*)&u );
808 }
809  
810  
811 static size_t
812 104085010 output_str(NYTP_file file, const char *str, I32 len) { /* negative len signifies utf8 */
813 104085010 unsigned char tag = NYTP_TAG_STRING;
814 size_t retval;
815 size_t total;
816  
817 104085010 ▶ if (len < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len < 0) { 0 104085010 104085010
818 0 tag = NYTP_TAG_STRING_UTF8;
819 0 len = -len;
820 }
821  
822 104085010 total = retval = output_tag_u32(file, tag, len);
823 104085010 ▶ if (retval <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (retval <= 0) 0 104085010 104085010
824 0 return retval;
825  
826 104085010 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 104004454 80556 104085010
827 104004454 total += retval = NYTP_write(file, str, len);
828 104004454 ▶ if (retval <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (retval <= 0) 0 104004454 104004454
829 0 return retval;
830 }
831  
832 104085010 return total;
833 }
834  
835  
836 /**
837 * Output a double precision float via a simple binary write of the memory.
838 * (Minor portability issues are seen as less important than speed and space.)
839 */
840 size_t
841 199640591 output_nv(NYTP_file file, NV nv)
842 {
843 199640591 return NYTP_write(file, (unsigned char *)&nv, sizeof(NV));
844 }
845  
846 /**
847 * Read an NV by simple byte copy to memory
848 */
849 NV
850 418669601 read_nv(NYTP_file ifile)
851 {
852 NV nv;
853 /* no error checking on the assumption that a later token read will
854 * detect the error/eof condition
855 */
856 418669601 NYTP_read(ifile, (unsigned char *)&nv, sizeof(NV), "float");
857 418669601 return nv;
858 }
859  
860  
861 /* ====== Higher-level protocol I/O functions ====== */
862  
863 size_t
864 675 NYTP_write_header(NYTP_file ofile, U32 major, U32 minor)
865 {
866 675 return NYTP_printf(ofile, "NYTProf %u %u\n", major, minor);
867 }
868  
869 size_t
870 1045 NYTP_write_comment(NYTP_file ofile, const char *format, ...) {
871 size_t retval;
872 size_t retval2;
873 va_list args;
874 ERRNO_PROBE;
875  
876 1045 retval = NYTP_write(ofile, "#", 1);
877 1045 ▶ if (retval != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != 1) 0 1045 1045
878 0 return retval;
879  
880 1045 va_start(args, format);
881  
882 1045 ▶ if(strEQ(format, "%s")) {
Branch: 1 branch
BranchTrueFalseTotal
if(strEQ(format, "%s")) { 0 1045 1045
883 0 const char * const s = va_arg(args, char*);
884 0 STRLEN len = strlen(s);
885 0 retval = NYTP_write(ofile, s, len);
886 } else {
887 1045 ▶ CROAK_IF_NOT_STDIO(ofile, "NYTP_printf");
Branch: 1 branch
BranchTrueFalseTotal
CROAK_IF_NOT_STDIO(ofile, "NYTP_printf"); 0 1045 1045
888 {
889 dNFTHX(ofile);
890 1045 retval = vfprintf(ofile->file, format, args);
891 }
892 }
893 1045 va_end(args);
894  
895 1045 retval2 = NYTP_write(ofile, "\n", 1);
896 1045 ▶ if (retval2 != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval2 != 1) 0 1045 1045
897 0 return retval2;
898  
899 1045 return retval + 2;
900 }
901  
902 static size_t
903 18195 NYTP_write_plain_kv(NYTP_file ofile, const char prefix,
904 const char *key, size_t key_len,
905 const char *value, size_t value_len)
906 {
907 size_t total;
908 size_t retval;
909  
910 18195 total = retval = NYTP_write(ofile, &prefix, 1);
911 18195 ▶ if (retval != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != 1) 0 18195 18195
912 0 return retval;
913  
914 18195 total += retval = NYTP_write(ofile, key, key_len);
915 18195 ▶ if (retval != key_len)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != key_len) 0 18195 18195
916 0 return retval;
917  
918 18195 total += retval = NYTP_write(ofile, "=", 1);
919 18195 ▶ if (retval != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != 1) 0 18195 18195
920 0 return retval;
921  
922 18195 total += retval = NYTP_write(ofile, value, value_len);
923 18195 ▶ if (retval != value_len)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != value_len) 0 18195 18195
924 0 return retval;
925  
926 18195 total += retval = NYTP_write(ofile, "\n", 1);
927 18195 ▶ if (retval != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval != 1) 0 18195 18195
928 0 return retval;
929  
930 18195 return total;
931 }
932  
933 size_t
934 6045 NYTP_write_attribute_string(NYTP_file ofile,
935 const char *key, size_t key_len,
936 const char *value, size_t value_len)
937 {
938 6045 return NYTP_write_plain_kv(ofile, ':', key, key_len, value, value_len);
939 }
940  
941 #ifndef CHAR_BIT
942 # define CHAR_BIT 8
943 #endif
944 #define LOG_2_OVER_LOG_10 0.30103
945  
946 size_t
947 2700 NYTP_write_attribute_unsigned(NYTP_file ofile, const char *key,
948 size_t key_len, unsigned long value)
949 2700 {
950 /* 3: 1 for rounding errors, 1 for the '\0' */
951 2700 char buffer[(int)(sizeof (unsigned long) * CHAR_BIT * LOG_2_OVER_LOG_10 + 3)];
952 2700 const size_t len = my_snprintf(buffer, sizeof(buffer), "%lu", value);
953  
954 2700 return NYTP_write_attribute_string(ofile, key, key_len, buffer, len);
955 }
956  
957 size_t
958 675 NYTP_write_attribute_signed(NYTP_file ofile, const char *key,
959 size_t key_len, long value)
960 675 {
961 /* 3: 1 for rounding errors, 1 for the sign, 1 for the '\0' */
962 675 char buffer[(int)(sizeof (long) * CHAR_BIT * LOG_2_OVER_LOG_10 + 3)];
963 675 const size_t len = my_snprintf(buffer, sizeof(buffer), "%ld", value);
964  
965 675 return NYTP_write_attribute_string(ofile, key, key_len, buffer, len);
966 }
967  
968 size_t
969 645 NYTP_write_attribute_nv(NYTP_file ofile, const char *key,
970 size_t key_len, NV value)
971 {
972 char buffer[NV_DIG+20]; /* see Perl_sv_2pv_flags */
973 645 const size_t len = my_snprintf(buffer, sizeof(buffer), "%" NVgf, value);
974  
975 645 return NYTP_write_attribute_string(ofile, key, key_len, buffer, len);
976 }
977  
978 /* options */
979  
980 size_t
981 12150 NYTP_write_option_pv(NYTP_file ofile,
982 const char *key,
983 const char *value, size_t value_len)
984 {
985 12150 return NYTP_write_plain_kv(ofile, '!', key, strlen(key), value, value_len);
986 }
987  
988 size_t
989 12150 NYTP_write_option_iv(NYTP_file ofile, const char *key, IV value)
990 12150 {
991 /* 3: 1 for rounding errors, 1 for the sign, 1 for the '\0' */
992 12150 char buffer[(int)(sizeof (IV) * CHAR_BIT * LOG_2_OVER_LOG_10 + 3)];
993 12150 const size_t len = my_snprintf(buffer, sizeof(buffer), "%" IVdf, value);
994  
995 12150 return NYTP_write_option_pv(ofile, key, buffer, len);
996 }
997  
998 /* other */
999  
1000 #ifdef HAS_ZLIB
1001  
1002 size_t
1003 370 NYTP_start_deflate_write_tag_comment(NYTP_file ofile, int compression_level) {
1004 370 const unsigned char tag = NYTP_TAG_START_DEFLATE;
1005 size_t total;
1006 size_t retval;
1007  
1008 370 total = retval = NYTP_write_comment(ofile, "Compressed at level %d with zlib %s",
1009 compression_level, zlibVersion());
1010  
1011 370 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 370 370
1012 0 return retval;
1013  
1014 370 total += retval = NYTP_write(ofile, &tag, sizeof(tag));
1015 370 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 370 370
1016 0 return retval;
1017  
1018 370 NYTP_start_deflate(ofile, compression_level);
1019  
1020 370 return total;
1021 }
1022  
1023 #endif
1024  
1025 size_t
1026 675 NYTP_write_process_start(NYTP_file ofile, U32 pid, U32 ppid,
1027 NV time_of_day)
1028 {
1029 size_t total;
1030 size_t retval;
1031  
1032 675 total = retval = output_tag_u32(ofile, NYTP_TAG_PID_START, pid);
1033 675 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 675 675
1034 0 return retval;
1035  
1036 675 total += retval = output_u32(ofile, ppid);
1037 675 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 675 675
1038 0 return retval;
1039  
1040 675 total += retval = output_nv(ofile, time_of_day);
1041 675 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 675 675
1042 0 return retval;
1043  
1044 675 return total;
1045 }
1046  
1047 size_t
1048 645 NYTP_write_process_end(NYTP_file ofile, U32 pid, NV time_of_day)
1049 {
1050 size_t total;
1051 size_t retval;
1052  
1053 645 total = retval = output_tag_u32(ofile, NYTP_TAG_PID_END, pid);
1054 645 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 645 645
1055 0 return retval;
1056  
1057 645 total += retval = output_nv(ofile, time_of_day);
1058 645 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 645 645
1059 0 return retval;
1060  
1061 645 return total;
1062 }
1063  
1064 size_t
1065 0 NYTP_write_sawampersand(NYTP_file ofile, U32 fid, U32 line)
1066 {
1067 size_t total;
1068 size_t retval;
1069  
1070 0 total = retval = NYTP_write_attribute_unsigned(ofile, STR_WITH_LEN("sawampersand_fid"), fid);
1071 0 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 0 0
1072 0 return retval;
1073  
1074 0 total += retval = NYTP_write_attribute_unsigned(ofile, STR_WITH_LEN("sawampersand_line"), line);
1075 0 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 0 0
1076 0 return retval;
1077  
1078 0 return total;
1079 }
1080  
1081 size_t
1082 22736 NYTP_write_new_fid(NYTP_file ofile, U32 id, U32 eval_fid,
1083 U32 eval_line_num, U32 flags,
1084 U32 size, U32 mtime,
1085 const char *name, I32 len)
1086 {
1087 size_t total;
1088 size_t retval;
1089  
1090 22736 total = retval = output_tag_u32(ofile, NYTP_TAG_NEW_FID, id);
1091 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1092 0 return retval;
1093  
1094 22736 total += retval = output_u32(ofile, eval_fid);
1095 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1096 0 return retval;
1097  
1098 22736 total += retval = output_u32(ofile, eval_line_num);
1099 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1100 0 return retval;
1101  
1102 22736 total += retval = output_u32(ofile, flags);
1103 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1104 0 return retval;
1105  
1106 22736 total += retval = output_u32(ofile, size);
1107 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1108 0 return retval;
1109  
1110 22736 total += retval = output_u32(ofile, mtime);
1111 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1112 0 return retval;
1113  
1114 22736 total += retval = output_str(ofile, name, len);
1115 22736 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 22736 22736
1116 0 return retval;
1117  
1118 22736 return total;
1119 }
1120  
1121 static size_t
1122 197866018 write_time_common(NYTP_file ofile, unsigned char tag, I32 elapsed, U32 overflow,
1123 U32 fid, U32 line)
1124 {
1125 size_t total;
1126 size_t retval;
1127  
1128 197866018 ▶ if (overflow) {
Branch: 1 branch
BranchTrueFalseTotal
if (overflow) { 0 197866018 197866018
1129 dNFTHX(ofile);
1130 /* XXX needs protocol change to output a new time-overflow tag */
1131 0 fprintf(stderr, "profile time overflow of %lu seconds discarded!\n",
1132 (unsigned long)overflow);
1133 }
1134  
1135 197866018 total = retval = output_tag_i32(ofile, tag, elapsed);
1136 197866018 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 197866018 197866018
1137 0 return retval;
1138  
1139 197866018 total += retval = output_u32(ofile, fid);
1140 197866018 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 197866018 197866018
1141 0 return retval;
1142  
1143 197866018 total += retval = output_u32(ofile, line);
1144 197866018 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 197866018 197866018
1145 0 return retval;
1146  
1147 197866018 return total;
1148 }
1149  
1150 size_t
1151 188083441 NYTP_write_time_block(NYTP_file ofile, I32 elapsed, U32 overflow,
1152 U32 fid, U32 line, U32 last_block_line, U32 last_sub_line)
1153 {
1154 size_t total;
1155 size_t retval;
1156  
1157 188083441 total = retval = write_time_common(ofile, NYTP_TAG_TIME_BLOCK, elapsed, overflow,
1158 fid, line);
1159 188083441 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 188083441 188083441
1160 0 return retval;
1161  
1162 188083441 total += retval = output_u32(ofile, last_block_line);
1163 188083441 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 188083441 188083441
1164 0 return retval;
1165  
1166 188083441 total += retval = output_u32(ofile, last_sub_line);
1167 188083441 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 188083441 188083441
1168 0 return retval;
1169  
1170 188083441 return total;
1171 }
1172  
1173 size_t
1174 9782577 NYTP_write_time_line(NYTP_file ofile, I32 elapsed, U32 overflow,
1175 U32 fid, U32 line)
1176 {
1177 9782577 return write_time_common(ofile, NYTP_TAG_TIME_LINE, elapsed, overflow, fid, line);
1178 }
1179  
1180  
1181 size_t
1182 31370923 NYTP_write_call_entry(NYTP_file ofile, U32 caller_fid, U32 caller_line)
1183 {
1184 size_t total;
1185 size_t retval;
1186  
1187 31370923 total = retval = output_tag_u32(ofile, NYTP_TAG_SUB_ENTRY, caller_fid);
1188 31370923 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 31370923 31370923
1189 0 return retval;
1190  
1191 31370923 total += retval = output_u32(ofile, caller_line);
1192 31370923 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 31370923 31370923
1193 0 return retval;
1194  
1195 31370923 return total;
1196 }
1197  
1198 size_t
1199 99184900 NYTP_write_call_return(NYTP_file ofile, U32 prof_depth, const char *called_subname_pv,
1200 NV incl_subr_ticks, NV excl_subr_ticks)
1201 {
1202 size_t total;
1203 size_t retval;
1204  
1205 99184900 total = retval = output_tag_u32(ofile, NYTP_TAG_SUB_RETURN, prof_depth);
1206 99184900 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 99184900 99184900
1207 0 return retval;
1208  
1209 99184900 total += retval = output_nv(ofile, incl_subr_ticks);
1210 99184900 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 99184900 99184900
1211 0 return retval;
1212  
1213 99184900 total += retval = output_nv(ofile, excl_subr_ticks);
1214 99184900 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 99184900 99184900
1215 0 return retval;
1216  
1217 99184900 ▶ if (!called_subname_pv)
Branch: 1 branch
BranchTrueFalseTotal
if (!called_subname_pv) 0 99184900 99184900
1218 0 called_subname_pv = "(null)";
1219 99184900 total += retval = output_str(ofile, called_subname_pv, strlen(called_subname_pv));
1220 99184900 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 99184900 99184900
1221 0 return retval;
1222  
1223 99184900 return total;
1224 }
1225  
1226  
1227 size_t
1228 7506 NYTP_write_sub_info(NYTP_file ofile, U32 fid,
1229 const char *name, I32 len,
1230 U32 first_line, U32 last_line)
1231 {
1232 size_t total;
1233 size_t retval;
1234  
1235 7506 total = retval = output_tag_u32(ofile, NYTP_TAG_SUB_INFO, fid);
1236 7506 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 7506 7506
1237 0 return retval;
1238  
1239 7506 total += retval = output_str(ofile, name, (I32)len);
1240 7506 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 7506 7506
1241 0 return retval;
1242  
1243 7506 total += retval = output_u32(ofile, first_line);
1244 7506 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 7506 7506
1245 0 return retval;
1246  
1247 7506 total += retval = output_u32(ofile, last_line);
1248 7506 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 7506 7506
1249 0 return retval;
1250  
1251 7506 return total;
1252 }
1253  
1254 size_t
1255 423157 NYTP_write_sub_callers(NYTP_file ofile, U32 fid, U32 line,
1256 const char *caller_name, I32 caller_name_len,
1257 U32 count, NV incl_rtime, NV excl_rtime,
1258 NV reci_rtime, U32 depth,
1259 const char *called_name, I32 called_name_len)
1260 {
1261 size_t total;
1262 size_t retval;
1263  
1264 423157 total = retval = output_tag_u32(ofile, NYTP_TAG_SUB_CALLERS, fid);
1265 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1266 0 return retval;
1267  
1268 423157 total += retval = output_u32(ofile, line);
1269 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1270 0 return retval;
1271  
1272 423157 total += retval = output_str(ofile, caller_name, caller_name_len);
1273 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1274 0 return retval;
1275  
1276 423157 total += retval = output_u32(ofile, count);
1277 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1278 0 return retval;
1279  
1280 423157 total += retval = output_nv(ofile, incl_rtime);
1281 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1282 0 return retval;
1283  
1284 423157 total += retval = output_nv(ofile, excl_rtime);
1285 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1286 0 return retval;
1287  
1288 423157 total += retval = output_nv(ofile, reci_rtime);
1289 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1290 0 return retval;
1291  
1292 423157 total += retval = output_u32(ofile, depth);
1293 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1294 0 return retval;
1295  
1296 423157 total += retval = output_str(ofile, called_name, called_name_len);
1297 423157 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 423157 423157
1298 0 return retval;
1299  
1300 423157 return total;
1301 }
1302  
1303 size_t
1304 4023554 NYTP_write_src_line(NYTP_file ofile, U32 fid,
1305 U32 line, const char *text, I32 text_len)
1306 {
1307 size_t total;
1308 size_t retval;
1309  
1310 4023554 total = retval = output_tag_u32(ofile, NYTP_TAG_SRC_LINE, fid);
1311 4023554 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 4023554 4023554
1312 0 return retval;
1313  
1314 4023554 total += retval = output_u32(ofile, line);
1315 4023554 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 4023554 4023554
1316 0 return retval;
1317  
1318 4023554 total += retval = output_str(ofile, text, text_len);
1319 4023554 ▶ if (retval < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval < 1) 0 4023554 4023554
1320 0 return retval;
1321  
1322 4023554 return total;
1323 }
1324  
1325 size_t
1326 12217163 NYTP_write_discount(NYTP_file ofile)
1327 {
1328 12217163 const unsigned char tag = NYTP_TAG_DISCOUNT;
1329 12217163 return NYTP_write(ofile, &tag, sizeof(tag));
1330 }
1331  
1332  
1333 MODULE = Devel::NYTProf::FileHandle PACKAGE = Devel::NYTProf::FileHandle PREFIX = NYTP_
1334  
1335 PROTOTYPES: DISABLE
1336  
1337 void
1338 open(pathname, mode)
1339 char *pathname
1340 char *mode
1341 PREINIT:
1342 0 NYTP_file fh = NYTP_open(pathname, mode);
1343 SV *object;
1344 PPCODE:
1345 0 ▶ if(!fh)
Branch: 1 branch
BranchTrueFalseTotal
if(!fh) 0 0 0
1346 0 XSRETURN(0);
1347 0 object = newSV(0);
1348 0 sv_usepvn(object, (char *) fh, sizeof(struct NYTP_file_t));
1349 0 ST(0) = sv_bless(sv_2mortal(newRV_noinc(object)), gv_stashpvs("Devel::NYTProf::FileHandle", GV_ADD));
1350 0 XSRETURN(1);
1351  
1352 int
1353 DESTROY(handle)
1354 NYTP_file handle
1355 ALIAS:
1356 close = 1
1357 PREINIT:
1358 SV *guts;
1359 CODE:
1360 0 guts = SvRV(ST(0));
1361 PERL_UNUSED_VAR(ix);
1362 0 RETVAL = NYTP_close(handle, 0);
1363 0 SvPV_set(guts, NULL);
1364 0 ▶ SvLEN_set(guts, 0);
Branch: 1 branch
BranchTrueFalseTotal
SvLEN_set(guts, 0); 0 0 0
1365 OUTPUT:
1366 RETVAL
1367  
1368 size_t
1369 write(handle, string)
1370 NYTP_file handle
1371 SV *string
1372 PREINIT:
1373 STRLEN len;
1374 char *p;
1375 CODE:
1376 0 p = SvPVbyte(string, len);
1377 0 RETVAL = NYTP_write(handle, p, len);
1378 OUTPUT:
1379 RETVAL
1380  
1381 #ifdef HAS_ZLIB
1382  
1383 void
1384 NYTP_start_deflate(handle, compression_level = 6)
1385 NYTP_file handle
1386 int compression_level
1387  
1388 void
1389 NYTP_start_deflate_write_tag_comment(handle, compression_level = 6)
1390 NYTP_file handle
1391 int compression_level
1392  
1393 #endif
1394  
1395 size_t
1396 NYTP_write_comment(handle, comment)
1397 NYTP_file handle
1398 char *comment
1399 CODE:
1400 0 RETVAL = NYTP_write_comment(handle, "%s", comment);
1401 OUTPUT:
1402 RETVAL
1403  
1404 size_t
1405 NYTP_write_attribute(handle, key, value)
1406 NYTP_file handle
1407 SV *key
1408 SV *value
1409 PREINIT:
1410 STRLEN key_len;
1411 0 ▶ const char *const key_p = SvPVbyte(key, key_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const key_p = SvPVbyte(key, key_len); 0 0 0
1412 STRLEN value_len;
1413 0 ▶ const char *const value_p = SvPVbyte(value, value_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const value_p = SvPVbyte(value, value_len); 0 0 0
1414 CODE:
1415 0 RETVAL = NYTP_write_attribute_string(handle, key_p, key_len, value_p, value_len);
1416 OUTPUT:
1417 RETVAL
1418  
1419 size_t
1420 NYTP_write_option(handle, key, value)
1421 NYTP_file handle
1422 SV *key
1423 SV *value
1424 PREINIT:
1425 STRLEN key_len;
1426 0 ▶ const char *const key_p = SvPVbyte(key, key_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const key_p = SvPVbyte(key, key_len); 0 0 0
1427 STRLEN value_len;
1428 0 ▶ const char *const value_p = SvPVbyte(value, value_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const value_p = SvPVbyte(value, value_len); 0 0 0
1429 CODE:
1430 0 RETVAL = NYTP_write_option_pv(handle, key_p, value_p, value_len);
1431 OUTPUT:
1432 RETVAL
1433  
1434 size_t
1435 NYTP_write_process_start(handle, pid, ppid, time_of_day)
1436 NYTP_file handle
1437 U32 pid
1438 U32 ppid
1439 NV time_of_day
1440  
1441 size_t
1442 NYTP_write_process_end(handle, pid, time_of_day)
1443 NYTP_file handle
1444 U32 pid
1445 NV time_of_day
1446  
1447 size_t
1448 NYTP_write_new_fid(handle, id, eval_fid, eval_line_num, flags, size, mtime, name)
1449 NYTP_file handle
1450 U32 id
1451 U32 eval_fid
1452 int eval_line_num
1453 U32 flags
1454 U32 size
1455 U32 mtime
1456 SV *name
1457 PREINIT:
1458 STRLEN len;
1459 0 ▶ const char *const p = SvPV(name, len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const p = SvPV(name, len); 0 0 0
1460 CODE:
1461 0 RETVAL = NYTP_write_new_fid(handle, id, eval_fid, eval_line_num,
1462 flags, size, mtime, p,
1463 0 ▶ SvUTF8(name) ? -(I32)len : (I32)len );
Branch: 1 branch
BranchTrueFalseTotal
SvUTF8(name) ? -(I32)len : (I32)len ); 0 0 0
1464 OUTPUT:
1465 RETVAL
1466  
1467 size_t
1468 NYTP_write_time_block(handle, elapsed, overflow, fid, line, last_block_line, last_sub_line)
1469 NYTP_file handle
1470 U32 elapsed
1471 U32 overflow
1472 U32 fid
1473 U32 line
1474 U32 last_block_line
1475 U32 last_sub_line
1476  
1477 size_t
1478 NYTP_write_time_line(handle, elapsed, overflow, fid, line)
1479 NYTP_file handle
1480 U32 elapsed
1481 U32 overflow
1482 U32 fid
1483 U32 line
1484  
1485 size_t
1486 NYTP_write_call_entry(handle, caller_fid, caller_line)
1487 NYTP_file handle
1488 U32 caller_fid
1489 U32 caller_line
1490  
1491 size_t
1492 NYTP_write_call_return(handle, prof_depth, called_subname_pv, incl_subr_ticks, excl_subr_ticks)
1493 NYTP_file handle
1494 U32 prof_depth
1495 const char *called_subname_pv
1496 NV incl_subr_ticks
1497 NV excl_subr_ticks
1498  
1499 size_t
1500 NYTP_write_sub_info(handle, fid, name, first_line, last_line)
1501 NYTP_file handle
1502 U32 fid
1503 SV *name
1504 U32 first_line
1505 U32 last_line
1506 PREINIT:
1507 STRLEN len;
1508 0 ▶ const char *const p = SvPV(name, len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const p = SvPV(name, len); 0 0 0
1509 CODE:
1510 0 RETVAL = NYTP_write_sub_info(handle, fid,
1511 0 ▶ p, SvUTF8(name) ? -(I32)len : (I32)len,
Branch: 1 branch
BranchTrueFalseTotal
p, SvUTF8(name) ? -(I32)len : (I32)len, 0 0 0
1512 first_line, last_line);
1513 OUTPUT:
1514 RETVAL
1515  
1516 size_t
1517 NYTP_write_sub_callers(handle, fid, line, caller, count, incl_rtime, excl_rtime, reci_rtime, depth, called_sub)
1518 NYTP_file handle
1519 U32 fid
1520 U32 line
1521 SV *caller
1522 U32 count
1523 NV incl_rtime
1524 NV excl_rtime
1525 NV reci_rtime
1526 U32 depth
1527 SV *called_sub
1528 PREINIT:
1529 STRLEN caller_len;
1530 0 ▶ const char *const caller_p = SvPV(caller, caller_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const caller_p = SvPV(caller, caller_len); 0 0 0
1531 STRLEN called_len;
1532 0 ▶ const char *const called_p = SvPV(called_sub, called_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const called_p = SvPV(called_sub, called_len); 0 0 0
1533 CODE:
1534 0 RETVAL = NYTP_write_sub_callers(handle, fid, line, caller_p,
1535 0 ▶ SvUTF8(caller) ? -(I32)caller_len : (I32)caller_len,
Branch: 1 branch
BranchTrueFalseTotal
SvUTF8(caller) ? -(I32)caller_len : (I32)caller_len, 0 0 0
1536 count, incl_rtime, excl_rtime,
1537 reci_rtime, depth, called_p,
1538 0 ▶ SvUTF8(called_sub) ? -(I32)called_len : (I32)called_len);
Branch: 1 branch
BranchTrueFalseTotal
SvUTF8(called_sub) ? -(I32)called_len : (I32)called_len); 0 0 0
1539 OUTPUT:
1540 RETVAL
1541  
1542 size_t
1543 NYTP_write_src_line(handle, fid, line, text)
1544 NYTP_file handle
1545 U32 fid
1546 U32 line
1547 SV *text
1548 PREINIT:
1549 STRLEN len;
1550 0 ▶ const char *const p = SvPV(text, len);
Branch: 1 branch
BranchTrueFalseTotal
const char *const p = SvPV(text, len); 0 0 0
1551 CODE:
1552 0 RETVAL = NYTP_write_src_line(handle, fid, line,
1553 0 ▶ p, SvUTF8(text) ? -(I32)len : (I32)len);
Branch: 1 branch
BranchTrueFalseTotal
p, SvUTF8(text) ? -(I32)len : (I32)len); 0 0 0
1554 OUTPUT:
1555 RETVAL
1556  
1557 size_t
1558 NYTP_write_discount(handle)
1559 NYTP_file handle
1560  
1561 size_t
1562 NYTP_write_header(handle, major, minor)
1563 NYTP_file handle
1564 U32 major
1565 U32 minor
1566  
« t/test03.p ↑ Summary NYTProf.xs »