Giter VIP home page Giter VIP logo

devel-tracerun's Introduction

NAME

Devel::TraceRun - Shows all the function calls and returns in a Perl program

PROJECT STATUS

CPAN version

SYNOPSIS

$ perl -d -d:TraceRun -S yourscript

DESCRIPTION

Figuring out a large system's workings is hard. Figuring out why it's not working, and where it's going wrong, is even harder.

This tool produces an indented list of all function calls with parameters (in a very very concise format) and return values (ditto). It aims to minimise diffs between runs of a program that are doing the same thing, so that differences stand out.

The output is on STDOUT currently. That may become overridable in due course.

Example

This code (from the test - Thing::func calls Thing::func2 which returns "2nd retval"):

use Thing;
my $f = sub { Thing::func() };
Thing::func([2]); # void
my @r = Thing::func([2]);
my @r2 = $f->("very long string", 2, bless {}, 'Thing');

run with:

perl -d -d:TraceRun script.pl

produces on perl 5.8 - 5.14 (output is slightly different from 5.16, and again from 5.28):

main::(script.pl:1)()
return()
Thing::func(ARRAY)
  Thing::func2()
  return()
return()
Thing::func(ARRAY)
  Thing::func2()
  return(2nd retval)
return(2nd retval)
main entry(very long ,2,Thing)
  Thing::func()
    Thing::func2()
    return(2nd retval)
  return(2nd retval)
return(2nd retval)

Note that in void context, nothing is returned. Also note the very long string is truncated to (currently) 10 characters, array- and hash-refs are printed just as ARRAY and HASH, and objects as their classname.

There is currently no way to change what is printed. One thing that would increase homogeneity across runs would be a way to specify for certain function-names, which inputs or outputs to mask. Obvious examples where this would help are functions that return the current time, or a random number, or the port number of an incoming IP connection.

Another source of output variation is the change in Perl 5.18 to randomise the order hash-keys are returned in. You can overcome this for tracing purposes by setting the environment variable PERL_HASH_SEED to 0, which also has the effect of setting PERL_PERTURB_KEYS to 0.

How it works

As may be discerned from the command line, it uses Perl's debugging functionality. However, unlike the normal use of that, it is entirely non-interactive. Instead, it replaces DB::DB with a no-op, and uses the DB::sub hook to report function entries and returns.

These reports are indented (currently hardcoded to two spaces), nested according to stack depth. It is intended to be completely obvious what everything means.

SEE ALSO

perldebguts

AUTHOR

Ed J

COPYRIGHT AND LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

devel-tracerun's People

Contributors

mohawk2 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

clayne haarg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.