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

Alias on 2009-04-28T04:57:07

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::/;


This sounds familiar ...

drhyde on 2009-04-29T10:20:16

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.

Re:This sounds familiar ...

Alias on 2009-04-30T08:38:54

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.