This post contains a few state-of-the-art notes concerning Perl-specific DTrace probes available in OpenSolaris today (2010-05-31). For instructions how to quickly install a working DTrace-enabled version of Perl, skip to the next section.
- The OpenSolaris (2010.03, snv_134) Perl binary package comes with DTrace support disabled. Probably a good thing because the current implementation incurs a reported 5% worst-case performance hit - even with no enabled probes!
- Perl source packages from 5.12.x on (or maybe already in 5.10.x?) have some basic DTrace support, good for instrumenting calls to and returns from subroutines.
- More probes were made available through a patch from Sven Dowideit. However, his patch does not apply cleanly to 5.12.x.
- Building Perl from source with DTrace support fails due to a known bug in
Makefile.SH
. - Why bother? To see system calls and kernel (e.g. I/O) activity incurred by a particular Perl subroutine call, for example. Or to monitor memory allocations. For pure Perl performance profiling better tools exist (such as NYTProf).
Building DTrace-enabled Perl in OpenSolaris
- Download a recent Perl source code package. I grabbed 5.12.1.
- If you just want the subroutine entry/return probe, apply the mini-patch from Peter Bray's bug report to avoid a build error about missing op.o and perl.o, then skip the next step. On the other hand, if you'd like to try Sven Dowideit's probes as well:
- Download and apply this patch (version 2) to your freshly unpacked Perl source. This is a version of Sven's patch updated by myself to apply cleanly to 5.12.x, with an additional fix to
Makefile.SH
to avoid build interruptions and a fix to avoid a strange segfault inPerl_ck_require
when tracing of loaded modules is enabled. Please note that I have not tested Sven's patch extensively. We are probably talking about a development build here that may aid your Perl code debugging efforts rather than something to put in production. - To compile:
make distclean ./Configure -des -Dprefix="/opt/perl-5.12.1" -Dusedtrace -Duseshrplib make
Testing whether it works
Generally, the new probes become visible when a Perl process is running. You should be able to see them with the following command:
pfexec dtrace -l | grep perl
Here is a little test Perl script:
#!/opt/perl/bin/perl foo() for 1..50; sub foo { print BAD_HANDLE "In foo\n"; sleep(1); }
A little test DTrace script:
#!/usr/sbin/dtrace -s perl$target:::sub-entry, perl$target:::sub-return { printf("%s %s (%s:%d)\n", probename == "sub-entry" ? "->" : "<-", copyinstr(arg0), copyinstr(arg1), arg2); }
Running both of them together:
pfexec dtrace -Z -s ./script.d -c ./script.pl
Several nice sample scripts for DTrace-enabled Perl are included in the DTrace Toolkit. Check it out.
If you want to see Sven's probes in action: download, read and run his example Perl DTrace script. Alternatively, you might try my DTrace script to measure time consumed by use/require statements.
No comments:
Post a Comment