From 743b813c8b1f33bc89018c5e6c529623659eb13c Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 11 Feb 2010 16:16:21 +0000 Subject: [PATCH] Add NYTP_start_deflate_write_tag_comment(), which abstracts writing out the comment with the compression details (only available in the XS code), the "start compression" tag, and starts compression. Use this from nytprofmerge, which removes the finale $out->write(...) call. Now the output file format is completely wrapped in XS. --- FileHandle.h | 1 + FileHandle.xs | 26 ++++++++++++++++++++++++++ NYTProf.xs | 6 +----- bin/nytprofmerge | 5 ++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/FileHandle.h b/FileHandle.h index 9cbfd92..1f91c28 100644 --- a/FileHandle.h +++ b/FileHandle.h @@ -70,6 +70,7 @@ size_t NYTP_write_attribute_signed(NYTP_file ofile, const char *key, size_t key_len, long value); size_t NYTP_write_attribute_unsigned(NYTP_file ofile, const char *key, size_t key_len, unsigned long value); +size_t NYTP_start_deflate_write_tag_comment(NYTP_file ofile, int compression_level); size_t NYTP_write_process_start(NYTP_file ofile, unsigned int pid, unsigned int ppid, NV time_of_day); size_t NYTP_write_process_end(NYTP_file ofile, unsigned int pid, diff --git a/FileHandle.xs b/FileHandle.xs index a23655a..4cb3840 100644 --- a/FileHandle.xs +++ b/FileHandle.xs @@ -797,6 +797,27 @@ NYTP_write_attribute_signed(NYTP_file ofile, const char *key, } size_t +NYTP_start_deflate_write_tag_comment(NYTP_file ofile, int compression_level) { + const unsigned char tag = NYTP_TAG_START_DEFLATE; + size_t total; + size_t retval; + + total = retval = NYTP_write_comment(ofile, "Compressed at level %d with zlib %s", + compression_level, zlibVersion()); + + if (retval < 1) + return retval; + + total += retval = NYTP_write(ofile, &tag, sizeof(tag)); + if (retval < 1) + return retval; + + NYTP_start_deflate(ofile, compression_level); + + return total; +} + +size_t NYTP_write_process_start(NYTP_file ofile, unsigned int pid, unsigned int ppid, NV time_of_day) { @@ -1142,6 +1163,11 @@ NYTP_start_deflate(handle, compression_level = 6) NYTP_file handle int compression_level +void +NYTP_start_deflate_write_tag_comment(handle, compression_level = 6) +NYTP_file handle +int compression_level + #endif int diff --git a/NYTProf.xs b/NYTProf.xs index b19a151..ee096e5 100644 --- a/NYTProf.xs +++ b/NYTProf.xs @@ -456,11 +456,7 @@ output_header(pTHX) #ifdef HAS_ZLIB if (compression_level) { - const unsigned char tag = NYTP_TAG_START_DEFLATE; - NYTP_write_comment(out, "Compressed at level %d with zlib %s", - compression_level, zlibVersion()); - NYTP_write(out, &tag, sizeof(tag)); - NYTP_start_deflate(out, compression_level); + NYTP_start_deflate_write_tag_comment(out, compression_level); } #endif diff --git a/bin/nytprofmerge b/bin/nytprofmerge index dcd2d69..2e57460 100755 --- a/bin/nytprofmerge +++ b/bin/nytprofmerge @@ -125,9 +125,8 @@ my %dispatcher = }, START_DEFLATE => sub { - if (!$deflating && $out->can('start_deflate')) { - $out->write('z'); - $out->start_deflate; + if (!$deflating && $out->can('start_deflate_write_tag_comment')) { + $out->start_deflate_write_tag_comment; ++$deflating; } }, -- 1.6.0