Movatterモバイル変換


[0]ホーム

URL:


perldtrace
(source,CPAN)
You are viewing the version of this documentation from Perl 5.22.1.View the latest version

CONTENTS

#NAME

perldtrace - Perl's support for DTrace

#SYNOPSIS

# dtrace -Zn 'perl::sub-entry, perl::sub-return { trace(copyinstr(arg0)) }'dtrace: description 'perl::sub-entry, perl::sub-return ' matched 10 probes# perl -E 'sub outer { inner(@_) } sub inner { say shift } outer("hello")'hello(dtrace output)CPU     ID                    FUNCTION:NAME  0  75915       Perl_pp_entersub:sub-entry   BEGIN  0  75915       Perl_pp_entersub:sub-entry   import  0  75922      Perl_pp_leavesub:sub-return   import  0  75922      Perl_pp_leavesub:sub-return   BEGIN  0  75915       Perl_pp_entersub:sub-entry   outer  0  75915       Perl_pp_entersub:sub-entry   inner  0  75922      Perl_pp_leavesub:sub-return   inner  0  75922      Perl_pp_leavesub:sub-return   outer

#DESCRIPTION

DTrace is a framework for comprehensive system- and application-level tracing. Perl is a DTraceprovider, meaning it exposes severalprobes for instrumentation. You can use these in conjunction with kernel-level probes, as well as probes from other providers such as MySQL, in order to diagnose software defects, or even just your application's bottlenecks.

Perl must be compiled with the-Dusedtrace option in order to make use of the provided probes. While DTrace aims to have no overhead when its instrumentation is not active, Perl's support itself cannot uphold that guarantee, so it is built without DTrace probes under most systems. One notable exception is that Mac OS X ships a/usr/bin/perl with DTrace support enabled.

#HISTORY

#5.10.1

Perl's initial DTrace support was added, providingsub-entry andsub-return probes.

#5.14.0

Thesub-entry andsub-return probes gain a fourth argument: the package name of the function.

#5.16.0

Thephase-change probe was added.

#5.18.0

Theop-entry,loading-file, andloaded-file probes were added.

#PROBES

#sub-entry(SUBNAME, FILE, LINE, PACKAGE)

Traces the entry of any subroutine. Note that all of the variables refer to the subroutine that is being invoked; there is currently no way to get ahold of any information about the subroutine'scaller from a DTrace action.

:*perl*::sub-entry {    printf("%s::%s entered at %s line %d\n",           copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg2);}
#sub-return(SUBNAME, FILE, LINE, PACKAGE)

Traces the exit of any subroutine. Note that all of the variables refer to the subroutine that is returning; there is currently no way to get ahold of any information about the subroutine'scaller from a DTrace action.

:*perl*::sub-return {    printf("%s::%s returned at %s line %d\n",           copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg2);}
#phase-change(NEWPHASE, OLDPHASE)

Traces changes to Perl's interpreter state. You can internalize this as tracing changes to Perl's${^GLOBAL_PHASE} variable, especially since the values forNEWPHASE andOLDPHASE are the strings that${^GLOBAL_PHASE} reports.

:*perl*::phase-change {    printf("Phase changed from %s to %s\n",        copyinstr(arg1), copyinstr(arg0));}
#op-entry(OPNAME)

Traces the execution of each opcode in the Perl runloop. This probe is fired before the opcode is executed. When the Perl debugger is enabled, the DTrace probe is firedafter the debugger hooks (but still before the opcode itself is executed).

:*perl*::op-entry {    printf("About to execute opcode %s\n", copyinstr(arg0));}
#loading-file(FILENAME)

Fires when Perl is about to load an individual file, whether fromuse,require, ordo. This probe fires before the file is read from disk. The filename argument is converted to local filesystem paths instead of providingModule::Name-style names.

:*perl*:loading-file {    printf("About to load %s\n", copyinstr(arg0));}
#loaded-file(FILENAME)

Fires when Perl has successfully loaded an individual file, whether fromuse,require, ordo. This probe fires after the file is read from disk and its contents evaluated. The filename argument is converted to local filesystem paths instead of providingModule::Name-style names.

:*perl*:loaded-file {    printf("Successfully loaded %s\n", copyinstr(arg0));}

#EXAMPLES

#Most frequently called functions
# dtrace -qZn 'sub-entry { @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END {trunc(@, 10)}'Class::MOP::Attribute::slots                                    400Try::Tiny::catch                                                411Try::Tiny::try                                                  411Class::MOP::Instance::inline_slot_access                        451Class::MOP::Class::Immutable::Trait:::around                    472Class::MOP::Mixin::AttributeCore::has_initializer               496Class::MOP::Method::Wrapped::__ANON__                           544Class::MOP::Package::_package_stash                             737Class::MOP::Class::initialize                                  1128Class::MOP::get_metaclass_by_name                              1204
#Trace function calls
# dtrace -qFZn 'sub-entry, sub-return { trace(copyinstr(arg0)) }'0  -> Perl_pp_entersub                        BEGIN0  <- Perl_pp_leavesub                        BEGIN0  -> Perl_pp_entersub                        BEGIN0    -> Perl_pp_entersub                      import0    <- Perl_pp_leavesub                      import0  <- Perl_pp_leavesub                        BEGIN0  -> Perl_pp_entersub                        BEGIN0    -> Perl_pp_entersub                      dress0    <- Perl_pp_leavesub                      dress0    -> Perl_pp_entersub                      dirty0    <- Perl_pp_leavesub                      dirty0    -> Perl_pp_entersub                      whiten0    <- Perl_pp_leavesub                      whiten0  <- Perl_dounwind                           BEGIN
#Function calls during interpreter cleanup
# dtrace -Zn 'phase-change /copyinstr(arg0) == "END"/ { self->ending = 1 } sub-entry /self->ending/ { trace(copyinstr(arg0)) }'CPU     ID                    FUNCTION:NAME  1  77214       Perl_pp_entersub:sub-entry   END  1  77214       Perl_pp_entersub:sub-entry   END  1  77214       Perl_pp_entersub:sub-entry   cleanup  1  77214       Perl_pp_entersub:sub-entry   _force_writable  1  77214       Perl_pp_entersub:sub-entry   _force_writable
#System calls at compile time
# 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) }'lseek                                                           310read                                                            374stat64                                                         1056
#Perl functions that execute the most opcodes
# dtrace -qZn 'sub-entry { self->fqn = strjoin(copyinstr(arg3), strjoin("::", copyinstr(arg0))) } op-entry /self->fqn != ""/ { @[self->fqn] = count() } END { trunc(@, 3) }'warnings::unimport                                             4589Exporter::Heavy::_rebuild_cache                                5039Exporter::import                                              14578

#REFERENCES

#DTrace Dynamic Tracing Guide

http://dtrace.org/guide/preface.html

#DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD

http://www.amazon.com/DTrace-Dynamic-Tracing-Solaris-FreeBSD/dp/0132091518/

#SEE ALSO

#Devel::DTrace::Provider

This CPAN module lets you create application-level DTrace probes written in Perl.

#AUTHORS

Shawn M Mooresartak@gmail.com

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp