Revision: 887 Author: tim.bunce Date: Wed Oct 28 05:00:38 2009 Log: Moved some $^P () settings into init_profiler. Renamed use_db_sub to opt_use_db_sub (will rename others later)
http://code.google.com/p/perl-devel-nytprof/source/detail?r=887 Modified: /trunk/NYTProf.xs /trunk/lib/Devel/NYTProf.pm ======================================= --- /trunk/NYTProf.xs Wed Oct 28 03:40:28 2009 +++ /trunk/NYTProf.xs Wed Oct 28 05:00:38 2009 @@ -65,7 +65,7 @@ * so we'd have to crawl the stack to find the right cop. However, for some * reason that I don't pretend to understand the following expression works: */ -#define PL_curcop_nytprof (use_db_sub ? ((cxstack + cxstack_ix)->blk_oldcop) : PL_curcop) +#define PL_curcop_nytprof (opt_use_db_sub ? ((cxstack + cxstack_ix)->blk_oldcop) : PL_curcop) #else #define PL_curcop_nytprof PL_curcop #endif @@ -250,7 +250,7 @@ { "expand", 0 }, #define trace_level options[5].option_value { "trace", 0 }, -#define use_db_sub options[6].option_value +#define opt_use_db_sub options[6].option_value { "use_db_sub", 0 }, #define compression_level options[7].option_value { "compress", default_compression_level }, @@ -2897,7 +2897,7 @@ last_executed_fileptr = NULL; /* discard cached OutCopFILE */ is_profiling = 1; /* enable NYTProf profilers */ - if (use_db_sub) /* set PL_DBsingle if required */ + if (opt_use_db_sub) /* set PL_DBsingle if required */ sv_setiv(PL_DBsingle, 1); /* discard time spent since profiler was disabled */ @@ -2912,7 +2912,7 @@ { int prev_is_profiling = is_profiling; if (is_profiling) { - if (use_db_sub) + if (opt_use_db_sub) sv_setiv(PL_DBsingle, 0); if (out) NYTP_flush(out); @@ -2935,7 +2935,7 @@ last_pid, getpid(), cumulative_overhead_ticks/ticks_per_sec, is_profiling); /* write data for final statement, unless DB_leave has already */ - if (!profile_leave || use_db_sub) + if (!profile_leave || opt_use_db_sub) DB_stmt(aTHX_ NULL, NULL); disable_profile(aTHX); @@ -2952,7 +2952,7 @@ } -/* Initial setup */ +/* Initial setup - should only be called once */ static int init_profiler(pTHX) { @@ -2966,6 +2966,11 @@ DB_INIT_cv = (SV*)GvCV(gv_fetchpv("DB::_INIT", FALSE, SVt_PVCV)); DB_fin_cv = (SV*)GvCV(gv_fetchpv("DB::finish_profile", FALSE, SVt_PVCV)); + if (opt_use_db_sub) { + PL_perldb |= PERLDBf_LINE; /* line-by-line profiling via DB::DB (if $DB::single true) */ + PL_perldb |= PERLDBf_SINGLE; /* start (after BEGINs) with single-step on XXX still needed? */ + } + #ifdef HAS_CLOCK_GETTIME if (profile_clock == -1) { /* auto select */ # ifdef CLOCK_MONOTONIC @@ -3028,7 +3033,7 @@ /* redirect opcodes for statement profiling */ Newxc(PL_ppaddr_orig, OP_max, void *, orig_ppaddr_t); Copy(PL_ppaddr, PL_ppaddr_orig, OP_max, void *); - if (profile_stmts && !use_db_sub) { + if (profile_stmts && !opt_use_db_sub) { PL_ppaddr[OP_NEXTSTATE] = pp_stmt_profiler; PL_ppaddr[OP_DBSTATE] = pp_stmt_profiler; #ifdef OP_SETSTATE @@ -3451,7 +3456,7 @@ logwarn("fid %d has %ld src lines\n", e->id, (long)lines); /* for perl 5.10.0 or 5.8.8 (or earlier) use_db_sub is needed to get src */ /* give a hint for the common case */ - if (0 == lines && !use_db_sub + if (0 == lines && !opt_use_db_sub && ( (e->key_len == 1 && strnEQ(e->key, "-", 1)) || (e->key_len == 2 && strnEQ(e->key, "-e", 2)) ) ) { @@ -4542,7 +4547,7 @@ CODE: /* this sub gets aliased as "DB::DB" by NYTProf.pm if use_db_sub is true */ PERL_UNUSED_VAR(items); - if (use_db_sub) + if (opt_use_db_sub) DB_stmt(aTHX_ NULL, PL_op); else if (1||trace_level) logwarn("DB called needlessly\n"); ======================================= --- /trunk/lib/Devel/NYTProf.pm Wed Oct 28 03:32:23 2009 +++ /trunk/lib/Devel/NYTProf.pm Wed Oct 28 05:00:38 2009 @@ -28,11 +28,7 @@ # XXX hack, need better option handling my $use_db_sub = ($ENV{NYTPROF} && $ENV{NYTPROF} =~ m/\buse_db_sub=1\b/); -$^P |= 0x002 # line-by-line profiling via DB::DB (if $DB::single true) - | 0x020 # start (after BEGINs) with single-step on - if $use_db_sub; - -require Devel::NYTProf::Core; # loads XS +require Devel::NYTProf::Core; # loads XS and sets options if ($use_db_sub) { # install DB::DB sub *DB = ($] < 5.008008) --~--~---------~--~----~------------~-------~--~----~ 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] -~----------~----~----~----~------~----~------~--~---
