1PERLDTRACE(1)          Perl Programmers Reference Guide          PERLDTRACE(1)
2
3
4

NAME

6       perldtrace - Perl's support for DTrace
7

SYNOPSIS

9           # dtrace -Zn 'perl::sub-entry, perl::sub-return { trace(copyinstr(arg0)) }'
10           dtrace: description 'perl::sub-entry, perl::sub-return ' matched 10 probes
11
12           # perl -E 'sub outer { inner(@_) } sub inner { say shift } outer("hello")'
13           hello
14
15           (dtrace output)
16           CPU     ID                    FUNCTION:NAME
17             0  75915       Perl_pp_entersub:sub-entry   BEGIN
18             0  75915       Perl_pp_entersub:sub-entry   import
19             0  75922      Perl_pp_leavesub:sub-return   import
20             0  75922      Perl_pp_leavesub:sub-return   BEGIN
21             0  75915       Perl_pp_entersub:sub-entry   outer
22             0  75915       Perl_pp_entersub:sub-entry   inner
23             0  75922      Perl_pp_leavesub:sub-return   inner
24             0  75922      Perl_pp_leavesub:sub-return   outer
25

DESCRIPTION

27       DTrace is a framework for comprehensive system- and application-level
28       tracing. Perl is a DTrace provider, meaning it exposes several probes
29       for instrumentation. You can use these in conjunction with kernel-level
30       probes, as well as probes from other providers such as MySQL, in order
31       to diagnose software defects, or even just your application's
32       bottlenecks.
33
34       Perl must be compiled with the "-Dusedtrace" option in order to make
35       use of the provided probes. While DTrace aims to have no overhead when
36       its instrumentation is not active, Perl's support itself cannot uphold
37       that guarantee, so it is built without DTrace probes under most
38       systems. One notable exception is that Mac OS X ships a /usr/bin/perl
39       with DTrace support enabled.
40

HISTORY

42       5.10.1
43           Perl's initial DTrace support was added, providing "sub-entry" and
44           "sub-return" probes.
45
46       5.14.0
47           The "sub-entry" and "sub-return" probes gain a fourth argument: the
48           package name of the function.
49
50       5.16.0
51           The "phase-change" probe was added.
52

PROBES

54       sub-entry(SUBNAME, FILE, LINE, PACKAGE)
55           Traces the entry of any subroutine. Note that all of the variables
56           refer to the subroutine that is being invoked; there is currently
57           no way to get ahold of any information about the subroutine's
58           caller from a DTrace action.
59
60               :*perl*::sub-entry {
61                   printf("%s::%s entered at %s line %d\n",
62                          copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg0);
63               }
64
65       sub-return(SUBNAME, FILE, LINE, PACKAGE)
66           Traces the exit of any subroutine. Note that all of the variables
67           refer to the subroutine that is returning; there is currently no
68           way to get ahold of any information about the subroutine's caller
69           from a DTrace action.
70
71               :*perl*::sub-return {
72                   printf("%s::%s returned at %s line %d\n",
73                          copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg0);
74               }
75
76       phase-change(NEWPHASE, OLDPHASE)
77           Traces changes to Perl's interpreter state. You can internalize
78           this as tracing changes to Perl's "${^GLOBAL_PHASE}" variable,
79           especially since the values for "NEWPHASE" and "OLDPHASE" are the
80           strings that "${^GLOBAL_PHASE}" reports.
81
82               :*perl*::phase-change {
83                   printf("Phase changed from %s to %s\n",
84                       copyinstr(arg1), copyinstr(arg0));
85               }
86

EXAMPLES

88       Most frequently called functions
89               # dtrace -qZn 'sub-entry { @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END {trunc(@, 10)}'
90
91               Class::MOP::Attribute::slots                                    400
92               Try::Tiny::catch                                                411
93               Try::Tiny::try                                                  411
94               Class::MOP::Instance::inline_slot_access                        451
95               Class::MOP::Class::Immutable::Trait:::around                    472
96               Class::MOP::Mixin::AttributeCore::has_initializer               496
97               Class::MOP::Method::Wrapped::__ANON__                           544
98               Class::MOP::Package::_package_stash                             737
99               Class::MOP::Class::initialize                                  1128
100               Class::MOP::get_metaclass_by_name                              1204
101
102       Trace function calls
103               # dtrace -qFZn 'sub-entry, sub-return { trace(copyinstr(arg0)) }'
104
105               0  -> Perl_pp_entersub                        BEGIN
106               0  <- Perl_pp_leavesub                        BEGIN
107               0  -> Perl_pp_entersub                        BEGIN
108               0    -> Perl_pp_entersub                      import
109               0    <- Perl_pp_leavesub                      import
110               0  <- Perl_pp_leavesub                        BEGIN
111               0  -> Perl_pp_entersub                        BEGIN
112               0    -> Perl_pp_entersub                      dress
113               0    <- Perl_pp_leavesub                      dress
114               0    -> Perl_pp_entersub                      dirty
115               0    <- Perl_pp_leavesub                      dirty
116               0    -> Perl_pp_entersub                      whiten
117               0    <- Perl_pp_leavesub                      whiten
118               0  <- Perl_dounwind                           BEGIN
119
120       Function calls during interpreter cleanup
121               # dtrace -Zn 'phase-change /copyinstr(arg0) == "END"/ { self->ending = 1 } sub-entry /self->ending/ { trace(copyinstr(arg0)) }'
122
123               CPU     ID                    FUNCTION:NAME
124                 1  77214       Perl_pp_entersub:sub-entry   END
125                 1  77214       Perl_pp_entersub:sub-entry   END
126                 1  77214       Perl_pp_entersub:sub-entry   cleanup
127                 1  77214       Perl_pp_entersub:sub-entry   _force_writable
128                 1  77214       Perl_pp_entersub:sub-entry   _force_writable
129
130       System calls at compile time
131               # dtrace -qZn 'phase-change /copyinstr(arg0) == "START"/ { self->interesting = 1 } phase-change /copyinstr(arg0) == "RUN"/ { self->interesting = 0 } syscall::: /self->interesting/ { @[probefunc] = count() } END { trunc(@, 3) }'
132
133               lseek                                                           310
134               read                                                            374
135               stat64                                                         1056
136

REFERENCES

138       DTrace User Guide
139           http://download.oracle.com/docs/cd/E19082-01/819-3620/index.html
140           <http://download.oracle.com/docs/cd/E19082-01/819-3620/index.html>
141
142       DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD
143           http://www.amazon.com/DTrace-Dynamic-Tracing-Solaris-FreeBSD/dp/0132091518/
144           <http://www.amazon.com/DTrace-Dynamic-Tracing-Solaris-
145           FreeBSD/dp/0132091518/>
146

AUTHORS

148       Shawn M Moore "sartak@gmail.com"
149
150
151
152perl v5.16.3                      2013-03-04                     PERLDTRACE(1)
Impressum