⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch06_05.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>The Perl Profiler (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch06_04.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch06_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">6.5. The Perl Profiler</h2><p><a name="INDEX-1185" /><a name="INDEX-1186" /><a name="INDEX-1187" /><a name="INDEX-1188" />You can supply an alternative debuggerfor Perl to run by invoking your script with the<em class="emphasis">-d</em>:<em class="emphasis">module</em> switch. One ofthe most popular alternative debuggers for Perl is DProf, the Perlprofiler. As of this writing, DProf is not included with the standardPerl distribution, but it is expected to be included soon.</p><p>Meanwhile, you can fetch the Devel::DProf module from CPAN. Once ithas been properly installed on your system, you can use it to profilethe Perl program in <em class="emphasis">testpgm</em> by typing:</p><blockquote><pre class="code">perl -d:DProf testpgm</pre></blockquote><p>As your script runs, DProf gathers profile information. When thescript terminates, the profiler dumps the gathered information to afile called <em class="emphasis">tmon.out</em>. A<a name="INDEX-1189" />tool such as<em class="emphasis">dprofpp</em>, which is supplied with the Devel::DProfpackage, can be run to interpret the profile. If you run<em class="emphasis">dprofpp</em> against the<em class="emphasis">tmon.out</em> file created by DProf in the exampleabove, you'll see something like the following:</p><blockquote><pre class="code">% dprofpp tmon.outTotal Elapsed Time =    0.15 Seconds  User+System Time =     0.1 SecondsExclusive Times%Time Seconds     # Calls sec/call Name 30.0   0.030          1   0.0300 Text::Wrap::CODE(0x175f08) 20.0   0.020          1   0.0200 main::CODE(0xc7880) 20.0   0.020          1   0.0200 main::CODE(0xfe480) 10.0   0.010          1   0.0100 Text::Wrap::CODE(0x17151c) 10.0   0.010         10   0.0010 Text::Tabs::expand 0.00   0.000          1   0.0000 lib::CODE(0xfe5b8) 0.00   0.000          3   0.0000 Exporter::export 0.00   0.000          1   0.0000 Config::FETCH 0.00   0.000          1   0.0000 lib::import 0.00   0.000          1   0.0000 Text::Wrap::CODE(0x171438) 0.00   0.000          3   0.0000 vars::import 0.00   0.000          3   0.0000 Exporter::import 0.00   0.000          2   0.0000 strict::import 0.00   0.000          1   0.0000 Text::Wrap::CODE(0x171684) 0.00   0.000          1   0.0000 lib::CODE(0xfe4d4)</pre></blockquote><p>The output shows the 15 subroutines that use the most time; you canthen focus your efforts on those subroutines where tuning the codewill have the greatest effect. This output is an example of runningthe <em class="emphasis">dprofpp</em> command with the default option set.The following are the options that are available:</p><dl><dt><i><em class="emphasis">-a</em></i></dt><dd><a name="INDEX-1190" />Sorts output alphabetically bysubroutine name.</p></dd><dt><i><em class="emphasis">-E</em></i></dt><dd><a name="INDEX-1191" />Default. Displays all subroutine timesexclusive of child subroutine times.</p></dd><dt><i><em class="emphasis">-F</em></i></dt><dd><a name="INDEX-1192" />Forces generation of fake exittimestamps if <em class="emphasis">dprofpp</em> reports that the profileis garbled. Useful only if <em class="emphasis">dprofpp</em> determinesthat the profile is garbled due to missing exit timestamps.</p></dd><dt><i><em class="emphasis">-I</em></i></dt><dd>Displays all subroutine times inclusive of child subroutine times.</p></dd><dt><i><em class="emphasis">-l</em></i></dt><dd><a name="INDEX-1193" />Sorts by number of calls to thesubroutines.</p></dd><dt><i><em class="emphasis">-O cnt</em></i></dt><dd><a name="INDEX-1194" />Shows only <em class="emphasis">cnt</em>subroutines. The default is <tt class="literal">15</tt>.</p></dd><dt><i><em class="emphasis">-p script</em></i></dt><dd><a name="INDEX-1195" />Profiles the given script andinterprets its profile data, combining the usual two steps into one.</p></dd><dt><i><em class="emphasis">-Q</em></i></dt><dd><a name="INDEX-1196" />Used with <em class="emphasis">-p</em>,profiles the script and quits without interpreting the data.</p></dd><dt><i><em class="emphasis">-q</em></i></dt><dd><a name="INDEX-1197" />Does not display column headers.</p></dd><dt><i><em class="emphasis">-r</em></i></dt><dd><a name="INDEX-1198" />Displayselapsed real times.</p></dd><dt><i><em class="emphasis">-s</em></i></dt><dd><a name="INDEX-1199" />Displays system times only.</p></dd><dt><i><em class="emphasis">-T</em></i></dt><dd>Displays subroutine calls, but not subroutinestatistics<a name="INDEX-1200" />.</p></dd><dt><i><em class="emphasis">-t</em></i></dt><dd><a name="INDEX-1201" />Displayssubroutine call tree, but not subroutine statistics. A subroutinecalled multiple times is shown only once, with a repeat count.</p></dd><dt><i><em class="emphasis">-U</em></i></dt><dd><a name="INDEX-1202" />Displays unsorted output.</p></dd><dt><i><em class="emphasis">-u</em></i></dt><dd><a name="INDEX-1203" />Displays user times only.</p></dd><dt><i><em class="emphasis">-V</em></i></dt><dd><a name="INDEX-1204" />Prints the<em class="emphasis">dprofpp</em> version number.</p></dd><dt><i><em class="emphasis">-v</em></i></dt><dd><a name="INDEX-1205" />Sorts byaverage time spent in subroutines during each call.</p></dd><dt><i><em class="emphasis">-z</em></i></dt><dd><a name="INDEX-1206" />Default. Sorts by amount of user andsystem time used, so that the first few lines should show whichsubroutines are using the most time.<a name="INDEX-1207" /><a name="INDEX-1208" /><a name="INDEX-1209" /> </p></dd></dl><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch06_04.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch06_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">6.4. Customizing the Debugger</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">6.6. The perlbug Program</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -