Day 19: Tracing your Perl program's execution (App::plstrace)
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
plstrace is a Perl script which can be used to trace your Perl program's execution. There are other "tracing" modules already available on CPAN, but I was inspired by the popular and immensely useful Unix utility strace, so the interface and output format of plstrace mimic that of strace.
Under the hood, though, things are different. plstrace currently can only trace user-defined subroutines and not Perl builtins. It is implemented by wrapping Perl subroutines with Perl subroutines during INIT phase. caller() has been adjusted so the wrapped subroutines does not see the trace wrappers (thanks to Hook::LexWrap). O/S system calls or external programs are not traced. And there are a few other technical limitations.
And it turns out that plstrace is not very useful (hah, got you :-p) as I seldom touch it again after experimenting with writing it in the first place. Instead, I usually revert to logging using Log::Any when wanting to trace the flow of execution or find out the data being modified/involved during program execution, or reaching out to Devel::NYTProf when wanting to figure out performance problems and bottlenecks. I guess the main problem is plstrace, for this type of tracing, I usually might want to trace standard, well-known Perl subroutines, which normally mean Perl builtin functions!
Nevertheless, perhaps some of you might like or find it useful.
Leave a comment