edwardt_tril has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Can anyone give me some advice in profiling a subset of
subroutines inside multiple perl scripts through 1 entry point script
My aim is to profile certain parts of a big perl apps and excluding the part I am not interested in.
I know there is a -DProfile option but it profiles everything involved in EntryPoint.pl (see below).
But what if I only insterested in measuring the effects of
only certain subroutine/subroutines (for example, subroutine LogMe of LogMe.pl)
but excluding all the others, how can I do that?
LogMe.pl
use B; sub LogMe{ #calling other subroutines and do a lot of stuff print "logme is called\n"; B->new; B->_func2; };
commonRoutine.pm
package commonRoutine; sub new { my ($class, $cacheFileName) = @_; my $this = bless({}, ref($class) || $class); # Initialize member variables. $this->{initialized} = 1; $this->{lastFlushTime} = time(); return $this; } ## # Destructor. Clean up object. # sub DESTROY { my $this = shift; $this->_func2(); } sub _func3{ print "me\n"; } 1
EntryPoint.pl:
use A; use commonRoutine; do ('LogMe.pl'); sub enter{ A->new; commonRoutine->new; }
A.pm:
package A; use strict; use B; use commonRoutine; do ('LogMe.pl'); ## # Constructor. Initialize instance of object. # # @param $cacheFileName [in] Name of cache file. # # @return Instance of object or undef if failure. # sub new { print "A->new()\n"; my ($class, $cacheFileName) = @_; my $this = bless({}, ref($class) || $class); # Initialize member variables. $this->{initialized} = 1; $this->{lastFlushTime} = time(); $this->_func1(); return $this; } ## # Destructor. Clean up object. # sub DESTROY { my $this = shift; } sub _func1{ LogMe(); print "me\n"; } 1
B.pm
package B sub new { my ($class, $cacheFileName) = @_; my $this = bless({}, ref($class) || $class); # Initialize member variables. $this->{initialized} = 1; $this->{lastFlushTime} = time(); $this->_func2(); return $this; } ## # Destructor. Clean up object. # sub DESTROY { my $this = shift; $this->_func2(); } sub _func2{ print "me\n"; } 1

Edit: g0n - readmore tags

  • Comment on profiling a subset of subroutines inside multiple perl scripts through 1 entry point script
  • Select or Download Code

Replies are listed 'Best First'.
Re: profiling a subset of subroutines inside multiple perl scripts through 1 entry point script
by salva (Canon) on Feb 09, 2006 at 09:44 UTC
    You can use Devel::SmallProf for that.

    At the beginning of your script add...

    $DB::profile = 0;
    and at the beggining of every function you want to profile...
    local $DB::profile = 1;