Revision: 943 Author: tim.bunce Date: Thu Dec 10 06:36:30 2009 Log: Added nameevals=0 and nameanonsubs=0 to make NYTProf less visible to code that may assume the default perl naming behaviour. (Such as perl's own test suite.) Added rough stab at detecting threading/multiplicity.
http://code.google.com/p/perl-devel-nytprof/source/detail?r=943 Modified: /trunk/Changes /trunk/NYTProf.xs /trunk/lib/Devel/NYTProf.pm ======================================= --- /trunk/Changes Mon Dec 7 14:33:41 2009 +++ /trunk/Changes Thu Dec 10 06:36:30 2009 @@ -43,6 +43,9 @@ Added forkdepth=N option to enable profiling to be turned off after N generations of fork(). + Added nameevals=0 and nameanonsubs=0 to make NYTProf less visible + to code that may assume the default perl naming behaviour. + Added initial support for profiling PostgreSQL PL/Perl code via Devel::NYTProf::PgPLPerl module. ======================================= --- /trunk/NYTProf.xs Thu Dec 10 04:10:52 2009 +++ /trunk/NYTProf.xs Thu Dec 10 06:36:30 2009 @@ -173,6 +173,11 @@ static int next_fid = 1; /* 0 is reserved */ +/* we're not thread-safe (or even multiplicity safe) yet, so detect and bail */ +#ifdef MULTIPLICITY +static PerlInterpreter *orig_my_perl; +#endif + typedef struct hash_entry { unsigned int id; @@ -283,7 +288,11 @@ #define profile_forkdepth options[12].option_value { "forkdepth", -1 }, /* how many generations of kids to profile */ #define opt_perldb options[13].option_value - { "perldb", 0 } /* force certain PL_perldb value */ + { "perldb", 0 }, /* force certain PL_perldb value */ +#define opt_nameevals options[14].option_value + { "nameevals", 1 }, /* change $^P 0x100 bit */ +#define opt_nameanonsubs options[15].option_value + { "nameanonsubs", 1 } /* change $^P 0x200 bit */ }; /* time tracking */ @@ -2026,7 +2035,8 @@ bool found = FALSE; do { if (strEQ(option, opt_p->option_name)) { - opt_p->option_value = atoi(value); + opt_p->option_value = (strnEQ(value,"0x",2)) + ? strtol(value, NULL, 16) : atoi(value); found = TRUE; break; } @@ -2542,7 +2552,7 @@ if (subr_entry_ix <= prev_subr_entry_ix) { /* one cause of this is running NYTProf with threads */ - logwarn("NYTProf panic: stack is confused!\n"); + logwarn("NYTProf panic: stack is confused, giving up!\n"); /* limit the damage */ disable_profile(aTHX); subr_entry->already_counted++; @@ -3102,6 +3112,15 @@ SV **svp; #endif +#ifdef MULTIPLICITY + if (!orig_my_perl) + orig_my_perl = my_perl; + else if (orig_my_perl != my_perl) { + logwarn("NYTProf: threads/multiplicity not supported!\n"); + return 0; + } +#endif + /* Save the process id early. We monitor it to detect forks */ last_pid = getpid(); ticks_per_sec = (usecputime) ? CLOCKS_PER_SEC : CLOCKS_PER_TICK; @@ -3121,6 +3140,11 @@ /* ask perl to keep the source lines so we can copy them */ PL_perldb |= PERLDBf_SAVESRC | PERLDBf_SAVESRC_NOSUBS; } + + if (!opt_nameevals) + PL_perldb &= PERLDBf_NAMEEVAL; + if (!opt_nameanonsubs) + PL_perldb &= PERLDBf_NAMEANON; if (opt_perldb) /* force a PL_perldb value - for testing only, not documented */ PL_perldb = opt_perldb; @@ -4744,6 +4768,13 @@ 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 Tue Nov 17 13:03:49 2009 +++ /trunk/lib/Devel/NYTProf.pm Thu Dec 10 06:36:30 2009 @@ -490,6 +490,36 @@ If forkdepth is -1 (the default) then there's no limit on the number of generations of children that are profiled. +=head2 nameevals=0 + +The 'file name' of a string eval is normally a string like "C<(eval N)>", where +C<N> is a sequence number. By default NYTProf asks perl to give evals more +informative names like "C<(eval N)[file:line]>", where C<file> and C<line> are +the file and line number where the string C<eval> was executed. + +The C<nameevals=0> option can be used to disable the more informative names and +return to the default behaviour. This may be need in rare cases where the +application code is sensitive to the name given to a C<eval>. (The most common +case in when running test suites undef NYTProf.) + +The downside is that the NYTProf reporting tools are less useful and may get +confused if this option is used. + +=head2 nameanonsubs=0 + +The name of a anonymous subroutine is normally "C<__ANON__>". By default +NYTProf asks perl to give anonymous subroutines more informative names like +"C<__ANON__[file:line]>", where C<file> and C<line> are the file and line +number where the anonymous subroutine was defined. + +The C<nameanonsubs=0> option can be used to disable the more informative names +and return to the default behaviour. This may be need in rare cases where the +application code is sensitive to the name given to a anonymous subroutines. +(The most common case in when running test suites undef NYTProf.) + +The downside is that the NYTProf reporting tools are less useful and may get +confused if this option is used. + =head1 RUN-TIME CONTROL OF PROFILING You can profile only parts of an application by calling DB::disable_profile() -- 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]
