Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Class::InsideOut doesn't play nicely with DProf

by patspam (Sexton)
on Jul 01, 2008 at 09:11 UTC ( #694910=perlquestion: print w/ replies, xml ) Need Help??
patspam has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I'm having trouble profiling code using DProf and dprofpp when Class::InsideOut is involved. From what I can gather it's due to the magic goto & on line 666 of InsideOut.pm that garbles the output. Does anyone know a way around this? I can run dprofpp with the "-F" option but I end up with negative time values. example.pl
use Class::InsideOut;
And then run:
perl -d:DProf example.pl && dprofpp tmon.out
Generates:
Exporter::import Garbled profile, unexpected exit time stamp at __path_to_dprofpp__ lin +e 666, <fh> line 385.
Cheers, Patrick

Comment on Class::InsideOut doesn't play nicely with DProf
Select or Download Code
Re: Class::InsideOut doesn't play nicely with DProf
by BrowserUk (Pope) on Jul 01, 2008 at 10:05 UTC

    You should be able to replace the use of goto in the four subroutines private(), property(), public() & readonly() with a normal function call if you postpend the caller() to @_, and the only difference will be that it will run (marginally) faster. That is, property() would become:

    sub property($\%;$) { ## no critic -- prototype &_check_property; push @_, scalar caller(); &_install_property; }

    and _install_property() would become:

    sub _install_property{ my ($label, $hash, $opt, $caller) = @_; # my $caller = caller(0); # we get here via "goto", so caller(0) is + right $PROP_DATA_FOR{ $caller }{$label} = $hash; my $options = _merge_options( $caller, $opt ); if ( exists $options->{privacy} && $options->{privacy} eq 'public' + ) { no strict 'refs'; *{ "$caller\::$label" } = ($options->{set_hook} || $options->{get_hook}) ? _gen_hook_accessor( $hash, $label, $options->{get_ho +ok}, $options->{set_hook} +) : _gen_accessor( $hash ) ; $PUBLIC_PROPS_FOR{ $caller }{ $label } = 1; } return; }

    That's untested, but I believe it shoudl work and be a little quicker. That only leaves the goto at line 81 (There is no goto at line: 666? Maybe the "evil" connotations made you miss that the line number 666 related to dprof_pp rather than the source file :).

    This might be more awkward as Exporter might rely upon caller() being different, though I've never seen anyone else that subclasses Exporter use goto. I think you should try just deleting the goto on line 81 and see what happens.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Sadly no good - the suggested changes make modules using Class::InsideOut go boom. Sorry about the incorrect line number, the goto I'm really interested in nuking is the one at line 79:
      goto &Exporter::import;
      Patrick

        I've looked into it. Please try replacing that line with these:

        local $Exporter::ExportLevel = $Exporter::ExportLevel + 1; &Exporter::import;

        I don't really like playing with a global hack like that, but it's limited in scope and Class::InsideOut still passes all its tests.

        Let me know if that works for you with DProf and if it does, I'll release it as Class::InsideOut 1.10

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Class::InsideOut doesn't play nicely with DProf
by xdg (Monsignor) on Jul 02, 2008 at 12:50 UTC

    Do some of the other profilers on CPAN choke on it as well? It would be interesting to see if the technique in general is a problem or just DProf's reaction to it.

    If you email me a test case, I'll look into what could be done in Class::InsideOut to make it work. (dagolden _at_ cpan.org)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://694910]
Approved by Corion
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2014-12-19 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (82 votes), past polls