.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Devel::NYTProf::Core 3pm" .TH Devel::NYTProf::Core 3pm "2020-11-09" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Devel::NYTProf::Core \- load internals of Devel::NYTProf .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is not meant to be used directly. See Devel::NYTProf, Devel::NYTProf::Data, and Devel::NYTProf::Reader. .PP While it's not meant to be used directly, it is a handy place to document some internals. .SH "SUBROUTINE PROFILER" .IX Header "SUBROUTINE PROFILER" The subroutine profiler intercepts the \f(CW\*(C`entersub\*(C'\fR opcode which perl uses to invoke a subroutine, both \s-1XS\s0 subs (henceforth xsubs) and pure perl subs. .PP The following sections outline the way the subroutine profiler works: .SS "Before the subroutine call" .IX Subsection "Before the subroutine call" The profiler records the current time, the current value of cumulative_subr_secs (as initial_subr_secs), and the current cumulative_overhead_ticks (as initial_overhead_ticks). .PP The statement profiler measures time at the start and end of processing for each statement (so time spent in the profiler, writing to the file for example, is excluded.) It accumulates the measured overhead into the cumulative_overhead_ticks variable. .PP In a similar way, the subroutine profiler measures the \fIexclusive\fR time spent in subroutines and accumulates it into the cumulative_subr_secs global. .SS "Make the subroutine call" .IX Subsection "Make the subroutine call" The call is made by executing the original perl internal code for the \&\f(CW\*(C`entersub\*(C'\fR opcode. .PP \fICalling a perl subroutine\fR .IX Subsection "Calling a perl subroutine" .PP If the sub being called is a perl sub then when the entersub opcode returns, back into the subroutine profiler, the subroutine has been 'entered' but the first opcode of the subroutine hasn't been executed yet. Crucially though, a new scope has been entered by the entersub opcode. .PP The subroutine profiler then pushes a destructor onto the context stack. The destructor is effectively just \fIinside\fR the sub, like a \f(CW\*(C`local\*(C'\fR, and so will be triggered when the subroutine exits by \fIany\fR means. Also, because it was the first thing push onto the context stack, it will be triggered \fIafter\fR any activity caused by the subroutines scope exiting. .PP When the destructor is invoked it calls a function which completes the measurement of the time spent in the sub (see below). .PP In this way the profiling of perl subroutines is very accurate and robust. .PP \fICalling an xsub\fR .IX Subsection "Calling an xsub" .PP If the sub being called is an xsub, then control doesn't return from the entersub opcode until the xsub has returned. The profiler detects this and calls the function which completes the measurement of the time spent in the xsub. .PP So far so good, but there's a problem. What if the xsub doesn't return normally but throws an exception instead? .PP In that case (currently) the profiler acts as if the xsub was never called. Time spent inside the xsub will be allocated to the calling sub. .SS "Completing the measurement" .IX Subsection "Completing the measurement" The function which completes the timing of a subroutine call does the following: .PP It calculates the time spent in the statement profiler: .PP .Vb 1 \& overhead_ticks = cumulative_overhead_ticks \- initial_overhead_ticks .Ve .PP and subtracts that from the total time spent 'inside' the subroutine: .PP .Vb 1 \& incl_subr_sec = (time now \- time call was made) \- overhead_ticks .Ve .PP That gives us an accurate \fIinclusive\fR time. To get the \fIexclusive\fR time it calculates the time spent in subroutines called from the subroutine call we're measuring: .PP .Vb 1 \& called_sub_secs = cumulative_subr_secs \- initial_subr_secs .Ve .PP and subtracts that from the incl_subr_sec: .PP .Vb 1 \& excl_subr_sec = incl_subr_sec \- called_sub_secs .Ve .PP To make that easier to follow, consider a call to a sub that calls no others. In that case cumulative_subr_secs remains unchanged during the call, so called_sub_secs is zero, and excl_subr_sec is the same as incl_subr_sec. .PP Finally, it adds the exclusive time to the cumulative exclusive time: .PP .Vb 1 \& cumulative_subr_secs += excl_subr_sec .Ve .SH "AUTHOR" .IX Header "AUTHOR" \&\fBTim Bunce\fR, and .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" .Vb 1 \& Copyright (C) 2008, 2009 by Tim Bunce. .Ve .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.