Author: tim.bunce
Date: Sat Jan  3 10:01:41 2009
New Revision: 661

Added:
    trunk/t/test22-strevala.p
    trunk/t/test22-strevala.rdt
Modified:
    trunk/MANIFEST
    trunk/NYTProf.xs

Log:
Implemented normalize_eval_seqn, but left it disabled.
Added test file for 'anon subs defined in string evals'
Added test results file that shows current partial normalization of eval  
sequence numbers.
Pondering best course of action...


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Sat Jan  3 10:01:41 2009
@@ -93,6 +93,8 @@
  t/test21-streval3.p
  t/test21-streval3.rdt
  t/test21-streval3.x
+t/test22-strevala.p
+t/test22-strevala.rdt
  t/test30-fork.0.p
  t/test30-fork.0.rdt
  t/test30-fork.0.x

Modified: trunk/NYTProf.xs
==============================================================================
--- trunk/NYTProf.xs    (original)
+++ trunk/NYTProf.xs    Sat Jan  3 10:01:41 2009
@@ -2763,12 +2763,49 @@


  SV *
-normalize_eval_seqn(SV *sv) {
-    /* look for 'eval ' with instr()
-     * if present then check it's preceeded by '(' or '_' (for '(re_eval')
-     * and followed by one or more digits then ')'
-     * if so then edit sv inplace to replace 'eval <digits>' part  
with 'eval 0'
+normalize_eval_seqn(pTHX_ SV *sv) {
+    /* in-place-edit any eval sequence numbers to 0 */
+    int found = 0;
+    STRLEN len;
+    char *start = SvPV(sv, len);
+    char *src = start;
+    char *dst = start;
+
+    return sv;  /* XXX currently disabled */
+
+    if (len < 5)
+        return sv;
+
+    /* effectively does $sv =~ s/(?<!$assert) \s \d+/eval 0/xg;
+     * where $assert is qr/\((?:re_)?eval/ so it only matches '(eval '  
and '(re_eval '
       */
+    while (*src) {
+        if (*src == ' ' && isdigit(*(src+1)) &&
+            (  (src-start >= 5 && strnEQ(src-5,    "(eval ", 6))
+            || (src-start >= 8 && strnEQ(src-8, "(re_eval ", 8)) )
+        ) {
+            ++found;
+            if (trace_level >= 5)
+                warn("found eval at '%s' in %s", src, start);
+            *dst++ = ' ';
+            *dst++ = '0';
+             src++; /* skip space */
+             src++; /* skip first digit */
+            while (isdigit(*src)) { /* skip any extra digits */
+                ++src;
+            }
+        }
+        else {
+            *dst++ = *src++;
+        }
+    }
+    if (found) {
+        *dst++ = '\0';
+        SvCUR_set(sv, strlen(start));
+        if (trace_level >= 5)
+            warn("edited it to: %s", start);
+    }
+
      return sv;
  }

@@ -3078,7 +3115,7 @@

                  filename_sv = read_str(aTHX_ NULL);
                  if (eval_file_num)
-                    normalize_eval_seqn(filename_sv);
+                    normalize_eval_seqn(aTHX_ filename_sv);

                  if (cb) {
                      PUSHMARK(SP);
@@ -3196,7 +3233,7 @@
                  unsigned int fid        = read_int();
                  unsigned int first_line = read_int();
                  unsigned int last_line  = read_int();
-                SV *subname_sv = normalize_eval_seqn(read_str(aTHX_  
tmp_str_sv));
+                SV *subname_sv = normalize_eval_seqn(aTHX_ read_str(aTHX_  
tmp_str_sv));
                  STRLEN subname_len;
                  char *subname_pv;

@@ -3257,7 +3294,7 @@
                  NV scpu_time       = read_nv();
                  NV reci_time       = (file_minor >= 1) ? read_nv()  : 0;
                  UV rec_depth       = (file_minor >= 1) ? read_int() : 0;
-                subname_sv = normalize_eval_seqn(read_str(aTHX_  
tmp_str_sv));
+                subname_sv = normalize_eval_seqn(aTHX_ read_str(aTHX_  
tmp_str_sv));

                  if (cb) {
                      PUSHMARK(SP);

Added: trunk/t/test22-strevala.p
==============================================================================
--- (empty file)
+++ trunk/t/test22-strevala.p   Sat Jan  3 10:01:41 2009
@@ -0,0 +1,14 @@
+# test merging of anon subs from evals
+
+my $code = 'sub { 1 }';
+
+# call once from particular line
+eval($code)->();
+
+# call twice from the same line
+eval($code)->() for (1,2);
+
+# called from inside a string eval
+eval q{
+    eval($code)->() for (1,2);
+};

Added: trunk/t/test22-strevala.rdt
==============================================================================
--- (empty file)
+++ trunk/t/test22-strevala.rdt Sat Jan  3 10:01:41 2009
@@ -0,0 +1,83 @@
+attribute      application     test22-strevala.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       3       [ 0 1 ]
+fid_block_time 1       6       0       0
+fid_block_time 1       6       1       1
+fid_block_time 1       6       2       1       [ 0 1 ]
+fid_block_time 1       6       2       2       [ 0 1 ]
+fid_block_time 1       9       0       0
+fid_block_time 1       9       1       2
+fid_block_time 1       9       2       1       [ 0 2 ]
+fid_block_time 1       9       2       2       [ 0 2 ]
+fid_block_time 1       12      0       0
+fid_block_time 1       12      1       1
+fid_block_time 1       12      2       1       [ 0 2 ]
+fid_block_time 1       12      2       2       [ 0 4 ]
+fid_fileinfo   1       [ test22-strevala.p   1 2 0 0 ]
+fid_fileinfo   1       call    6       main::__ANON__[(eval 
1)[test22-strevala.p:6]:1] [ 1  
0 0 0 0 0 0 ]
+fid_fileinfo   1       call    9       main::__ANON__[(eval 
2)[test22-strevala.p:9]:1] [ 1  
0 0 0 0 0 0 ]
+fid_fileinfo   1       call    9       main::__ANON__[(eval 
3)[test22-strevala.p:9]:1] [ 1  
0 0 0 0 0 0 ]
+fid_fileinfo   1       eval    6       [ 1 0 ]
+fid_fileinfo   1       eval    9       [ 2 0 ]
+fid_fileinfo   1       eval    12      [ 1 2 ]
+fid_fileinfo   2       [ (eval 0)[test22-strevala.p:6] 1 6 2 2 0 0 ]
+fid_fileinfo   2       sub     main::__ANON__[(eval 0)[test22-strevala.p:6]:1] 
1-1
+fid_fileinfo   3       [ (eval 0)[test22-strevala.p:9] 1 9 3 2 0 0 ]
+fid_fileinfo   3       sub     main::__ANON__[(eval 0)[test22-strevala.p:9]:1] 
and  
main::__ANON__[(eval 3)[test22-strevala.p:9]:1] 1-1
+fid_fileinfo   4       [ (eval 0)[test22-strevala.p:9] 1 9 4 2 0 0 ]
+fid_fileinfo   4       sub     main::__ANON__[(eval 3)[test22-strevala.p:9]:1] 
1-1
+fid_fileinfo   5       [ (eval 0)[test22-strevala.p:12] 1 12 5 2 0 0 ]
+fid_fileinfo   5       call    2       main::__ANON__[(eval 5)[(eval  
4)[test22-strevala.p:12]:2]:1]  [ 1 0 0 0 0 0 0 ]
+fid_fileinfo   5       call    2       main::__ANON__[(eval 6)[(eval  
4)[test22-strevala.p:12]:2]:1]  [ 1 0 0 0 0 0 0 ]
+fid_fileinfo   5       eval    2       [ 2 0 ]
+fid_fileinfo   6       [ (eval 0)[(eval 0)[test22-strevala.p:12]:2] 5 2 6 2 0 
0 ]
+fid_fileinfo   6       sub     main::__ANON__[(eval 5)[(eval  
4)[test22-strevala.p:12]:2]:1]  1-1
+fid_fileinfo   7       [ (eval 0)[(eval 0)[test22-strevala.p:12]:2] 5 2 7 2 0 
0 ]
+fid_fileinfo   7       sub     main::__ANON__[(eval 0)[(eval  
4)[test22-strevala.p:12]:2]:1]  1-1
+fid_line_time  1       3       [ 0 1 ]
+fid_line_time  1       6       0       0
+fid_line_time  1       6       1       1
+fid_line_time  1       6       2       1       [ 0 1 ]
+fid_line_time  1       6       2       2       [ 0 1 ]
+fid_line_time  1       9       0       0
+fid_line_time  1       9       1       2
+fid_line_time  1       9       2       1       [ 0 2 ]
+fid_line_time  1       9       2       2       [ 0 2 ]
+fid_line_time  1       12      0       0
+fid_line_time  1       12      1       1
+fid_line_time  1       12      2       1       [ 0 2 ]
+fid_line_time  1       12      2       2       [ 0 4 ]
+fid_sub_time   1       3       [ 0 1 ]
+fid_sub_time   1       6       0       0
+fid_sub_time   1       6       1       1
+fid_sub_time   1       6       2       1       [ 0 1 ]
+fid_sub_time   1       6       2       2       [ 0 1 ]
+fid_sub_time   1       9       0       0
+fid_sub_time   1       9       1       2
+fid_sub_time   1       9       2       1       [ 0 2 ]
+fid_sub_time   1       9       2       2       [ 0 2 ]
+fid_sub_time   1       12      0       0
+fid_sub_time   1       12      1       1
+fid_sub_time   1       12      2       1       [ 0 2 ]
+fid_sub_time   1       12      2       2       [ 0 4 ]
+profile_modes  fid_block_time  block
+profile_modes  fid_line_time   line
+profile_modes  fid_sub_time    sub
+sub_subinfo    main::__ANON__[(eval 0)[(eval 0)[test22-strevala.p:12]:2]:1]    
[  
7 1 1 2 0 0 0 0 ]
+sub_subinfo    main::__ANON__[(eval 0)[(eval 0)[test22-strevala.p:12]:2]:1]    
 
called_by       5       2       [ 1 0 0 0 0 0 0 ]
+sub_subinfo    main::__ANON__[(eval 0)[test22-strevala.p:6]:1] [ 2 1 1 1 0 0  
0 0 ]
+sub_subinfo    main::__ANON__[(eval 0)[test22-strevala.p:6]:1] called_by       
1       6        
[ 1 0 0 0 0 0 0 ]
+sub_subinfo    main::__ANON__[(eval 0)[test22-strevala.p:9]:1] [ 3 1 1 2 0 0  
0 0 ]
+sub_subinfo    main::__ANON__[(eval 0)[test22-strevala.p:9]:1] called_by       
1       9        
[ 1 0 0 0 0 0 0 ]

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