Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.8 KiB

  1. require 5.005_64;
  2. =head1 NAME
  3. Devel::DProf - a Perl code profiler
  4. =head1 SYNOPSIS
  5. perl5 -d:DProf test.pl
  6. =head1 DESCRIPTION
  7. The Devel::DProf package is a Perl code profiler. This will collect
  8. information on the execution time of a Perl script and of the subs in that
  9. script. This information can be used to determine which subroutines are
  10. using the most time and which subroutines are being called most often. This
  11. information can also be used to create an execution graph of the script,
  12. showing subroutine relationships.
  13. To profile a Perl script run the perl interpreter with the B<-d> debugging
  14. switch. The profiler uses the debugging hooks. So to profile script
  15. F<test.pl> the following command should be used:
  16. perl5 -d:DProf test.pl
  17. When the script terminates (or when the output buffer is filled) the
  18. profiler will dump the profile information to a file called
  19. F<tmon.out>. A tool like I<dprofpp> can be used to interpret the
  20. information which is in that profile. The following command will
  21. print the top 15 subroutines which used the most time:
  22. dprofpp
  23. To print an execution graph of the subroutines in the script use the
  24. following command:
  25. dprofpp -T
  26. Consult L<dprofpp> for other options.
  27. =head1 PROFILE FORMAT
  28. The old profile is a text file which looks like this:
  29. #fOrTyTwO
  30. $hz=100;
  31. $XS_VERSION='DProf 19970606';
  32. # All values are given in HZ
  33. $rrun_utime=2; $rrun_stime=0; $rrun_rtime=7
  34. PART2
  35. + 26 28 566822884 DynaLoader::import
  36. - 26 28 566822884 DynaLoader::import
  37. + 27 28 566822885 main::bar
  38. - 27 28 566822886 main::bar
  39. + 27 28 566822886 main::baz
  40. + 27 28 566822887 main::bar
  41. - 27 28 566822888 main::bar
  42. [....]
  43. The first line is the magic number. The second line is the hertz value, or
  44. clock ticks, of the machine where the profile was collected. The third line
  45. is the name and version identifier of the tool which created the profile.
  46. The fourth line is a comment. The fifth line contains three variables
  47. holding the user time, system time, and realtime of the process while it was
  48. being profiled. The sixth line indicates the beginning of the sub
  49. entry/exit profile section.
  50. The columns in B<PART2> are:
  51. sub entry(+)/exit(-) mark
  52. app's user time at sub entry/exit mark, in ticks
  53. app's system time at sub entry/exit mark, in ticks
  54. app's realtime at sub entry/exit mark, in ticks
  55. fully-qualified sub name, when possible
  56. With newer perls another format is used, which may look like this:
  57. #fOrTyTwO
  58. $hz=10000;
  59. $XS_VERSION='DProf 19971213';
  60. # All values are given in HZ
  61. $over_utime=5917; $over_stime=0; $over_rtime=5917;
  62. $over_tests=10000;
  63. $rrun_utime=1284; $rrun_stime=0; $rrun_rtime=1284;
  64. $total_marks=6;
  65. PART2
  66. @ 406 0 406
  67. & 2 main bar
  68. + 2
  69. @ 456 0 456
  70. - 2
  71. @ 1 0 1
  72. & 3 main baz
  73. + 3
  74. @ 141 0 141
  75. + 2
  76. @ 141 0 141
  77. - 2
  78. @ 1 0 1
  79. & 4 main foo
  80. + 4
  81. @ 142 0 142
  82. + & Devel::DProf::write
  83. @ 5 0 5
  84. - & Devel::DProf::write
  85. (with high value of $ENV{PERL_DPROF_TICKS}).
  86. New C<$over_*> values show the measured overhead of making $over_tests
  87. calls to the profiler These values are used by the profiler to
  88. subtract the overhead from the runtimes.
  89. The lines starting with C<@> mark time passed from the previous C<@>
  90. line. The lines starting with C<&> introduce new subroutine I<id> and
  91. show the package and the subroutine name of this id. Lines starting
  92. with C<+>, C<-> and C<*> mark entering and exit of subroutines by
  93. I<id>s, and C<goto &subr>.
  94. The I<old-style> C<+>- and C<->-lines are used to mark the overhead
  95. related to writing to profiler-output file.
  96. =head1 AUTOLOAD
  97. When Devel::DProf finds a call to an C<&AUTOLOAD> subroutine it looks at the
  98. C<$AUTOLOAD> variable to find the real name of the sub being called. See
  99. L<perlsub/"Autoloading">.
  100. =head1 ENVIRONMENT
  101. C<PERL_DPROF_BUFFER> sets size of output buffer in words. Defaults to 2**14.
  102. C<PERL_DPROF_TICKS> sets number of ticks per second on some systems where
  103. a replacement for times() is used. Defaults to the value of C<HZ> macro.
  104. C<PERL_DPROF_OUT_FILE_NAME> sets the name of the output file. If not set,
  105. defaults to tmon.out.
  106. =head1 BUGS
  107. Builtin functions cannot be measured by Devel::DProf.
  108. With a newer Perl DProf relies on the fact that the numeric slot of
  109. $DB::sub contains an address of a subroutine. Excessive manipulation
  110. of this variable may overwrite this slot, as in
  111. $DB::sub = 'current_sub';
  112. ...
  113. $addr = $DB::sub + 0;
  114. will set this numeric slot to numeric value of the string
  115. C<current_sub>, i.e., to C<0>. This will cause a segfault on the exit
  116. from this subroutine. Note that the first assignment above does not
  117. change the numeric slot (it will I<mark> it as invalid, but will not
  118. write over it).
  119. Mail bug reports and feature requests to the perl5-porters mailing list at
  120. F<E<lt>perl5-porters@perl.orgE<gt>>.
  121. =head1 SEE ALSO
  122. L<perl>, L<dprofpp>, times(2)
  123. =cut
  124. # This sub is needed for calibration.
  125. package Devel::DProf;
  126. sub NONESUCH_noxs {
  127. return $Devel::DProf::VERSION;
  128. }
  129. package DB;
  130. #
  131. # As of perl5.003_20, &DB::sub stub is not needed (some versions
  132. # even had problems if stub was redefined with XS version).
  133. #
  134. # disable DB single-stepping
  135. BEGIN { $single = 0; }
  136. # This sub is needed during startup.
  137. sub DB {
  138. # print "nonXS DBDB\n";
  139. }
  140. use XSLoader ();
  141. # Underscore to allow older Perls to access older version from CPAN
  142. $Devel::DProf::VERSION = '20000000.00_00'; # this version not authorized by
  143. # Dean Roehrich. See "Changes" file.
  144. XSLoader::load 'Devel::DProf', $Devel::DProf::VERSION;
  145. 1;