Reputation: 22421
I'm trying to profile a big application that contains a module creatively named DB
. After running it under -d:NYTProf
and calling nytprofhtml
, both without any additional switches or related environment variables, I get usual nytprof
directory with HTML output. However it seems that due to some internal logic any output related to my module DB
is severely mangled. Just to make sure, DB
is pure Perl.
-pm-NN-line.html
file, links to subs from DB
point to entry script instead.DB-pm-NN-line.html
and it does exists, but unlike all other files it doesn't have "Statements" table inside and "Line" table have absolutely no lines of code, only summary of calls.Actually, here's a small example:
# main.pl
use lib '.';
use DB;
for (1..10) {
print DB::do_stuff();
}
# DB.pm
package DB;
sub do_stuff {
my $a = 1;
my $b = 2;
my $c = $a + $b;
return $c;
}
1;
Try running perl -d:NYTProf main.pl
, then nytprofhtml
and then inspect nytprof/DB-pm-8-line.html
.
I don't know if it happens because NYTProf itself have internal module named DB
or it handles modules starting with DB in some magical way - I've noticed output for functions from DBI
looks somewhat different too.
Is there a way to change/disable this behavior short of renaming my DB
module?
Upvotes: 0
Views: 111
Reputation: 126732
That's hardly an option
You don't really have an option. The special DB
package and the associated Devel::
namespace are coded into the perl compiler / interpreter. Unless you want to do without any debugging facilities altogether and live in fear of any mysterious unquantifiable side effects then you must refactor your code to rename your proprietary DB
library
Anyway, the name is very generic and that's exactly why it is expected to be encountered
On the contrary, Devel::NYTProf
is bound to use the existing core package DB
. It's precisely because it is a very generic identifier that an engineer should reject it as a choice for production code, which could be required to work with pre-existing third-party code at any point
a module creatively named
DB
This belies your own support of the choice. DB
has been a core module since v5.6 in 2000, and anything already in CPAN should have been off the cards from the start. I feel certain that the clash of namespaces must been discovered before now. Please don't be someone else who just sweeps the issue under the carpet
Remember that, as it stands, any code you are now putting in the DB
package is sharing space with everything that perl has already put there. It is astonishing that you are not experiencing strange and inexplicable symptoms already
I don't see that it's too big a task to fix this as long as you have a proper test suite for your 10MB of Perl code. If you don't, then hopefully you will at least not make the same mistakes again
Upvotes: 3