Revision: 945
Author: tim.bunce
Date: Thu Dec 10 07:29:00 2009
Log: Better handling (ignoring) of threads/multiplicity, (at least good  
enough to pass perls own thread tests).

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

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

=======================================
--- /trunk/NYTProf.xs   Thu Dec 10 06:38:44 2009
+++ /trunk/NYTProf.xs   Thu Dec 10 07:29:00 2009
@@ -1823,9 +1823,13 @@
      char *file;
      long elapsed, overflow;

-    if (!is_profiling || !profile_stmts) {
+    if (!is_profiling || !profile_stmts)
          return;
-    }
+#ifdef MULTIPLICITY
+    if (my_perl != orig_my_perl)
+        return;
+#endif
+
      saved_errno = errno;

      if (usecputime) {
@@ -1947,6 +1951,10 @@

      if (!is_profiling || !out || !profile_stmts)
          return;
+#ifdef MULTIPLICITY
+    if (my_perl != orig_my_perl)
+        return;
+#endif

      /* measure and output end time of previous statement
       * (earlier than it would have been done)
@@ -2749,6 +2757,9 @@
      || (op_type==OP_ENTERSUB && (sub_sv == &PL_sv_yes || sub_sv ==  
DB_INIT_cv || sub_sv == DB_fin_cv))
          /* don't profile other kids of goto */
      || (op_type==OP_GOTO && !(SvROK(sub_sv) && SvTYPE(SvRV(sub_sv)) ==  
SVt_PVCV))
+#ifdef MULTIPLICITY
+    || (my_perl != orig_my_perl)
+#endif
      ) {
          return run_original_op(op_type);
      }
@@ -3029,6 +3040,10 @@
  {
      /* enable the run-time aspects to profiling */
      int prev_is_profiling = is_profiling;
+#ifdef MULTIPLICITY
+    if (my_perl != orig_my_perl)
+        return 0;
+#endif

      if (trace_level)
          logwarn("~ enable_profile (previously %s) to %s\n",
@@ -3063,6 +3078,10 @@
  disable_profile(pTHX)
  {
      int prev_is_profiling = is_profiling;
+#ifdef MULTIPLICITY
+    if (my_perl != orig_my_perl)
+        return 0;
+#endif
      if (is_profiling) {
          if (opt_use_db_sub)
              sv_setiv(PL_DBsingle, 0);
@@ -3081,6 +3100,10 @@
  finish_profile(pTHX)
  {
      int saved_errno = errno;
+#ifdef MULTIPLICITY
+    if (my_perl != orig_my_perl)
+        return;
+#endif

      if (trace_level >= 1)
          logwarn("~ finish_profile (overhead %"NVff"s, is_profiling %d)\n",
@@ -4768,13 +4791,6 @@
  void
  _INIT()
      CODE:
-#ifdef MULTIPLICITY
-    if (orig_my_perl != my_perl) {
-        logwarn("NYTProf: threads/multiplicity not supported, giving  
up!\n");
-        disable_profile(aTHX);
-        XSRETURN_UNDEF;
-    }
-#endif
      if (profile_start == NYTP_START_INIT)  {
          enable_profile(aTHX_ NULL);
      }
=======================================
--- /trunk/lib/Devel/NYTProf.pm Thu Dec 10 06:36:30 2009
+++ /trunk/lib/Devel/NYTProf.pm Thu Dec 10 07:29:00 2009
@@ -35,6 +35,8 @@
          : \&DB_profiler;
  }
  sub sub { die "DB::sub" }              # needed for perl <5.8.7  
(<p...@24265)
+
+sub CLONE { DB::disable_profiler }

  init_profiler();                       # provides true return value for  
module

@@ -588,7 +590,9 @@

  C<Devel::NYTProf> is not currently thread safe or multiplicity safe.
  If you'd be interested in helping to fix that then please get in
-touch with us.
+touch with us. Meanwhile, profiling is disabled when a thread is created,  
and
+NYTProf tries to ignore any activity from perl interpreters other than the
+first one that loaded it.

  =head2 For perl < 5.8.8 it may change what caller() returns

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