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

Esteemed monks,
I have a very bad piece of code that takes 2-3 minutes to compile! Can I have some sort of compilation profiling? I tried "Autotrace" option of PERLDB_OPTS. It gives you list of all statements executed, but doesn't tell how much time was spent on each of them.
I also tried Devel::Modlist, which can tell most of the .pm files parsed at compilation - but again no mention of the time taken.
Ideally, if I could get the list of the modules that are compiled, how many times they are parsed and the time taken for their compilation - that would help me nail down the exact set of modules that need to be rewritten to reduce my compilation time.

I'm new to perl as such, so please forgive in case I missed something.

thanks in advance!

Replies are listed 'Best First'.
Re: help on compilation profiling
by salva (Canon) on Sep 18, 2007 at 10:57 UTC
    2-3 minutes is far too much (unless you are running Perl in and old C=64)!

    Probably one of the modules you are using is doing something more that just being compiled. For instance, resolving some hostnames, trying to stablish some connection with a remote server, etc.

    How is your CPU load over that 2-3 minutes?. Compiling would use 100%. On the other hand, if it is doing nothing over a long period, use strace or a similar utility to monitor your script at the OS level and found what it is waiting for.

    Finally, you can also use a divide and conquer approach to find the slow loading module, insert sentences like the ones below between the use calls:

    BEGIN { $| = 1; printf "%d: Foo\n", time } use Foo; BEGIN { printf "%d: Bar\n", time } use Bar; BEGIN { printf "%d: all modules loaded\n", time }
Re: help on compilation profiling
by Muggins (Pilgrim) on Sep 18, 2007 at 12:40 UTC
    Hi,

    You can see exactly how long the certain parts of compilation (BEGIN blocks, use statements) are taking using Devel::DProf. Just run using:

    perl -d:DProf your_program.pl

    ..it will put info into a file "tmon.out". Then:

    dprofpp -S (or -E or -I depending on what/how much you want to see)

    at the command line (in the same directory you're running in) will give you lots of info.

      thanks! I'll try those out and get back to you with how it goes.