document updated 13 days ago, on Nov 7, 2024
Various tracing modules
You might be familiar with Bash's set -x. Or even Basic's TRON command, which may have been related to the movie 'Tron'.
(note: Some modules below will only enable tracing within the CURRENT package. To fix this — to enable tracing everywhere:
)
automatically trace things, without having to add code in every subroutine
- Devel::Trace
(20 ++s, last updated Mar 2012, first released Sep 1999)
- good if you just need specific line numbers, but minimal variable contents
- the output only goes to STDERR, if you need it to go somewhere else, then manually redirect STDERR
- Data::Dump::Trace
(41 ++s, last updated Jun 2021, first released 1998)
- Devel::DumpTrace
(7 ++s, last updated May 2019, first released 2011)
- good if you need LOTS of variable contents
- Devel::Trace::More
(2 ++s, last updated Aug 2011, first released Oct 2009)
- Devel::Trace::Fork
(last updated Sep 2010, first released ??)
- Log::Trace
(last updated Nov 2005, first released ??)
- Debug::Trace
(5 ++s, last updated Nov 2013, first released Oct 2002)
- Acme::Echo
(last updated Apr 2007, first released Aug 2006)
- Devel::STrace — although it's called "strace", it has nothing to do with that system utility, and it only traces Perl subs
(last updated Aug 2006, first released ??)
- even more detailed tracing
- Runops::Trace — trace Perl opcodes
(2 ++s, last updated Jan 2011, first released Oct 2005)
- other funky stuff
- Devel::Spy — logs all accesses to your objects and data
(1 ++, last updated Jul 2010, first released ~2006)
- Tie::Trace — watch specific variables that you 'tie'
(8 ++s, last updated Jan 2017, first released Aug 2006)
- interfaces to truss/strace/etc (ie. can be used for non-Perl programs)
- Sys::Trace
(last updated Jul 2010, first released Jun 2010)
trace whenever a variable gets changed
only displays a full stack (with subroutine arguments) for very specific conditions... not every line
using Devel::DumpTrace in a CGI script
To use Devel::DumpTrace in a CGI script, just modify the first line that reads #!/usr/bin/perl with:
#!/usr/bin/perl -d:DumpTrace
Then add this near the very top of the script:
BEGIN {
# if Devel::DumpTrace is loaded, direct output to trace.txt
if ($INC{'Devel/DumpTrace.pm'} && !$^C) {
no warnings 'once'; # avoid name "used only once" warnings
open $Devel::DumpTrace::DUMPTRACE_FH, '>', '/var/tmp/trace.txt';
$Devel::DumpTrace::EXCLUDE_PKG{'DB_File'} = 1;
}
}
library-specific logging/tracing