Revision: 1327
Author: [email protected]
Date: Thu Jul  8 04:14:31 2010
Log: Add clear NOTE to the report for the sawampersand_fid explaining the issue. Higlight appropriate file on index page even if sawampersand_fid is an eval fid.

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

Modified:
 /trunk/bin/nytprofhtml
 /trunk/demo/demo-code.pl
 /trunk/lib/Devel/NYTProf/Reader.pm

=======================================
--- /trunk/bin/nytprofhtml      Thu Jul  8 02:11:40 2010
+++ /trunk/bin/nytprofhtml      Thu Jul  8 04:14:31 2010
@@ -184,11 +184,36 @@

 $reporter->set_param(
     'taintmsg',
-    qq{<div class="warn_title">WARNING!</div>\n
+    qq{<br /><div class="warn_title">WARNING!</div>\n
 <div class="warn">The source file used to generate this report was modified
 after the profiler data was generated.
The data might be out of sync with the modified source code so you should regenerate it.
-Meanwhile, the data on this page might not make much sense!</div><br />\n}
+Meanwhile, the data on this page might not make much sense!</div>\n}
+);
+
+$reporter->set_param(
+    'sawampersand',
+    sub {
+        my ($profile, $fi) = @_;
+        my $line = $profile->{attribute}{sawampersand_line};
+        return qq{<br /><div class="warn_title">NOTE!</div>\n
+<div class="warn"><p>While profiling this file Perl noted the use of one or more special +variables that impact the performance of <i>all</i> regular expressions in the program.</p>
+
+<p>Use of the "<tt>\$`</tt>", "<tt>\$&</tt>", and "<tt>\$'</tt>" variables should be replaced with faster alternatives. +See the WARNING at the end of the <a href="http://perldoc.perl.org/perlre.html#Capture-buffers";>
+Capture Buffers section of the perlre documentation</a>.</p>
+
+<p>The use is detected by perl at compile time but by NYTProf during execution.
+NYTProf first noted it when executing <a href="#$line">line $line</a>.
+That was probably the first statement executed by the program after perl
+compiled the code containing the variables.
+If the variables can't be found by studying the source code, try using the
+<a href="http://search.cpan.org/perldoc?Devel::FindAmpersand";>Devel::FindAmpersand</a>
+module.</p>
+
+</div>\n}
+    }
 );

 $reporter->set_param(
@@ -1271,7 +1296,8 @@
     my $allTimes = $profile->{attribute}{total_stmts_duration};
     my $allCalls = $profile->{attribute}{total_stmts_measured}
                  - $profile->{attribute}{total_stmts_discounted};
-    my $sawampersand_fid = $profile->{attribute}{sawampersand_fid};
+    # file in which sawampersand was noted during profiling
+ my $sawampersand_fi = $profile->fileinfo_of($profile->{attribute}{sawampersand_fid}, 1);

     my (@t_stmt_exec, @t_stmt_time);
     my @fis = $profile->noneval_fileinfos;
@@ -1299,8 +1325,12 @@
             $eval_stmts = sum(map { $_->sum_of_stmts_count } @has_evals);
             $eval_time  = sum(map { $_->sum_of_stmts_time  } @has_evals);
         }
-        if ($fid == $sawampersand_fid) {
- push @extra, "variables that impact regex performance for whole application seen here"; + # is this file one where we sawampersand (or contains an eval that is)? + if ($sawampersand_fi && $fi == ($sawampersand_fi->outer || $sawampersand_fi)) {
+            my $in_eval = ($fi == $sawampersand_fi)
+                ? 'here'
+ : sprintf q{<a %s>in eval here</a>}, $reporter->href_for_file($sawampersand_fi, undef, 'line'); + push @extra, sprintf qq{variables that impact regex performance for whole application seen $in_eval},
             $css_class = "warn $css_class";
         }

=======================================
--- /trunk/demo/demo-code.pl    Wed Jul  7 10:05:28 2010
+++ /trunk/demo/demo-code.pl    Thu Jul  8 04:14:31 2010
@@ -1,4 +1,5 @@
 use strict 0.1;   # use UNIVERSAL::VERSION
+use English;      # demo detection of $& et al
 use Benchmark;
 use File::Find;

@@ -29,9 +30,6 @@
# assigned to the previous statement, i.e., the last statement executed in foo()!
     foo() && 'aaaaaaaaaaa' =~ /((a{0,5}){0,5})*[c]/;

-    # $&, $' and $` cause global slowdown in regex performance
-    my $dummy = $&;
-
     1;
 }

=======================================
--- /trunk/lib/Devel/NYTProf/Reader.pm  Sat Jun 19 11:56:26 2010
+++ /trunk/lib/Devel/NYTProf/Reader.pm  Thu Jul  8 04:14:31 2010
@@ -74,6 +74,10 @@
         taintmsg => "# WARNING!\n"
. "# The source file used in generating this report has been modified\n" . "# since generating the profiler database. It might be out of sync\n",
+        sawampersand => "# NOTE!\n"
+ . "# This file uses special regexp match variables that impact the performance\n"
+            . "# of all regular expression in the program!\n"
+ . "# See WARNING in http://perldoc.perl.org/perlre.html#Capture-buffers\n";,
     };

     bless($self, $class);
@@ -348,6 +352,10 @@
         print OUT $self->get_param('taintmsg', [$profile, $fi])
if !$fi->has_savesrc and $self->file_has_been_modified($filestr);

+        print OUT $self->get_param('sawampersand', [$profile, $fi])
+            if $profile->{attribute}{sawampersand_fid}
+            && $fi->fid == $profile->{attribute}{sawampersand_fid};
+
         print OUT $self->get_param('merged_fids', [$profile, $fi])
             if $fi->meta->{merged_fids};

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