Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

[Solved] Best method of call tracing, without writing code?

by Hercynium (Hermit)
on Oct 05, 2007 at 16:36 UTC ( #642956=perlquestion: print w/replies, xml ) Need Help??
Hercynium has asked for the wisdom of the Perl Monks concerning the following question:

I thought this was too simplistic a question for SoPW, but the CB was pretty well engaged in an interesting discussion that I decided trying to interrupt further would be rude :)

I have an existing code-base, and I want to begin writing a test suite for one of the modules. I've decided that the best way to start would be to determine exactly what data is being passed into each subroutine and what is getting returned.

So, for example, I want to be able to specify that all method and subroutine calls in module Foo::Bar get logged, complete with a dump of the passed arguments and the returned data. This has to be done without modifying any existing code. (Adding a single 'use' at the top of the main script is acceptable, though)

I found Debug::Trace which looks like it will do the job, and the author looks like someone who knows his stuff (He also wrote the venerable Getopt::Long!) but I wonder if there is a better, more fitting solution to which the wisdom of the Monks can illuminate.

Update: Down the rabbit hole we go... I've now tried Debug::Trace, Devel::TraceCalls, and Devel::TraceMethods, and none worked... BUT I have an idea why.

The module that *uses* the module whose methods I want to trace is loaded dynamically, at run-time through a mechanism I created with an eval. In other words, the methods that call the methods I want to analyze are in a module that isn't used until run-time, and therefore the module containing the methods I want to analyze is not loaded until run-time. Ick...

It's a bit complicated to describe - the code is on CPAN as TL1ng. (please don't take this as a plug for my module... it's still young and fragile.)

Update 2: Eureka! Since I am testing, I already know which module will be loaded at run-time... so I can pre-load it and now Debug::Trace works!
perl -MTL1ng::Base -MDebug::Trace=TL1ng::Parser::parse_string,:indent\ +(2\),:nomaxdepth,:nouseqq

Of course, it would still be nice to get some more feedback on other better/best/interesting debugging techniques of similar ilk!

Ikegami - Even though I figured it out before you posted, Thank you!

Replies are listed 'Best First'.
Re: Best method of call tracing, without writing code?
by ikegami (Pope) on Oct 05, 2007 at 18:10 UTC

    The module that *uses* the module whose methods I want to trace is loaded dynamically, at run-time through a mechanism I created with an eval.

    So load it earlier when debugging.

    perl -MTL1ng::Parser -MDebug::Trace=TL1ng::Parser::parse_string test_s
Re: Best method of call tracing, without writing code?
by dragonchild (Archbishop) on Oct 05, 2007 at 16:57 UTC
    What are you looking for that Debug::Trace doesn't do for you?

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Really, I'm just looking for the current best practice.

      As a update, I've just tried Debug::Trace as it is documented and I'm getting no output...
      perl -MDebug::Trace=TL1ng::Parser::parse_string
      TL1ng::Parser::parse_string() is called as a method on a TL1ng::Parser object from inside various methods in TL1ng::Base.

      I can't figure out what I'm missing :(
Re: [Solved] Best method of call tracing, without writing code?
by DrHyde (Prior) on Oct 08, 2007 at 08:40 UTC
    It's for this task that I wrote Sub::WrapPackages, although right now you'll still have to write a bit of code to make it do exactly what you want. The Log::FunctionCalls module that was going to depend on it has been on my to-do list for, umm, far too long. Sorry.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://642956]
Approved by Corion
Front-paged by Corion
[Corion]: Once more, I'm looking for a sane client-side framework, but I guess these don't exist. Everything I look at either uses a weirdo home-grown templating language (like Angular in all its incarnations) or uses weirdo Javascript incarnations (like ...
[Corion]: ... Inferno.js, which uses ES2015) or uses some horrible amount of Javascript infrastructure before you can even render a single file.
[Corion]: I'd really like to create a dynamic frontend for my Google Keep clone, but so far, all the templating solutions seem to bring their own template language or require me to hand-code everything in (their own flavour of) Javascript. I'd like something ...
[Corion]: ... that can use templates from the HTML (via <script language="text/ template">... my template ...</script> and otherwise gets out of my way. But it seems that is not how the Javascript world is, currently :-/
[Corion]: I guess my question is, has anybody worked with React, Ember, Angular (v2, v4, v.whatever) or any other JS client-side dynamic rendering/virtual DOM thingie and found a simple, single-file solution like jQuery?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2017-03-27 19:03 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (321 votes). Check out past polls.