Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Alias (5735)

Alias
  (email not shown publicly)
http://ali.as/

Journal of Alias (5735)

Monday April 27, 2009
11:57 PM

Aspect::Library::Trace - A replacement for dprofpp -T

[ #38883 ]

http://svn.ali.as/cpan/releases/Aspect-Library-Trace-0.02.tar.gz

When I first discovered Devel::DProf I fell in love with it not once, but twice.

First and foremost there was the profiling functionality that I've since replaced with the far superior and not-bit-rotted Devel::NYTProf.

But the second really useful feature was the C command, which took the function call tree and printed it out. This made for a really easy way to debug a programs internals, because you could filter the (gigantic) function tree output and see when and where various interesting functions were called.

Aspect::Library::Trace is partial replacement for this functionality.

It replaces a debugger-level internals hooking of all function calls with an Aspect-controllable selective hook (Aspect implements "Aspect Oriented Programming" concepts, which at it's core is a fancy structured wrapper for Hook::LexWrap.

To use it, you just do something like the following in your top level script (after you have loaded the modules you care about).

    use Aspect;
    use Aspect::Library::Trace;

    aspect Trace => call qr/^Foo::/;

A function tree of all modules described in the pointcut (that would be the qr/^Foo::/ bit) will be printed to STDERR.

    Foo::foo1
        Foo::foo2
            Foo::foo3
    Foo::foo2
        Foo::foo3
    Foo::foo2
        Foo::foo3

I've been finding this particularly useful for debugging things like where different DBI code gets called from, and whether or not caching code is working the way I expect it to.

Update:

After finding it too hard to type three lines, I've also added support for a simple one-line form.

use Aspect::Library::Trace qr/^Foo::/;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • That sounds remarkably similar to something I wrote some years ago and never released because I thought it was too trivial - although I *did* release part of it as [cpan://Sub::WrapPackages].

    My version also logged the input and output from functions, which I found very useful.

    • You should know by now that NOTHING is too trivial :)

      I'd like to put more hooks and options into the aspect, once I work out where exactly I want to go with this and get a little more experience using Aspect.