From 9809bea87dcd48496852407330a8dbc1fbc15111 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 11 Feb 2010 12:58:03 +0000 Subject: [PATCH] Abstract writing sub info into NYTP_write_sub_info(), wrap it and use it nytprofmerge. --- FileHandle.h | 3 +++ FileHandle.xs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ NYTProf.xs | 7 ++----- bin/nytprofmerge | 5 +---- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/FileHandle.h b/FileHandle.h index 55d39bb..f8358e0 100644 --- a/FileHandle.h +++ b/FileHandle.h @@ -82,3 +82,6 @@ size_t NYTP_write_time_block(NYTP_file ofile, unsigned int elapsed, unsigned int last_sub_line); size_t NYTP_write_time_line(NYTP_file ofile, unsigned int elapsed, unsigned int fid, unsigned int line); +size_t NYTP_write_sub_info(NYTP_file ofile, unsigned int fid, + const char *name, I32 len, + unsigned int first_line, unsigned int last_line); diff --git a/FileHandle.xs b/FileHandle.xs index 88d7b61..92d0244 100644 --- a/FileHandle.xs +++ b/FileHandle.xs @@ -841,6 +841,39 @@ NYTP_write_time_line(NYTP_file ofile, unsigned int elapsed, unsigned int fid, return write_time_common(ofile, NYTP_TAG_TIME_LINE, elapsed, fid, line); } +size_t +NYTP_write_sub_info(NYTP_file ofile, unsigned int fid, + const char *name, I32 len, + unsigned int first_line, unsigned int last_line) +{ + size_t total; + size_t retval; + + total = retval = output_tag_int(ofile, NYTP_TAG_SUB_INFO, fid); + if (retval < 1) + return retval; + + total += retval = output_str(ofile, name, (I32)len); + if (retval < 1) + return retval; + + total += retval = output_int(ofile, first_line); + if (retval < 1) + return retval; + + total += retval = output_int(ofile, last_line); + if (retval < 1) + return retval; + + /* FIXME. Next time we change the file format, remove this: */ + /* how many extra items follow */ + total += retval = output_int(ofile, 0); + if (retval < 1) + return retval; + + return total; +} + MODULE = Devel::NYTProf::FileHandle PACKAGE = Devel::NYTProf::FileHandle PREFIX = NYTP_ PROTOTYPES: DISABLE @@ -1008,3 +1041,20 @@ NYTP_file handle unsigned int elapsed unsigned int fid unsigned int line + +size_t +NYTP_write_sub_info(handle, fid, name, first_line, last_line) +NYTP_file handle +unsigned int fid +SV *name +unsigned int first_line +unsigned int last_line + PREINIT: + STRLEN len; + const char *const p = SvPV(name, len); + CODE: + RETVAL = NYTP_write_sub_info(handle, fid, + p, SvUTF8(name) ? -(I32)len : (I32)len, + first_line, last_line); + OUTPUT: + RETVAL diff --git a/NYTProf.xs b/NYTProf.xs index 74e906b..0024a3c 100644 --- a/NYTProf.xs +++ b/NYTProf.xs @@ -3183,11 +3183,8 @@ write_sub_line_ranges(pTHX) logwarn("Sub %s fid %u lines %lu..%lu\n", sub_name, fid, (unsigned long)first_line, (unsigned long)last_line); - output_tag_int(out, NYTP_TAG_SUB_INFO, fid); - output_str(out, sub_name, sub_name_len); - output_int(out, first_line); - output_int(out, last_line); - output_int(out, 0); /* how many extra items follow */ + NYTP_write_sub_info(out, fid, sub_name, sub_name_len, first_line, + last_line); } } diff --git a/bin/nytprofmerge b/bin/nytprofmerge index 5481894..1514c8f 100755 --- a/bin/nytprofmerge +++ b/bin/nytprofmerge @@ -162,10 +162,7 @@ my %dispatcher = my $output_fid = $pending_subs{"$fid,$first_line,$last_line,$name"}; return unless defined $output_fid; - $out->write('s'); - $out->output_int($output_fid); - $out->output_str($name); - $out->output_int($first_line, $last_line, 0); + $out->write_sub_info($output_fid, $name, $first_line, $last_line); }, SUB_CALLERS => sub { my (undef, $fid, $line, $count, $incl_time, $excl_time, $ucpu_time, $scpu_time, $reci_time, $rec_depth, $called, $caller) = @_; -- 1.6.0