Devel::STrace - strace-like runtime call trace for Perl applications
# # setup environment variables to control # configuration of Devel::RingBuffer's mmap'ed # memory # export DEVEL_RINGBUF_SLOTS=10 export DEVEL_RINGBUF_BUFFERS=50 export DEVEL_RINGBUF_FILE='somescript.prof' # # run the script under STrace perl -d:STrace somescript # # use another terminal to view the # contents of the ringbuffers # plstrace.pl -f $DEVEL_RINGBUF_FILE -s 10 -d 100
Provides a strace/truss-like runtime call monitor for Perl applications. Note that, while strace/truss only dumps system calls, Devel::STrace dumps all calls to Perl subs on the application's stack. Also note that Devel::STrace cannot trace non-Perl calls (e.g., calls inside XS/C modules), so an additional external strace/truss monitor may be needed to fully diagnose a misbehaving Perl script.
As each subroutine is entered (ie, when
DB::sub() is called), the next available ring buffer slot is allocated (possibly overwriting the oldest in-use slot) and
$DB::sub is written to the slot - possibly suffixed by the $AUTOLOAD value if the call is an AUTOLOAD - and the line number and timestamp (as returned by Time::HiRes) are set to -1, 0, respectively. The line number and timestamp are filled in by
DB::DB() as each Perl statement is executed.
Note that no explicit locks are used during the slot updates, in order to minimize the profiling overhead,
Also note that exit timings are not provided, as this tool is intended for debugging, rather than profiling, purposes.
The Devel::STrace::Monitor module provides a minimal set of functions for external applications to
The included plstrace.pl script implements a simple command line monitoring view using Devel::STrace::Monitor. More feature rich debugging applications (esp. GUI based) are planned.
Implements DB::DB and DB::sub. The ringbuffer is created by the Devel::RingBuffer class, which also acts as a factory for individual Devel::RingBuffer::Ring objects (representing a single ring buffer).
On POSIX-based systems, a file must be physically created to be mmap()'ed and read by a separate monitoring process. While this possibly permits post-mortem analysis of the execution when things die (though not guaranteed due to file flushing issues), it is possible to accumulate trace files in the /tmp directory if a trace file is not explicitly defined via
DEVEL_RINGBUF_FILE, as Devel::STrace doesn't currently know when to safely unlink such files.
$DB::singleon/off, so that more general, lower overhead tracing can be performed (ie, just logs subroutine entry/exit, no per-statement logging).
strace(1) (or truss(1))
Dean Arnold mailto:email@example.com
Copyright(C) 2006, Dean Arnold, Presicient Corp., USA. All rights reserved.
Permission is granted to use this software under the same terms as Perl itself. Refer to the Perl Artistic License for details.