r368 - trunk
flag
Messages 1 - 10 of 14 - Collapse all
/groups/adfetch?adid=kWQMBw8AAADFw8_H2Rh6d7cnDG6KHwo9
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
1.  codesite-nore...@google.com  
View profile  
 More options Jul 29 2008, 8:25 pm
From: codesite-nore...@google.com
Date: Tue, 29 Jul 2008 17:25:03 -0700
Local: Tues, Jul 29 2008 8:25 pm
Subject: [perl-devel-nytprof commit] r368 - trunk
Author: tim.bunce
Date: Tue Jul 29 09:45:08 2008
New Revision: 368

Modified:
   trunk/NYTProf.xs

Log:
Use fwrite in preference to fputc loop, thanks to Nicholas Clark.

Modified: trunk/NYTProf.xs
=========================================================================== ===
--- trunk/NYTProf.xs    (original)
+++ trunk/NYTProf.xs    Tue Jul 29 09:45:08 2008
@@ -334,8 +334,7 @@
        output_int(fid_info->fid_flags);
        output_int(fid_info->file_size);
        output_int(fid_info->file_mtime);
-       while (file_name_len--)
-               fputc(*file_name++, out);
+       fwrite(file_name, file_name_len, 1, out);
        fputc('\n', out);
 }

@@ -520,11 +519,7 @@
  */
 void
 output_nv(NV nv) {
-       int i = sizeof(NV);
-       unsigned char *p = (unsigned char *)&nv;
-       while (i-- > 0) {
-               fputc(*p++, out);
-       }
+       fwrite((unsigned char *)&nv, sizeof(NV), 1, out);
 }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "[perl-devel-nytprof commit] r368 - trunk" by Nicholas Clark
2.  Nicholas Clark  
View profile  
 More options Jul 30 2008, 4:53 am
From: Nicholas Clark <n...@ccl4.org>
Date: Wed, 30 Jul 2008 09:53:55 +0100
Local: Wed, Jul 30 2008 4:53 am
Subject: Re: [develnytprof-dev: 526] [perl-devel-nytprof commit] r368 - trunk

On Tue, Jul 29, 2008 at 05:25:03PM -0700, codesite-nore...@google.com wrote:

> Author: tim.bunce
> Date: Tue Jul 29 09:45:08 2008
> New Revision: 368

> Modified:
>    trunk/NYTProf.xs

> Log:
> Use fwrite in preference to fputc loop, thanks to Nicholas Clark.

I missed it's corresponding read loop though, didn't I? :-)

Still no error checking. Not sure of the best way to deal with that.

The way I read headers in PerlIO::gzip and ex::lib::zip was to fread() in
enough bytes (and error check that) then copy them out to the places they
were needed. No faffing with fgetc()/fputc() loops.

Nicholas Clark

Index: NYTProf.xs
===================================================================
--- NYTProf.xs  (revision 369)
+++ NYTProf.xs  (working copy)
@@ -1699,11 +1699,7 @@
 NV
 read_nv() {
        NV nv;
-       int i = sizeof(NV);
-       unsigned char *p = (unsigned char *)&nv;
-       while (i-- > 0) {
-               *p++ = (unsigned char)fgetc(in);
-       }
+       fread((unsigned char *)&nv, sizeof(NV), 1, in);
        return nv;
 }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
3.  Tim Bunce  
View profile  
 More options Jul 30 2008, 1:15 pm
From: Tim Bunce <Tim.Bu...@pobox.com>
Date: Wed, 30 Jul 2008 18:15:39 +0100
Local: Wed, Jul 30 2008 1:15 pm
Subject: Re: [develnytprof-dev: 528] Re: [perl-devel-nytprof commit] r368 - trunk

On Wed, Jul 30, 2008 at 09:53:55AM +0100, Nicholas Clark wrote:

> On Tue, Jul 29, 2008 at 05:25:03PM -0700, codesite-nore...@google.com wrote:

> > Author: tim.bunce
> > Date: Tue Jul 29 09:45:08 2008
> > New Revision: 368

> > Modified:
> >    trunk/NYTProf.xs

> > Log:
> > Use fwrite in preference to fputc loop, thanks to Nicholas Clark.

> I missed it's corresponding read loop though, didn't I? :-)

Applied, thanks.

> Still no error checking. Not sure of the best way to deal with that.

I added:
    /* no error checking on the assumption that a later token read will
     * detect the error/eof condition
     */
:)

> The way I read headers in PerlIO::gzip and ex::lib::zip was to fread() in
> enough bytes (and error check that) then copy them out to the places they
> were needed. No faffing with fgetc()/fputc() loops.

Hey, fancy adding zip support to NYTProf? :)

Meanwhile, want a commit bit?

Tim.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
4.  Nicholas Clark  
View profile  
 More options Jul 31 2008, 7:29 am
From: Nicholas Clark <n...@ccl4.org>
Date: Thu, 31 Jul 2008 12:29:44 +0100
Local: Thurs, Jul 31 2008 7:29 am
Subject: Re: [develnytprof-dev: 535] Re: [perl-devel-nytprof commit] r368 - trunk

On Wed, Jul 30, 2008 at 06:15:39PM +0100, Tim Bunce wrote:
> Hey, fancy adding zip support to NYTProf? :)

Not yet. I *think* that it might be as simple as

#include <zlib.h>

and then using gzopen() rather than fopen(), and using its gz*() functions
in place of f*()

> Meanwhile, want a commit bit?

Why not? I can add it to my collection. :-)

Nicholas Clark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)" by Nicholas Clark
5.  Nicholas Clark  
View profile  
 More options Aug 6 2008, 4:39 pm
From: Nicholas Clark <n...@ccl4.org>
Date: Wed, 6 Aug 2008 21:39:46 +0100
Local: Wed, Aug 6 2008 4:39 pm
Subject: compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)

On Thu, Jul 31, 2008 at 12:29:44PM +0100, Nicholas Clark wrote:

> On Wed, Jul 30, 2008 at 06:15:39PM +0100, Tim Bunce wrote:

> > Hey, fancy adding zip support to NYTProf? :)

> Not yet. I *think* that it might be as simple as

> #include <zlib.h>
> and then using gzopen() rather than fopen(), and using its gz*() functions
> in place of f*()

Right. I tried. Because right now I'm generating over 4Gb of profile data
trying to profile the harness in the Perl 5 core running tests in parallel.

I got to the appended in about an hour. It fails the tests, in a major way,
because there's no way to do this bit of cheating with a zlib compressed
file handle:

    /* any data that was unflushed in the parent when it forked
     * is now duplicated unflushed in this child process.
     * We need to be a little devious to prevent it getting flushed.
     */
    close(fileno(out));                           /* close the underlying fd first */
    NYT_close(out);                                  /* happily, this can't flush now */

and the underling implementation of zlib's compressed file handles uses stdio,
hence it can end up with unflushed data in the child.

Well, I think that there's no way of cheating. I can't see any way to
invalidate the FILE * hiding inside the gzFile, but I'd love to be proved
wrong.

If I'm not wrong, then the way to go seems to be to avoid fprintf, fscanf,
fputc, fgetc, and fgets, and instead recast all the input and output code
solely in terms of fread() and fwrite(). At which point they can be
conditionally replaced with routines that read or write blocks of data into
deflate() and inflate(), and we have to do all the manual handling ourselves.
However, it does mean that we can keep the current textual header, before
dropping into a deflated stream, if we so choose.

Nicholas Clark

Index: Makefile.PL
===================================================================
--- Makefile.PL (revision 390)
+++ Makefile.PL (working copy)
@@ -81,6 +81,7 @@

 my @LIBS = ();
 push @LIBS, "-lrt" if $clock_gettime;
+push @LIBS, "-lz";

 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
 # the contents of the Makefile that is written.
Index: NYTProf.xs
===================================================================
--- NYTProf.xs  (revision 390)
+++ NYTProf.xs  (working copy)
@@ -19,6 +19,8 @@
 #define PERL_NO_GET_CONTEXT                       /* we want efficiency */
 #endif

+#define HAS_ZLIB 1
+
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
@@ -28,6 +30,22 @@
 #   include "ppport.h"
 #endif

+#ifdef HAS_ZLIB
+#    include "zlib.h"
+#    define NYT_open(n, m)     gzopen((n), (m))
+#    define NYT_close  gzclose
+#    define NYT_read(p, l, f)  gzread((f), (p), (l))
+#    define NYT_write(p, l, f) gzwrite((f), (p), (l))
+#    define NYT_putc(i, f)     gzputc((f), (i))
+#    define NYT_getc   gzgetc
+#    define NYT_printf gzprintf
+#    define NYT_tell   gztell
+#    define NYT_gets(p, l, f)  gzgets((f), (p), (l))
+typedef gzFile NYT_File;
+#else
+typedef FILE *NYT_File;
+#endif
+
 #if !defined(OutCopFILE)
 #    define OutCopFILE CopFILE
 #endif
@@ -110,8 +128,8 @@
 /* END Hash table definitions */

 /* defaults */
-static FILE* out;
-static FILE* in;
+static NYT_File out;
+static NYT_File in;

 /* options and overrides */
 static char PROF_output_file[MAXPATHLEN+1] = "nytprof.out";
@@ -214,11 +232,11 @@
 #define getppid() 0
 #endif
 #define OUTPUT_PID() STMT_START { \
-    assert(out != NULL); fputc(NYTP_TAG_PID_START, out); output_int(getpid()); output_int(getppid()); \
+    assert(out != NULL); NYT_putc(NYTP_TAG_PID_START, out); output_int(getpid()); output_int(getppid()); \
 } STMT_END

 #define END_OUTPUT_PID(pid) STMT_START { \
-    assert(out != NULL); fputc(NYTP_TAG_PID_END, out); output_int(pid); fflush(out); \
+    assert(out != NULL); NYT_putc(NYTP_TAG_PID_END, out); output_int(pid); fflush(out); \
 } STMT_END

 /***********************************
@@ -236,25 +254,25 @@

     assert(out != NULL);
     /* File header with "magic" string, with file major and minor version */
-    fprintf(out, "NYTProf %d %d\n", 2, 0);
+    NYT_printf(out, "NYTProf %d %d\n", 2, 0);
     /* Human readable comments and attributes follow
      * comments start with '#', end with '\n', and are discarded
      * attributes start with ':', a word, '=', then the value, then '\n'
      */
-    fprintf(out, "# Perl profile database. Generated by Devel::NYTProf on %s",
+    NYT_printf(out, "# Perl profile database. Generated by Devel::NYTProf on %s",
         ctime(&basetime));                        /* uses \n from ctime to terminate line */

     /* XXX add options, $0, etc, but beware of embedded newlines */
     /* XXX would be good to adopt a proper charset & escaping for these */
     /* $^T */
-    fprintf(out, ":%s=%lu\n",      "basetime",      (unsigned long)PL_basetime);
-    fprintf(out, ":%s=%s\n",       "xs_version",    XS_VERSION);
-    fprintf(out, ":%s=%d.%d.%d\n", "perl_version",  PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
-    fprintf(out, ":%s=%u\n",       "ticks_per_sec", ticks_per_sec);
-    fprintf(out, ":%s=%lu\n",      "nv_size", sizeof(NV));
+    NYT_printf(out, ":%s=%lu\n",      "basetime",      (unsigned long)PL_basetime);
+    NYT_printf(out, ":%s=%s\n",       "xs_version",    XS_VERSION);
+    NYT_printf(out, ":%s=%d.%d.%d\n", "perl_version",  PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
+    NYT_printf(out, ":%s=%u\n",       "ticks_per_sec", ticks_per_sec);
+    NYT_printf(out, ":%s=%lu\n",      "nv_size", sizeof(NV));
     /* $0 - application name */
     mg_get(sv = get_sv("0",GV_ADDWARN));
-    fprintf(out, ":%s=%s\n",       "application", SvPV_nolen(sv));
+    NYT_printf(out, ":%s=%s\n",       "application", SvPV_nolen(sv));

     OUTPUT_PID();

@@ -273,9 +291,9 @@
         tag = NYTP_TAG_STRING_UTF8;
         len = -len;
     }
-    fputc(tag, out);
+    NYT_putc(tag, out);
     output_int(len);
-    fwrite(str, 1, len, out);
+    NYT_write(str, len, out);
 }

@@ -283,10 +301,10 @@
 read_str(pTHX_ SV *sv) {
     STRLEN len;
     char *buf;
-    char tag = fgetc(in);
+    char tag = NYT_getc(in);
     if (NYTP_TAG_STRING != tag && NYTP_TAG_STRING_UTF8 != tag)
         croak("File format error at offset %ld, expected string tag but found %d ('%c')",
-            (long)ftell(in)-1, tag, tag);
+            (long)NYT_tell(in)-1, tag, tag);

     len = read_int();
     if (sv) {
@@ -298,9 +316,9 @@
     }

     buf = SvPV_nolen(sv);
-    if (fread(buf, 1, len, in) != len)
+    if (NYT_read(buf, len, in) != len)
         croak("String truncated in file at offset %ld: %s",
-            (long)ftell(in)-1, (feof(in)) ? "end of file" : strerror(ferror(in)));
+            (long)NYT_tell(in)-1, (feof(in)) ? "end of file" : strerror(ferror(in)));
     SvCUR_set(sv, len);
     *SvEND(sv) = '\0';

@@ -415,7 +433,7 @@
         file_name = fid_info->key_abs;
         file_name_len = strlen(file_name);
     }
-    fputc(NYTP_TAG_NEW_FID, out);
+    NYT_putc(NYTP_TAG_NEW_FID, out);
     output_int(fid_info->id);
     output_int(fid_info->eval_fid);
     output_int(fid_info->eval_line_num);
@@ -592,29 +610,29 @@

     /* general case. handles all integers */
     if (i < 0x80) {                               /* < 8 bits */
-        fputc( (char)i, out);
+        NYT_putc( (char)i, out);
     }
     else if (i < 0x4000) {                        /* < 15 bits */
-        fputc( (char)((i >> 8) | 0x80), out);
-        fputc( (char)i, out);
+        NYT_putc( (char)((i >> 8) | 0x80), out);
+        NYT_putc( (char)i, out);
     }
     else if (i < 0x200000) {                      /* < 22 bits */
-        fputc( (char)((i >> 16) | 0xC0), out);
-        fputc( (char)(i >> 8), out);
-        fputc( (char)i, out);
+        NYT_putc( (char)((i >> 16) | 0xC0), out);
+        NYT_putc( (char)(i >> 8), out);
+        NYT_putc( (char)i, out);
     }
     else if (i < 0x10000000) {                    /* 32 bits */
-        fputc( (char)((i >> 24) | 0xE0), out);
-        fputc( (char)(i >> 16), out);
-        fputc( (char)(i >> 8), out);
-        fputc( (char)i, out);
+        NYT_putc( (char)((i >> 24) | 0xE0), out);
+        NYT_putc( (char)(i >> 16), out);
+        NYT_putc( (char)(i >> 8), out);
+        NYT_putc( (char)i, out);
     }
     else {                                        /* need all the bytes. */
-        fputc( 0xFF, out);
-        fputc( (char)(i >> 24), out);
-        fputc( (char)(i >> 16), out);
-        fputc( (char)(i >> 8), out);
-        fputc( (char)i, out);
+        NYT_putc( 0xFF, out);
+        NYT_putc( (char)(i >> 24), out);
+        NYT_putc( (char)(i >> 16), out);
+        NYT_putc( (char)(i >> 8), out);
+        NYT_putc( (char)i, out);
     }
 }

@@ -626,7 +644,7 @@
 void
 output_nv(NV nv)
 {
-    fwrite((unsigned char *)&nv, sizeof(NV), 1, out);
+    NYT_write((unsigned char *)&nv, sizeof(NV), out);
 }

@@ -928,7 +946,7 @@
     if (last_executed_fid) {
         reinit_if_forked(aTHX);

-        fputc( (profile_blocks) ? NYTP_TAG_TIME_BLOCK : NYTP_TAG_TIME_LINE, out);
+        NYT_putc( (profile_blocks) ? NYTP_TAG_TIME_BLOCK : NYTP_TAG_TIME_LINE, out);
         output_int(elapsed);
         output_int(last_executed_fid);
         output_int(last_executed_line);
@@ -1025,7 +1043,7 @@
      * increment the count (because the time is not for a new statement but simply
      * a continuation of a previously counted statement).
      */
-    fputc(NYTP_TAG_DISCOUNT, out);
+    NYT_putc(NYTP_TAG_DISCOUNT, out);

     if (trace_level >= 4) {
         warn("left %u:%u via %s back to %s at %u:%u (b%u s%u) - discounting next statement%s\n",
@@ -1101,7 +1119,7 @@
         /* caller is expected to have purged/closed old out if appropriate */
     }

-    out = fopen(filename, "wb");
+    out = NYT_open(filename, "wb");
     if (!out) {
         disable_profile(aTHX);
         croak("Failed to open output '%s': %s", filename, strerror(errno));
@@
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
6.  Tim Bunce  
View profile  
 More options Aug 7 2008, 4:28 am
From: Tim Bunce <Tim.Bu...@pobox.com>
Date: Thu, 7 Aug 2008 09:28:11 +0100
Local: Thurs, Aug 7 2008 4:28 am
Subject: Re: [develnytprof-dev: 567] compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)

Ouch!

(We also need a way to turn off the statement profiler, just leaving the
sub profiler running. That would be a big help. Then we'd need a way to
enable the statement profiler for individual subs or packages.)

We could perhaps use this trick... just before opening the file using
gzopen(), open a file ourselves, note the fd, then close it. Then when
gzopen() it'll _probably_ open a file with the same fd.

(An extra level of safety could be added by opening two files, getting
two fds and closing them. Then, after the gzopen(), we could open
another file and see if the new fd is the same as the second one
we opened previously.)

Tim.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
7.  Nicholas Clark  
View profile  
 More options Aug 8 2008, 12:28 pm
From: Nicholas Clark <n...@ccl4.org>
Date: Fri, 8 Aug 2008 17:28:58 +0100
Local: Fri, Aug 8 2008 12:28 pm
Subject: Re: [develnytprof-dev: 568] Re: compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)

On Thu, Aug 07, 2008 at 09:28:11AM +0100, Tim Bunce wrote:
> We could perhaps use this trick... just before opening the file using
> gzopen(), open a file ourselves, note the fd, then close it. Then when
> gzopen() it'll _probably_ open a file with the same fd.

> (An extra level of safety could be added by opening two files, getting
> two fds and closing them. Then, after the gzopen(), we could open
> another file and see if the new fd is the same as the second one
> we opened previously.)

That feels very fragile to me.

Nicholas Clark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
8.  Nicholas Clark  
View profile  
 More options Aug 10 2008, 1:08 pm
From: Nicholas Clark <n...@ccl4.org>
Date: Sun, 10 Aug 2008 18:08:51 +0100
Local: Sun, Aug 10 2008 1:08 pm
Subject: Re: compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)

On Wed, Aug 06, 2008 at 09:39:46PM +0100, Nicholas Clark wrote:
> If I'm not wrong, then the way to go seems to be to avoid fprintf, fscanf,
> fputc, fgetc, and fgets, and instead recast all the input and output code
> solely in terms of fread() and fwrite(). At which point they can be
> conditionally replaced with routines that read or write blocks of data into
> deflate() and inflate(), and we have to do all the manual handling ourselves.
> However, it does mean that we can keep the current textual header, before
> dropping into a deflated stream, if we so choose.

Which doesn't seem to be that hard, so I've started on it.

To me, currently, it seems that the way to go might well be to keep the current
plain text header, then switch to a compressed stream straight after it. This
could probably be done by having a tag that says "zlib compressed stream
starts here" and a pointer to swappable tables of read/write/... functions
for compressed and uncompressed.

Nicholas Clark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
9.  Tim Bunce  
View profile  
 More options Aug 10 2008, 5:28 pm
From: Tim Bunce <tim.bu...@gmail.com>
Date: Sun, 10 Aug 2008 22:28:49 +0100
Local: Sun, Aug 10 2008 5:28 pm
Subject: Re: [develnytprof-dev: 583] Re: compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)
Sounds good to me! Thanks.

It'll be interesting to see how it affects performance. I think  
there's a good chance performance will improve for most people as  
we'll be reducing the io by ~90%. May just need to set the default  
compression level to achieve a good balance.

Any portability issues?

Tim.

Sent from my iPhone

On 10 Aug 2008, at 18:08, Nicholas Clark <n...@ccl4.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
10.  Adam Kaplan  
View profile  
 More options Aug 11 2008, 4:52 pm
From: "Adam Kaplan" <akap...@nytimes.com>
Date: Mon, 11 Aug 2008 16:52:53 -0400
Local: Mon, Aug 11 2008 4:52 pm
Subject: Re: [develnytprof-dev: 595] Re: compressed profiles (was Re: [develnytprof-dev: 542] Re: [perl-devel-nytprof commit] r368 - trunk)

On Sun, Aug 10, 2008 at 17:28, Tim Bunce <tim.bu...@gmail.com> wrote:

> Sounds good to me! Thanks.

> It'll be interesting to see how it affects performance. I think
> there's a good chance performance will improve for most people as
> we'll be reducing the io by ~90%. May just need to set the default
> compression level to achieve a good balance.

> Any portability issues?

> Tim.

Wow, that would be incredible.

--
Adam J. Kaplan
Software Engineer, Code Critic and Cocoa Drinker.
The New York Times Company


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2013 Google