From 306c39e6388ddf76aa10746895d99bb9ac52f6c2 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 11 Feb 2010 15:19:40 +0000 Subject: [PATCH] Abstract writing source lines info into NYTP_write_src_line(), wrap it and use it from nytprofmerge. --- FileHandle.h | 2 ++ FileHandle.xs | 38 ++++++++++++++++++++++++++++++++++++++ NYTProf.xs | 4 +--- bin/nytprofmerge | 4 +--- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/FileHandle.h b/FileHandle.h index 572d6c1..be7b600 100644 --- a/FileHandle.h +++ b/FileHandle.h @@ -92,3 +92,5 @@ size_t NYTP_write_sub_callers(NYTP_file ofile, unsigned int fid, NV incl_utime, NV incl_stime, NV reci_rtime, unsigned int depth, const char *called_name, I32 called_name_len); +size_t NYTP_write_src_line(NYTP_file ofile, unsigned int fid, + unsigned int line, const char *text, I32 text_len); diff --git a/FileHandle.xs b/FileHandle.xs index 2aeae91..a383972 100644 --- a/FileHandle.xs +++ b/FileHandle.xs @@ -932,6 +932,29 @@ NYTP_write_sub_callers(NYTP_file ofile, unsigned int fid, unsigned int line, return total; } +size_t +NYTP_write_src_line(NYTP_file ofile, unsigned int fid, + unsigned int line, const char *text, I32 text_len) +{ + size_t total; + size_t retval; + + total = retval = output_tag_int(ofile, NYTP_TAG_SRC_LINE, fid); + if (retval < 1) + return retval; + + total += retval = output_int(ofile, line); + if (retval < 1) + return retval; + + total += retval = output_str(ofile, text, text_len); + if (retval < 1) + return retval; + + return total; +} + + MODULE = Devel::NYTProf::FileHandle PACKAGE = Devel::NYTProf::FileHandle PREFIX = NYTP_ PROTOTYPES: DISABLE @@ -1145,3 +1168,18 @@ SV *called_sub SvUTF8(called_sub) ? -(I32)called_len : (I32)called_len); OUTPUT: RETVAL + +size_t +NYTP_write_src_line(handle, fid, line, text) +NYTP_file handle +unsigned int fid +unsigned int line +SV *text + PREINIT: + STRLEN len; + const char *const p = SvPV(text, len); + CODE: + RETVAL = NYTP_write_src_line(handle, fid, line, + p, SvUTF8(text) ? -(I32)len : (I32)len); + OUTPUT: + RETVAL diff --git a/NYTProf.xs b/NYTProf.xs index d1de9cc..57ce444 100644 --- a/NYTProf.xs +++ b/NYTProf.xs @@ -3354,9 +3354,7 @@ write_src_of_files(pTHX) char *src = (svp) ? SvPV(*svp, len) : ""; /* outputting the tag and fid for each (non empty) line * is a little inefficient, but not enough to worry about */ - output_tag_int(out, NYTP_TAG_SRC_LINE, e->id); - output_int(out, line); - output_str(out, src, (I32)len); /* includes newline */ + NYTP_write_src_line(out, e->id, line, src, (I32)len); /* includes newline */ if (trace_level >= 5) { logwarn("fid %d src line %d: %s%s", e->id, line, src, (len && src[len-1]=='\n') ? "" : "\n"); diff --git a/bin/nytprofmerge b/bin/nytprofmerge index 827a389..8b5a335 100755 --- a/bin/nytprofmerge +++ b/bin/nytprofmerge @@ -201,9 +201,7 @@ my %dispatcher = # Is this a subroutine (re)defined in an eval? my $mapped_fid = $map_range{$fid}[$line]; $fid = $mapped_fid if defined $mapped_fid; - $out->write('S'); - $out->output_int($fid, $line); - $out->output_str($text); + $out->write_src_line($fid, $line, $text); }, ); -- 1.6.0