Revision: 1194
Author: [email protected]
Date: Thu Apr 22 03:23:05 2010
Log: Added automatic detection of calls to POSIX::_exit() by the sub profiler
so finish_profile() gets called and a usable profile is produced.
Added posix_exit=1 option to do the same thing (in a different way)
when the sub profiler is not beeing used (i.e., subs=0).

http://code.google.com/p/perl-devel-nytprof/source/detail?r=1194

Modified:
 /trunk/Changes
 /trunk/NYTProf.xs
 /trunk/lib/Devel/NYTProf/Core.pm
 /trunk/lib/Devel/NYTProf.pm

=======================================
--- /trunk/Changes      Sat Apr 17 05:34:28 2010
+++ /trunk/Changes      Thu Apr 22 03:23:05 2010
@@ -24,6 +24,11 @@

   Enabled savesrc=1 by default.

+  Added automatic detection of calls to POSIX::_exit() by the sub profiler
+    so finish_profile() gets called and a usable profile is produced.
+  Added posix_exit=1 option to do the same thing (in a different way)
+    when the sub profiler is not beeing used (i.e., subs=0).
+
   Corrected typos in nytprofhtml docs thanks to [email protected]

   Sequences of blank lines are skipped in generated reports.
=======================================
--- /trunk/NYTProf.xs   Sun Apr 18 09:17:15 2010
+++ /trunk/NYTProf.xs   Thu Apr 22 03:23:05 2010
@@ -774,8 +774,8 @@
     entry.key = file_name;
     entry.key_len = (unsigned int)file_name_len;

-    /* inserted new entry */
     if (1 != hash_op(entry, &found, (bool)(created_via ? 1 : 0))) {
+ /* found existing entry or else didn't but didn't create new one either */
         if (trace_level >= 7) {
             if (found)
logwarn("fid %d: %.*s\n", found->id, found->key_len, found->key);
@@ -783,6 +783,7 @@
         }
         return (found) ? found->id : 0;
     }
+    /* inserted new entry */

     /* if this is a synthetic filename for a string eval
      * ie "(eval 42)[/some/filename.pl:line]"
@@ -2098,8 +2099,17 @@
         GV *called_gv = Nullgv;
subr_entry->called_cv = resolve_sub_to_cv(aTHX_ subr_sv, &called_gv);
         if (called_gv) {
-            subr_entry->called_subpkg_pv = HvNAME(GvSTASH(called_gv));
+            char *p = HvNAME(GvSTASH(called_gv));
+            subr_entry->called_subpkg_pv = p;
             subr_entry->called_subnam_sv = newSVpv(GvNAME(called_gv), 0);
+
+            /* detect calls to POSIX::_exit */
+ if ('P'==*p++ && 'O'==*p++ && 'S'==*p++ && 'I'==*p++ && 'X'==*p++ && 0==*p) {
+                char *s = GvNAME(called_gv);
+ if ('_'==*s++ && 'e'==*s++ && 'x'==*s++ && 'i'==*s++ && 't'==*s++ && 0==*s) {
+                    finish_profile(aTHX);
+                }
+            }
         }
         else {
subr_entry->called_subnam_sv = newSV(0); /* see incr_sub_inclusive_time */
=======================================
--- /trunk/lib/Devel/NYTProf/Core.pm    Tue Mar  9 02:35:10 2010
+++ /trunk/lib/Devel/NYTProf/Core.pm    Thu Apr 22 03:23:05 2010
@@ -24,10 +24,24 @@
         s/\\(.)/$1/g for $opt, $val;

         if ($opt eq 'sigexit') {
+            # Intercept sudden process exit caused by signals
my @sigs = ($val eq '1') ? qw(INT HUP PIPE BUS SEGV) : split(/,/, $val);
             $SIG{uc $_} = sub { DB::finish_profile(); exit 1; } for @sigs;
             next; # no need to tell the XS code about this
         }
+
+        if ($opt eq 'posix_exit') {
+            # Intercept sudden process exit caused by POSIX::_exit() call.
+ # Should only be needed if subs=0. We delay till after profiling
+            # has probably started to minimize the effect on the profile.
+            eval q{ INIT {
+                require POSIX;
+                my $orig = \&POSIX::_exit;
+                local $^W = 0; # avoid sub redef warning
+                *POSIX::_exit = sub { DB::finish_profile(); $orig->(@_) };
+            } 1 } or die if $val;
+            next; # no need to tell the XS code about this
+        }

         DB::set_option($opt, $val);
     }
=======================================
--- /trunk/lib/Devel/NYTProf.pm Sat Apr 17 05:34:28 2010
+++ /trunk/lib/Devel/NYTProf.pm Thu Apr 22 03:23:05 2010
@@ -488,6 +488,16 @@

     sigexit=int,hup

+=head2 posix_exit=1
+
+The NYTProf subroutine profiler normally detects calls to C<POSIX::_exit()>
+(which exits the process without running END blocks) and automatically calls
+C<DB::finish_profile()> for you, so NYTProf 'just works'.
+
+When using the C<subs=0> option to disable the subroutine profiler the
+C<posix_exit> option can be used to tell NYTProf to take other steps to arrange
+for C<DB::finish_profile()> to be called before C<POSIX::_exit()>.
+
 =head2 forkdepth=N

When a perl process that is being profiled executes a fork() the child process

--
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]

Reply via email to