Revision: 1233
Author: tim.bunce
Date: Wed May 26 06:16:12 2010
Log: Avoid segv with mod_perl2. Not sure of root cause but removing the needless END
in Devel/NYTProf/Apache.pm.
Vivify PL_*av before use.
Added code to call finish_profile immediarely from CHECK/END if desired.
No longer uses old _finish alias for finish_profile in Devel/NYTProf/Apache.pm.

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

Modified:
 /trunk/NYTProf.xs
 /trunk/lib/Devel/NYTProf/Apache.pm

=======================================
--- /trunk/NYTProf.xs   Mon May 24 07:37:09 2010
+++ /trunk/NYTProf.xs   Wed May 26 06:16:12 2010
@@ -4941,7 +4941,9 @@
     else if (profile_start == NYTP_START_END) {
SV *enable_profile_sv = (SV *)get_cv("DB::enable_profile", GV_ADDWARN);
         if (trace_level >= 2)
-            logwarn("~ enable_profile defered until END\n");
+            logwarn("~ enable_profile deferred until END\n");
+        if (!PL_endav)
+            PL_endav = newAV();
         av_unshift(PL_endav, 1);  /* we want to be first */
         av_store(PL_endav, 0, SvREFCNT_inc(enable_profile_sv));
     }
@@ -4954,13 +4956,20 @@
         _CHECK = 1
     CODE:
/* we want to END { finish_profile() } but we want it to be the last END - * block run so we don't push it into PL_endav until END phase has started, + * block run, so we don't push it into PL_endav until END phase has started, * so it's likely to be the last thing run. Do this once, else we could end
      * up in an infinite loop arms race with something else trying the same
      * strategy.
      */
-    av_push((ix == 1 ? PL_checkav : PL_endav),
-            (SV *)get_cv("DB::finish_profile", GV_ADDWARN));
+    CV *finish_profile_cv = get_cv("DB::finish_profile", GV_ADDWARN);
+    if (1) {    /* defer */
+        if (!PL_checkav) PL_checkav = newAV();
+        if (!PL_endav)   PL_endav   = newAV();
+ av_push((ix == 1 ? PL_checkav : PL_endav), SvREFCNT_inc(finish_profile_cv));
+    }
+    else {      /* immediate */
+        call_sv((SV *)finish_profile_cv, G_VOID);
+    }
     if (trace_level >= 2)
         logwarn("~ %s done\n", ix == 1 ? "CHECK" : "END");

=======================================
--- /trunk/lib/Devel/NYTProf/Apache.pm  Tue May 25 14:12:31 2010
+++ /trunk/lib/Devel/NYTProf/Apache.pm  Wed May 26 06:16:12 2010
@@ -53,7 +53,7 @@

 sub child_exit {
     trace("child_exit(@_)") if TRACE;
-    DB::_finish();
+    DB::finish_profile();
 }

 # arrange for the profile to be enabled in each child
@@ -64,8 +64,9 @@
     # and for normal fork detection to detect the new child.
     # We just need to be sure the profile is finished properly
     # and an END block works well for that (if loaded right, see docs)
-    trace("adding child_exit hook") if TRACE;
-    eval q{ END { warn "END"; sleep 2; child_exit('END') } 1 } or die;
+    # We rely on NYTProf's own END block to finish the profile.
+    #trace("adding child_exit hook") if TRACE;
+    #eval q{ END { child_exit('END') } 1 } or die;
 }
 else {
     # the simple steps for mod_perl2 above might also be fine for mod_perl1

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