Author: tim.bunce
Date: Wed Jun  3 04:23:31 2009
New Revision: 750

Added:
    trunk/xt/test23-strevalxs.p
    trunk/xt/test23-strevalxs.rdt
    trunk/xt/test23-strevalxs.t
Modified:
    trunk/MANIFEST
    trunk/NYTProf.xs
    trunk/lib/Devel/NYTProf/FileInfo.pm
    trunk/lib/Devel/NYTProf/Test.pm

Log:
Added detection of file names like "(eval 1)" that don't have the expected
filename details added (they should look like "(eval 1)[/file:line]")
They're treated as if they were "(eval 1)[/unknown-eval-invoker:1]"
Added a new NYTP_FIDf_IS_FAKE flag to indicate /unknown-eval-invoker is  
fake.
Modified $fi->srclines_array() to return fake source if NYTP_FIDf_IS_FAKE  
set.
Added a test but it doesn't exercise the case as it's not really embedded
(at least I assume that's the reason).
Resorted MANIFEST and removed duplicate entry.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Wed Jun  3 04:23:31 2009
@@ -8,8 +8,8 @@
  NYTProf.xs
  README
  benchmark.pl
-bin/nytprofcsv
  bin/nytprofcg
+bin/nytprofcsv
  bin/nytprofhtml
  demo/README
  demo/demo-code.pl
@@ -17,12 +17,12 @@
  demo/exclusive-sub-time.pl
  lib/Devel/NYTProf.pm
  lib/Devel/NYTProf/Apache.pm
-lib/Devel/NYTProf/Core.pm
  lib/Devel/NYTProf/Constants.pm
+lib/Devel/NYTProf/Core.pm
  lib/Devel/NYTProf/Data.pm
  lib/Devel/NYTProf/FileInfo.pm
-lib/Devel/NYTProf/Reader.pm
  lib/Devel/NYTProf/ReadStream.pm
+lib/Devel/NYTProf/Reader.pm
  lib/Devel/NYTProf/SubInfo.pm
  lib/Devel/NYTProf/Test.pm
  lib/Devel/NYTProf/Util.pm
@@ -113,7 +113,6 @@
  t/test21-streval3.x
  t/test22-strevala.p
  t/test22-strevala.rdt
-t/test22-strevala.p
  t/test22-strevala.t
  t/test30-fork-0.p
  t/test30-fork-0.rdt

Modified: trunk/NYTProf.xs
==============================================================================
--- trunk/NYTProf.xs    (original)
+++ trunk/NYTProf.xs    Wed Jun  3 04:23:31 2009
@@ -85,7 +85,8 @@
  #define NYTP_FIDf_IS_AUTOSPLIT   0x0008 /* fid is an autosplit (see  
AutoLoader) */
  #define NYTP_FIDf_HAS_SRC        0x0010 /* src is available to profiler */
  #define NYTP_FIDf_SAVE_SRC       0x0020 /* src will be saved by profiler,  
if NYTP_FIDf_HAS_SRC also set */
-#define NYTP_FIDf_IS_ALIAS       0x0040 /* fid is cone of the 'parent' fid  
it was autosplit from */
+#define NYTP_FIDf_IS_ALIAS       0x0040 /* fid is clone of the 'parent'  
fid it was autosplit from */
+#define NYTP_FIDf_IS_FAKE        0x0080 /* eg dummy caller of a string  
eval that doesn't have a filename */

  #define NYTP_TAG_ATTRIBUTE       ':'    /* :name=value\n */
  #define NYTP_TAG_COMMENT         '#'    /* till newline */
@@ -1191,31 +1192,42 @@
          return (found) ? found->id : 0;
      }

-    /* if this is a synthetic filename for an 'eval'
+    /* if this is a synthetic filename for a string eval
       * ie "(eval 42)[/some/filename.pl:line]"
-     * then ensure we've already generated an id for the underlying
-     * filename
+     * then ensure we've already generated a fid for the underlying
+     * filename, and associate that fid with this eval fid
       */
-    if ('(' == file_name[0] && ']' == file_name[file_name_len-1]) {
-        char *start = strchr(file_name, '[');
-        const char *colon = ":";
-        /* can't use strchr here (not nul terminated) so use rninstr */
-        char *end = rninstr(file_name, file_name+file_name_len-1, colon,  
colon+1);
-
-        if (!start || !end || start > end) {    /* should never happen */
-            warn("NYTProf unsupported filename syntax '%s'", file_name);
-            return 0;
+    if ('(' == file_name[0]) {
+        if (']' == file_name[file_name_len-1]) {
+            char *start = strchr(file_name, '[');
+            const char *colon = ":";
+            /* can't use strchr here (not nul terminated) so use rninstr */
+            char *end = rninstr(file_name, file_name+file_name_len-1,  
colon, colon+1);
+
+            if (!start || !end || start > end) {    /* should never happen  
*/
+                warn("NYTProf unsupported filename syntax '%s'",  
file_name);
+                return 0;
+            }
+            ++start;                              /* move past [ */
+            /* recurse */
+            found->eval_fid = get_file_id(aTHX_ start, end - start,  
created_via);
+            found->eval_line_num = atoi(end+1);
+        }
+        else if (strnEQ(file_name, "(eval ", 6)) {
+            /* strange eval that doesn't have a filename associated */
+            /* seen in mod_perl, possibly from eval_sv(sv) api call */
+            char *eval_file = "/unknown-eval-invoker";
+            found->eval_fid = get_file_id(aTHX_ eval_file,  
strlen(eval_file),
+                NYTP_FIDf_IS_FAKE | created_via
+            );
+            found->eval_line_num = 1;
          }
-        ++start;                              /* move past [ */
-        /* recurse */
-        found->eval_fid = get_file_id(aTHX_ start, end - start,  
created_via);
-        found->eval_line_num = atoi(end+1);
      }

      /* is the file is an autosplit, e.g., has a file_name like
       * "../../lib/POSIX.pm (autosplit into ../../lib/auto/POSIX/errno.al)"
       */
-    if (   ')' == file_name[file_name_len-1] && strstr(file_name, "  
(autosplit ")) {
+    if ( ')' == file_name[file_name_len-1] && strstr(file_name, "  
(autosplit ")) {
          found->fid_flags |= NYTP_FIDf_IS_AUTOSPLIT;
      }

@@ -3852,9 +3864,10 @@
      newCONSTSUB(stash, "NYTP_FIDf_VIA_STMT",      
newSViv(NYTP_FIDf_VIA_STMT));
      newCONSTSUB(stash, "NYTP_FIDf_VIA_SUB",       
newSViv(NYTP_FIDf_VIA_SUB));
      newCONSTSUB(stash, "NYTP_FIDf_IS_AUTOSPLIT",  
newSViv(NYTP_FIDf_IS_AUTOSPLIT));
-    newCONSTSUB(stash, "NYTP_FIDf_IS_ALIAS",      
newSViv(NYTP_FIDf_IS_ALIAS));
      newCONSTSUB(stash, "NYTP_FIDf_HAS_SRC",       
newSViv(NYTP_FIDf_HAS_SRC));
      newCONSTSUB(stash, "NYTP_FIDf_SAVE_SRC",      
newSViv(NYTP_FIDf_SAVE_SRC));
+    newCONSTSUB(stash, "NYTP_FIDf_IS_ALIAS",      
newSViv(NYTP_FIDf_IS_ALIAS));
+    newCONSTSUB(stash, "NYTP_FIDf_IS_FAKE",       
newSViv(NYTP_FIDf_IS_FAKE));
      /* NYTP_FIDi_* */
      newCONSTSUB(stash, "NYTP_FIDi_FILENAME",  newSViv(NYTP_FIDi_FILENAME));
      newCONSTSUB(stash, "NYTP_FIDi_EVAL_FID",  newSViv(NYTP_FIDi_EVAL_FID));
@@ -3901,6 +3914,18 @@
  example_xsub(...)
      CODE:
      PERL_UNUSED_VAR(items);
+
+void
+example_xsub_eval(...)
+    CODE:
+    PERL_UNUSED_VAR(items);
+    /* to enable testing of string evals in embedded environments
+     * where there's no caller file information available.
+     * Only it doesn't actually do that because perl knows
+     * what it's executing at the time eval_pv() gets called.
+     * We need a better test, closer to true embedded.
+     */
+    eval_pv("Devel::NYTProf::Test::example_xsub()", 1);


  MODULE = Devel::NYTProf     PACKAGE = DB

Modified: trunk/lib/Devel/NYTProf/FileInfo.pm
==============================================================================
--- trunk/lib/Devel/NYTProf/FileInfo.pm (original)
+++ trunk/lib/Devel/NYTProf/FileInfo.pm Wed Jun  3 04:23:31 2009
@@ -5,7 +5,7 @@
  use Devel::NYTProf::Util qw(strip_prefix_from_paths);

  use Devel::NYTProf::Constants qw(
-    NYTP_FIDf_HAS_SRC NYTP_FIDf_SAVE_SRC
+    NYTP_FIDf_HAS_SRC NYTP_FIDf_SAVE_SRC NYTP_FIDf_IS_FAKE

      NYTP_FIDi_FILENAME NYTP_FIDi_EVAL_FID NYTP_FIDi_EVAL_LINE NYTP_FIDi_FID
      NYTP_FIDi_FLAGS NYTP_FIDi_FILESIZE NYTP_FIDi_FILEMTIME  
NYTP_FIDi_PROFILE
@@ -164,9 +164,15 @@
      }

      my $filename = $self->abs_filename;
-    open my $fh, "<", $filename
-        or return undef;
-    return [ <$fh> ];
+    if (open my $fh, "<", $filename) {
+        return [ <$fh> ];
+    }
+
+    if ($self->flags & NYTP_FIDf_IS_FAKE) {
+        return [ "# NYTP_FIDf_IS_FAKE - e.g., unknown caller of an  
eval.\n" ];
+    }
+
+    return undef;
  }



Modified: trunk/lib/Devel/NYTProf/Test.pm
==============================================================================
--- trunk/lib/Devel/NYTProf/Test.pm     (original)
+++ trunk/lib/Devel/NYTProf/Test.pm     Wed Jun  3 04:23:31 2009
@@ -8,7 +8,7 @@
  require Exporter;
  our @ISA = qw(Exporter);

-our @EXPORT_OK = qw(example_xsub example_sub);
+our @EXPORT_OK = qw(example_sub example_xsub example_xsub_eval);

  sub example_sub { }


Added: trunk/xt/test23-strevalxs.p
==============================================================================
--- (empty file)
+++ trunk/xt/test23-strevalxs.p Wed Jun  3 04:23:31 2009
@@ -0,0 +1,4 @@
+# test string eval made from embedded environment
+use Devel::NYTProf::Test qw(example_xsub_eval);
+
+example_xsub_eval(); # calls eval_pv() perlapi

Added: trunk/xt/test23-strevalxs.rdt
==============================================================================
--- (empty file)
+++ trunk/xt/test23-strevalxs.rdt       Wed Jun  3 04:23:31 2009
@@ -0,0 +1,42 @@
+attribute      application     test23-strevalxs.p
+attribute      basetime        0
+attribute      clock_id        0
+attribute      nv_size 0
+attribute      perl_version    0
+attribute      profiler_duration       0
+attribute      profiler_end_time       0
+attribute      profiler_start_time     0
+attribute      ticks_per_sec   0
+attribute      total_stmts_discounted  0
+attribute      total_stmts_duration    0
+attribute      total_stmts_measured    0
+attribute      total_sub_calls 0
+attribute      xs_version      0
+fid_block_time 1       4       0       0
+fid_block_time 1       4       1       1
+fid_block_time 1       4       2       1       [ 0 1 ]
+fid_fileinfo   1       [ test23-strevalxs.p   1 2 0 0 ]
+fid_fileinfo   1       sub     main::BEGIN     2-2
+fid_fileinfo   1       call    4       Devel::NYTProf::Test::example_xsub_eval 
[ 1 0 0 0 0  
0 0 ]
+fid_fileinfo   1       eval    4       [ 1 0 ]
+fid_fileinfo   2       [ (eval 0)[test23-strevalxs.p:4] 1 4 2 2 0 0 ]
+fid_fileinfo   2       call    1       Devel::NYTProf::Test::example_xsub      
[ 1 0 0 0 0 0 0 ]
+fid_fileinfo   3       [ Devel/NYTProf/Test.pm   3 4 0 0 ]
+fid_fileinfo   3       sub     Devel::NYTProf::Test::example_sub       13-13
+fid_fileinfo   3       sub     Devel::NYTProf::Test::example_xsub      0-0
+fid_fileinfo   3       sub     Devel::NYTProf::Test::example_xsub_eval 0-0
+fid_line_time  1       4       0       0
+fid_line_time  1       4       1       1
+fid_line_time  1       4       2       1       [ 0 1 ]
+fid_sub_time   1       4       0       0
+fid_sub_time   1       4       1       1
+fid_sub_time   1       4       2       1       [ 0 1 ]
+profile_modes  fid_block_time  block
+profile_modes  fid_line_time   line
+profile_modes  fid_sub_time    sub
+sub_subinfo    Devel::NYTProf::Test::example_sub       [ 3 13 13 0 0 0 0 0 ]
+sub_subinfo    Devel::NYTProf::Test::example_xsub      [ 3 0 0 1 0 0 0 0 ]
+sub_subinfo    Devel::NYTProf::Test::example_xsub      called_by       2       
1       [ 1 0 0 0 0 0  
0 ]
+sub_subinfo    Devel::NYTProf::Test::example_xsub_eval [ 3 0 0 1 0 0 0 0 ]
+sub_subinfo    Devel::NYTProf::Test::example_xsub_eval called_by       1       
4       [ 1 0 0  
0 0 0 0 ]
+sub_subinfo    main::BEGIN     [ 1 2 2 0 0 0 0 0 ]

Added: trunk/xt/test23-strevalxs.t
==============================================================================
--- (empty file)
+++ trunk/xt/test23-strevalxs.t Wed Jun  3 04:23:31 2009
@@ -0,0 +1,6 @@
+use strict;
+use Test::More;
+use lib qw(t/lib);
+use NYTProfTest;
+
+run_test_group;

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