Devel::DTrace - Enable dtrace probes for subroutine entry, exit
$ perl -MDevel::DTrace prog.pl & $ ps -af | grep perl $ dtrace -p <PID> -s examples/subs-tree.d $ cat examples/subs-tree.d #pragma D option quiet perlxs$target:::sub-entry, perlxs$target:::sub-return { printf("%s %s (%s:%d)\n", probename == "sub-entry" ? "->" : "<-", copyinstr(arg0), copyinstr(arg1), arg2); }
This module is alpha. Use with care. Expect problems. Report bugs.
Sun's dtrace tool is currently supplied with Solaris and Mac OS 10.5. It allows probes to be attached to a running executable so that debug information may be gathered.
This module provides probes for subroutine entry and exit. See examples/subs-tree.d for an small example D script that uses them.
dtperl
When you install Devel::DTrace you will also get a custom Perl interpreter called dtperl which automatically installs the dtrace instrumented runops loop at startup. Any Perl program run under dtperl can be probed using dtrace.
Devel::DTrace
dtrace
Note that dtrace can't find any probes in the Perl executable until after Devel::DTrace has loaded - because before then the probes don't exist. That means that you must use e.g.
dtrace -Z -n 'perlxs$target:::{ trace(copyinstr(arg0)); }' -c
The -Z switch tells dtrace that the named probe doesn't yet exist. Thanks to Chris Andrews for the suggestion.
-Z
On Solaris dtperl is statically linked and therefore probably not much use. Working out why I can't build a dynamic dtperl is high on my todo list.
It's difficult to test the dtrace probes. To do so the tests would have to run as root and I don't like doing that. So that I can get some test coverage the environment variable DEVEL_DTRACE_RUNOPS_FAKE causes the probes to send output directly to STDOUT rather to dtrace.
DEVEL_DTRACE_RUNOPS_FAKE
Note that this variable is only checked when Devel::DTrace is loaded or dtperl starts up so it can't be used to toggle tracing on and off while a process is running. However you may find it convenient in some cases to
$ DEVEL_DTRACE_RUNOPS_FAKE=1 dtperl someprog.pl
Andy Armstrong <andy@hexten.net>
Copyright (c) 2008, Andy Armstrong <andy@hexten.net>. All rights reserved.
<andy@hexten.net>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install Devel::DTrace, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::DTrace
CPAN shell
perl -MCPAN -e shell install Devel::DTrace
For more information on module installation, please visit the detailed CPAN module installation guide.