Revision: 970 Author: [email protected] Date: Fri Dec 18 09:04:12 2009 Log: Add methods write(), output_int(), output_nv() and output_str() to Devel::NYTProf::FileHandle. It's now possible to write out a profile file from Perl. http://code.google.com/p/perl-devel-nytprof/source/detail?r=970
Added: /trunk/NYTProf.h Modified: /trunk/FileHandle.xs /trunk/MANIFEST /trunk/NYTProf.xs ======================================= --- /dev/null +++ /trunk/NYTProf.h Fri Dec 18 09:04:12 2009 @@ -0,0 +1,28 @@ +/* vim: ts=8 sw=4 expandtab: + * ************************************************************************ + * This file is part of the Devel::NYTProf package. + * Copyright 2008 Adam J. Kaplan, The New York Times Company. + * Copyright 2008 Tim Bunce, Ireland. + * Released under the same terms as Perl 5.8 + * See http://search.cpan.org/dist/Devel-NYTProf/ + * + * Contributors: + * Adam Kaplan, akaplan at nytimes.com + * Tim Bunce, http://www.tim.bunce.name and http://blog.timbunce.org + * Steve Peters, steve at fisharerojo.org + * + * ************************************************************************ + * $Id$ + * ************************************************************************ + */ + +/* FIXME - The callers of these functions should be refactored into their own + library file, with a public API, the XS interface adapted to use that API, + and these 3 return to being static functions, within that library. */ + +void output_tag_int(NYTP_file file, unsigned char tag, unsigned int); +void output_str(NYTP_file file, char *str, I32 len); +void output_nv(NYTP_file file, NV nv); + +#define NYTP_TAG_NO_TAG '\0' /* Used as a flag to mean "no tag" */ +#define output_int(fh, i) output_tag_int((fh), NYTP_TAG_NO_TAG, (unsigned int)(i)) ======================================= --- /trunk/FileHandle.xs Fri Dec 18 09:03:53 2009 +++ /trunk/FileHandle.xs Fri Dec 18 09:04:12 2009 @@ -21,6 +21,7 @@ #include "XSUB.h" #include "FileHandle.h" +#include "NYTProf.h" #ifdef HAS_ZLIB # include <zlib.h> @@ -608,3 +609,60 @@ SvLEN_set(guts, 0); OUTPUT: RETVAL + +size_t +write(handle, string) +SV *handle +SV *string + PREINIT: + STRLEN len; + char *p; + NYTP_file fh; + CODE: + if(!sv_isa(handle, "Devel::NYTProf::FileHandle")) + croak("handle is not a Devel::NYTProf::FileHandle"); + p = SvPVbyte(string, len); + fh = (NYTP_file)SvPVX(SvRV(handle)); + RETVAL = NYTP_write(fh, p, len); + OUTPUT: + RETVAL + +void +output_int(handle, value) +SV *handle +unsigned int value + PREINIT: + NYTP_file fh; + CODE: + if(!sv_isa(handle, "Devel::NYTProf::FileHandle")) + croak("handle is not a Devel::NYTProf::FileHandle"); + fh = (NYTP_file)SvPVX(SvRV(handle)); + output_int(fh, value); + +void +output_nv(handle, value) +SV *handle +NV value + PREINIT: + NYTP_file fh; + CODE: + if(!sv_isa(handle, "Devel::NYTProf::FileHandle")) + croak("handle is not a Devel::NYTProf::FileHandle"); + fh = (NYTP_file)SvPVX(SvRV(handle)); + output_nv(fh, value); + + +void +output_str(handle, value) +SV *handle +SV *value + PREINIT: + STRLEN len; + char *p; + NYTP_file fh; + CODE: + if(!sv_isa(handle, "Devel::NYTProf::FileHandle")) + croak("handle is not a Devel::NYTProf::FileHandle"); + fh = (NYTP_file)SvPVX(SvRV(handle)); + p = SvPV(value, len); + output_str(fh, p, SvUTF8(value) ? -(I32)len : (I32) len); ======================================= --- /trunk/MANIFEST Fri Dec 18 09:03:53 2009 +++ /trunk/MANIFEST Fri Dec 18 09:04:12 2009 @@ -8,6 +8,7 @@ INSTALL MANIFEST Makefile.PL +NYTProf.h NYTProf.xs README benchmark.pl ======================================= --- /trunk/NYTProf.xs Fri Dec 18 09:04:05 2009 +++ /trunk/NYTProf.xs Fri Dec 18 09:04:12 2009 @@ -24,6 +24,7 @@ #include "XSUB.h" #include "FileHandle.h" +#include "NYTProf.h" #ifndef NO_PPPORT_H #define NEED_eval_pv @@ -136,7 +137,6 @@ #define NYTP_TAG_STRING '\'' #define NYTP_TAG_STRING_UTF8 '"' #define NYTP_TAG_START_DEFLATE 'z' -#define NYTP_TAG_NO_TAG '\0' /* Used as a flag to mean "no tag" */ /* indices to elements of the file info array */ #define NYTP_FIDi_FILENAME 0 @@ -325,10 +325,6 @@ /* prototypes */ static void output_header(pTHX); -static void output_tag_int(NYTP_file file, unsigned char tag, unsigned int); -#define output_int(fh, i) output_tag_int(fh, NYTP_TAG_NO_TAG, (unsigned int)(i)) -static void output_str(NYTP_file file, char *str, I32 len); -static void output_nv(NYTP_file file, NV nv); static unsigned int read_int(void); static SV *read_str(pTHX_ SV *sv); static unsigned int get_file_id(pTHX_ char*, STRLEN, int created_via); @@ -458,7 +454,7 @@ } -static void +void output_str(NYTP_file file, char *str, I32 len) { /* negative len signifies utf8 */ unsigned char tag = NYTP_TAG_STRING; if (len < 0) { @@ -928,7 +924,7 @@ * "In bytes" means output the number in binary, using the least number of bytes * possible. All numbers are positive. Use sign slot as a marker */ -static void +void output_tag_int(NYTP_file file, unsigned char tag, unsigned int i) { U8 buffer[6]; @@ -982,7 +978,7 @@ * Output a double precision float via a simple binary write of the memory. * (Minor portbility issues are seen as less important than speed and space.) */ -static void +void output_nv(NYTP_file file, NV nv) { NYTP_write(file, (unsigned char *)&nv, sizeof(NV)); -- You've received this message because you are subscribed to the Devel::NYTProf Development User group. Group hosted at: http://groups.google.com/group/develnytprof-dev Project hosted at: http://perl-devel-nytprof.googlecode.com CPAN distribution: http://search.cpan.org/dist/Devel-NYTProf To post, email: [email protected] To unsubscribe, email: [email protected]
