Author: tim.bunce
Date: Tue Nov 18 14:20:57 2008
New Revision: 606

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

Log:
Added optimize=0 option to disable the perl optimizer
so you can see more accurate statement execution counts
for some kinds of constructs.


Modified: trunk/Changes
==============================================================================
--- trunk/Changes       (original)
+++ trunk/Changes       Tue Nov 18 14:20:57 2008
@@ -6,6 +6,10 @@

  =head2 Changes in Devel::NYTProf 2.08

+  Added optimize=0 option to disable the perl optimizer
+    so you can see more accurate statement execution counts
+    for some kinds of constructs.
+
    Dramatically increased performance of nytprofhtml
      relative to the 2.07 version.


Modified: trunk/NYTProf.xs
==============================================================================
--- trunk/NYTProf.xs    (original)
+++ trunk/NYTProf.xs    Tue Nov 18 14:20:57 2008
@@ -65,6 +65,7 @@
  #define NYTP_START_END           4

  #define NYTP_OPTf_ADDPID         0x0001 /* append .pid to output filename  
*/
+#define NYTP_OPTf_OPTIMIZE       0x0002 /* affect $^P & 0x04 */

  #define NYTP_FIDf_IS_PMC         0x0001 /* .pm probably really loaded  
as .pmc */
  #define NYTP_FIDf_VIA_STMT       0x0002 /* fid first seen by stmt profiler  
*/
@@ -168,7 +169,7 @@

  /* options and overrides */
  static char PROF_output_file[MAXPATHLEN+1] = "nytprof.out";
-static unsigned int profile_opts = 0;
+static unsigned int profile_opts = NYTP_OPTf_OPTIMIZE;
  static int profile_start = NYTP_START_BEGIN;      /* when to start  
profiling */
  static int profile_zero = 0;                      /* don't do timing, all  
times are zero */

@@ -1741,6 +1742,11 @@
              ? profile_opts |  NYTP_OPTf_ADDPID
              : profile_opts & ~NYTP_OPTf_ADDPID;
      }
+    else if (strEQ(option, "optimize") || strEQ(option, "optimise")) {
+        profile_opts = (atoi(value))
+            ? profile_opts |  NYTP_OPTf_OPTIMIZE
+            : profile_opts & ~NYTP_OPTf_OPTIMIZE;
+    }
      else {
        struct NYTP_int_options_t *opt_p = options;
        const struct NYTP_int_options_t *const opt_end
@@ -2210,6 +2216,7 @@
  static int
  enable_profile(pTHX)
  {
+    /* enable the run-time aspects to profiling */
      int prev_is_profiling = is_profiling;
      if (!out) {
          warn("enable_profile: NYTProf not active");
@@ -2314,6 +2321,10 @@
          profile_clock = -1;
      }
  #endif
+
+    if (profile_opts & NYTP_OPTf_OPTIMIZE)
+         PL_perldb &= ~PERLDBf_NOOPT;
+    else PL_perldb |=  PERLDBf_NOOPT;

      if (trace_level)
          warn("NYTProf init pid %d, clock %d%s\n", last_pid, profile_clock,

Modified: trunk/lib/Devel/NYTProf.pm
==============================================================================
--- trunk/lib/Devel/NYTProf.pm  (original)
+++ trunk/lib/Devel/NYTProf.pm  Tue Nov 18 14:20:57 2008
@@ -283,6 +283,35 @@
  The start=no option is handy if you want to explicitly control profiling
  by calling DB::enable_profile() and DB::disable_profile() yourself.

+=head2 optimize=0
+
+Disable the perl optimizer.
+
+By default NYTProf leaves perl's optimizer enabled.  That gives you more
+accurate profile timing overall, but can lead to I<odd> statement counts  
for
+individual sets of lines. That's because the perl's peephole optimizer has
+effectively rewritten the statements but you can't see what the rewritten
+version looks like.
+
+For example:
+
+  1     if (...) {
+  2         return;
+  3     }
+
+may be rewritten as
+
+  1    return if (...)
+
+so the profile won't show a statement count for line 2 in your source code
+because the C<return> was merged into the C<if> statement on the  
preceeding line.
+
+Using the C<optimize=0> option disables the optimizer so you'll get lower
+overall performance but more accurately assigned statement counts.
+
+If you find any other examples of the effect of optimizer on NYTProf output
+(other than performance, obviously) please let us know.
+
  =head2 subs=0

  Set to 0 to disable the collection of subroutine caller and timing details.

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