<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>fosiki &#187; dtrace</title>
	<atom:link href="http://fosiki.com/blog/tag/dtrace/feed/" rel="self" type="application/rss+xml" />
	<link>http://fosiki.com/blog</link>
	<description>Sven Dowideit - Consulting Wiki Engineer</description>
	<lastBuildDate>Sat, 04 Feb 2012 14:10:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Blead Perl DTrace probes</title>
		<link>http://fosiki.com/blog/2008/02/15/blead-perl-dtrace-probes/</link>
		<comments>http://fosiki.com/blog/2008/02/15/blead-perl-dtrace-probes/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 07:16:26 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[opensolaris]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[require]]></category>
		<category><![CDATA[use]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2008/02/15/blead-perl-dtrace-probes/</guid>
		<description><![CDATA[I&#8217;ve ported my additional DTrace probes to blead perl, adding the following probes new-sv and del-sv to track Perl allocations, main-enter and main-exit to show what part of Perl&#8217;s execution phase we&#8217;re in load-module-entry and load-module-return to instrument use, require, do. I&#8217;ve also started to document the probes at http://wikis.sun.com/display/DTrace/perl+Provider To use the patch, get [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:c0a6cc7a492d3b300cf84f711bfe22d8c78cc11d'><p>I&#8217;ve <a href="http://distributedinformation.com/DTrace/">ported my additional DTrace</a> probes to blead perl, adding the following probes</p>
<ul>
<li>new-sv and del-sv to track Perl allocations,</li>
<li>main-enter and main-exit to show what part of Perl&#8217;s execution phase  we&#8217;re in</li>
<li>load-module-entry and load-module-return to instrument use, require, do.</li>
</ul>
<p>I&#8217;ve also started to document the probes at  <a href="http://wikis.sun.com/display/DTrace/perl+Provider" class="moz-txt-link-freetext">http://wikis.sun.com/display/DTrace/perl+Provider</a><br />
To use the patch,</p>
<ol>
<li>get bleadperl:
<ol>
<li> rsync -avz &#8211;exclude .svn/ &#8211;delete rsync://ftp.linux.activestate.com/perl-current/ bleadperl</li>
</ol>
</li>
<li>apply the patch:</li>
<li>cd bleadperl ; patch ../bleadperl.diff</li>
<li>run configure with dtrace enabled:
<ol>
<li>./Configure -de -Dusedevel -Dinc_version_list=none -Dprefix=/usr/local/bleadperl/ -Dldflags=-Dman3ext=3pm -Duseithreads -Duseshrplib -Uversiononly -Dusedtrace -Doptimize=-g</li>
</ol>
</li>
<li>make</li>
<li>make test</li>
<li>make install</li>
<li>run./perl.d (also found at <a href="http://distributedinformation.com/DTrace/">http://distributedinformation.com/DTrace/</a> ) and then run whatever Perl code you want to instrument.</li>
</ol>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F15%2Fblead-perl-dtrace-probes%2F&amp;title=Blead+Perl+DTrace+probes" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2008/02/15/blead-perl-dtrace-probes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Examining &#8216;use&#8217; and &#8216;require&#8217; with Perl Dtrace</title>
		<link>http://fosiki.com/blog/2008/02/13/examining-use-and-require-with-perl-dtrace/</link>
		<comments>http://fosiki.com/blog/2008/02/13/examining-use-and-require-with-perl-dtrace/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 08:51:59 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[twiki]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[opensolaris]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[require]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[use]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2008/02/13/examining-use-and-require-with-perl-dtrace/</guid>
		<description><![CDATA[Given the following functionally similar Perl modules, I was curious what the internal Perl differences in execution were. To recap &#8211; (from PerlDoc) Perl use &#8211; Imports some semantics into the current package from the named module &#8211; It is exactly equivalent to BEGIN { require Module; Module-&#62;import( LIST ); } Perl require &#8211; demands [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:dd5e8176b78d5e34c1265bd244d42b15712674ef'><p>Given the following functionally similar Perl modules, I was curious what the internal Perl differences in execution were.</p>
<p>To recap &#8211;  (from <a href="http://perldoc.perl.org/index-functions.html">PerlDoc</a>)</p>
<ul>
<li>Perl <em>use</em> &#8211; Imports some semantics into the current package from the named module &#8211;   It is exactly equivalent to
<pre class="verbatim">    BEGIN <span class="s">{</span> <a href="http://perldoc.perl.org/functions/require.html" class="l_k">require</a> <span class="w">Module</span><span class="sc">;</span> <span class="w">Module</span><span class="w">-&gt;import</span><span class="s">(</span> <span class="w">LIST</span> <span class="s">)</span><span class="sc">;</span> <span class="s">}</span></pre>
</li>
<li><span class="s">Perl <em>require</em> &#8211; </span>demands that a library file be included if it hasn&#8217;t already been included. There is pseudocode there to suggest that a previously required module (successful or not) would just return the previous result</li>
</ul>
<p>So given a set of modules that don&#8217;t define an import() function, one would expect that there would be little difference.</p>
<table valign="top" width="100%">
<tr>
<td>use Module</td>
<td>require Module</td>
</tr>
<tr>
<td>
<h3>main.pl</h3>
<p><code>use Module1;<br />
use </code><code>Module2;</code><br />
<code>use </code><code>Module1;      # add multiple use's to attempt to simulate having many use statements throughout many modules</code><br />
<code>use </code><code>Module1;</code><br />
<code>use </code><code>Module1;</code><br />
<code>use </code><code>Module1;</code><br />
<code>use </code><code>Module1;</code><br />
<code>use </code><code>Module1;</code><br />
<code><br />
BEGIN {<br />
print "::BEGIN\n";<br />
}</code></p>
<p>Module1::printit();</p>
<h3>Module1.pm</h3>
<p><code>package Module1;</code></p>
<p>BEGIN {<br />
my $test = &#8221;;</p>
<p>print &#8220;<code>Module1</code><code>::BEGIN\n";<br />
}<br />
sub printit {<br />
print "<code>Module1</code><code>::printit\n";</code></code></p>
<p>}<br />
1;</p>
<h3>Module2.pm</h3>
<p><code>package Module2;<br />
use Module1;</code></p>
<p>BEGIN {<br />
print &#8220;Module2::BEGIN\n&#8221;;<br />
}</p>
<p>sub printit {<br />
print &#8220;Module2::printit\n&#8221;;<br />
}</p>
<p>1;</td>
<td>
<h3>main.pl</h3>
<p><code>require</code><code> </code><code>Module1;</code><br />
<code>require MyOtherBegin;<br />
</code><code>require</code><code> </code><code>Module1;</code><br />
<code>require Module1;</code><br />
<code>require Module1;</code><br />
<code>require</code><code> </code><code>Module1;</code><br />
<code>require</code><code> </code><code>Module1;</code><br />
<code>require</code><code> </code><code>Module1;</code><br />
<code><br />
BEGIN {<br />
print "::BEGIN\n";<br />
}</code></p>
<p>MyBegin::printit();</p>
<h3>Module1.pm</h3>
<p><code>package Module1;</code></p>
<p>BEGIN {<br />
my $test = &#8221;;</p>
<p>print &#8220;<code>Module1</code><code>::BEGIN\n";<br />
}</code></p>
<p>sub printit {<br />
print &#8220;<code>Module1::printit\n";</code></p>
<p>}<br />
1;</p>
<h3>Module2.pm</h3>
<p><code>package Module2;<br />
require Module1;</code></p>
<p>BEGIN {<br />
print &#8220;Module2::BEGIN\n&#8221;;<br />
}</p>
<p>sub printit {<br />
print &#8220;Module2::printit\n&#8221;;<br />
}</p>
<p>1;</td>
</tr>
<tr>
<td>
<h3>program output</h3>
<p><code><br />
bash-3.00$ /usr/local/bin/perl main.pl<br />
Module1::BEGIN<br />
Module2::BEGIN<br />
::BEGIN<br />
Module1::printit<br />
</code></td>
<td>
<h3>program output</h3>
<p><code><br />
bash-3.00$ /usr/local/bin/perl main.pl<br />
::BEGIN<br />
Module1::BEGIN<br />
Module2::BEGIN<br />
Module1::printit<br />
</code></td>
</tr>
<tr>
<td>
<h3>dtrace output</h3>
<p><code><br />
== perl ==========================================================<br />
perl*::perl_alloc:main-enter<br />
perl*::perl_alloc:main-exit,  (0/0) (73 uS)<br />
perl*::perl_construct:main-enter<br />
perl*::perl_construct:main-exit,  (12/0) (543 uS)<br />
perl*::perl_parse:main-enter<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (254/2) (3 uS)<br />
--&gt; BEGIN, main.pl<br />
--&gt; BEGIN, Module1.pm<br />
&lt;-- BEGIN, Module1.pm (1/0) (102 uS)<br />
&lt;-- BEGIN, main.pl (60/38) (763 uS)<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module2)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module2)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module2.pm) (271/16) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (31/8) (2 uS)<br />
--&gt; BEGIN, Module2.pm<br />
&lt;-- BEGIN, Module2.pm (0/0) (4 uS)<br />
--&gt; BEGIN, Module2.pm<br />
&lt;-- BEGIN, Module2.pm (1/0) (11 uS)<br />
&lt;-- BEGIN, main.pl (67/47) (399 uS)<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (285/30) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (299/44) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (313/58) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
&gt;&gt; perl*::Perl_utilize:load-module-start (Module1)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (327/72) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_utilize:load-module-start (Module1)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (341/86) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_utilize:load-module-start (Module1)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (355/100) (2 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (0/0) (3 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (1/0) (10 uS)<br />
perl*::perl_parse:main-exit,  (373/132) (3464 uS)<br />
perl*::perl_run:main-enter<br />
--&gt; printit, Module1.pm<br />
&lt;-- printit, Module1.pm (0/0) (8 uS)<br />
perl*::perl_run:main-exit,  (0/0) (44 uS)<br />
perl*::perl_destruct:main-enter<br />
perl*::perl_destruct:main-exit,  (0/5) (20 uS)<br />
total, total (0/0) (4177 uS)Subs returned from:<br />
count  totaltime  mintime  avgtime  maxtime allocs  deallocs  func                 file<br />
1        8        8        8        8        0        0 printit              Module1.pm<br />
1      102      102      102      102        1        0 BEGIN                Module1.pm<br />
2       15        4        7       11        1        0 BEGIN                Module2.pm<br />
9     1190        3      132      763      128       85 BEGIN                main.pl<br />
count  totaltime  mintime  avgtime  maxtime allocs  deallocs  func                 file</code></p>
<p>allocations / deallocations (complete program):<br />
(515 /      222) perl</p>
<p>time to run perl:     6389 uS (time on CPU     4177 uS)</td>
<td>
<h3>dtrace output</h3>
<p><code><br />
== perl ==========================================================<br />
perl*::perl_alloc:main-enter<br />
perl*::perl_alloc:main-exit,  (0/0) (71 uS)<br />
perl*::perl_construct:main-enter<br />
perl*::perl_construct:main-exit,  (12/0) (583 uS)<br />
perl*::perl_parse:main-enter<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
&lt;&lt; perl*::Perl_ck_require:load-module-end (Module1.pm) (248/2) (3 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module2)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module2.pm) (252/2) (2 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (253/2) (1 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (254/2) (2 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (255/2) (1 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (256/2) (1 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (257/2) (2 uS)<br />
</code><code>&gt;&gt;</code><code> perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (258/2) (1 uS)<br />
--&gt; BEGIN, main.pl<br />
&lt;-- BEGIN, main.pl (1/0) (100 uS)<br />
perl*::perl_parse:main-exit,  (285/28) (2319 uS)<br />
perl*::perl_run:main-enter<br />
--&gt; BEGIN, Module1.pm<br />
&lt;-- BEGIN, Module1.pm (1/0) (14 uS)<br />
&gt;&gt; perl*::Perl_ck_require:load-module-start (Module1)<br />
</code><code>&lt;&lt;</code><code> perl*::Perl_ck_require:load-module-end (Module1.pm) (69/46) (2 uS)<br />
--&gt; BEGIN, Module2.pm<br />
&lt;-- BEGIN, Module2.pm (1/0) (10 uS)<br />
--&gt; printit, Module1.pm<br />
&lt;-- printit, Module1.pm (0/0) (8 uS)<br />
perl*::perl_run:main-exit,  (99/73) (772 uS)<br />
perl*::perl_destruct:main-enter<br />
perl*::perl_destruct:main-exit,  (0/13) (36 uS)<br />
total, total (0/0) (3814 uS)Subs returned from:<br />
count  totaltime  mintime  avgtime  maxtime allocs  deallocs  func                 file<br />
1        8        0        8        8        0        0 printit              Module1.pm<br />
1       10        0       10       10        1        0 BEGIN                Module2.pm<br />
1       14        0       14       14        1        0 BEGIN                Module1.pm<br />
1      100        0      100      100        1        0 BEGIN                main.pl<br />
count  totaltime  mintime  avgtime  maxtime allocs  deallocs  func                 file</code></p>
<p>allocations / deallocations (complete program):<br />
(399 /      114) perl</p>
<p>time to run perl:     5368 uS (time on CPU     3814 uS)</td>
</tr>
</table>
<p>The (1/0) tuples in braces are counts of allocations and deallocations by the Perl interpreter in in that enter-return pair, and execution times are all using DTrace&#8217;s vtimestamp, so are adjusted for time on CPU.</p>
<p>This suggests to me that Perl use and require suffer from the same problems that are encountered when using #include&#8217;s inside header files in large scale C and C++, a massive, un-realized parser mess, due to the re-importation of dependencies for the short term convenience of the developer.</p>
<p>While the require output appears better, none the less (looking at the source code for Perl_ck_require) it does more than a nop the second time around (at minimum, its doing a single allocation, and converting the Module name to a File.pm). It is interesting (scary really) that the use case has many more allocations than the require case, but I presume that has to do with the sillyness of importing code into the same namespace several times. That main.pl&#8217;s BEGIN is parsed&amp;allocated for 9 times, and Module2:BEGIN is parsed&amp;allocated for twice &#8211; is not really what I had in mind.</p>
<p>For those of us working with large scale Perl code (in my case TWiki and Catalyst) it seems that there is not enough clarity, and there are opposing concerns for users that run Perl directly, incurring the parse and allocate steps each time, and those using accelerators such as mod_perl and speedy_cgi, who essentially start at the main-run phase (I think).</p>
<p>Reducing the above examples by removing the use or requires from everywhere except the top level main.pl, still shows an unexpected side effect that the use case has 34 more allocations and 26 deallocations &#8211; but&#8230; there is less going on. So it is possible, that the inconvenience of needing to manage the Perl module loading at the top level might be worth while, at least until Perl is changed to do what the &#8216;manual&#8217; implies.</p>
<p>Another interesting side effect of replacing use with require, is that it moves the execution of the BEGIN from the parse phase to the execution phase &#8211; again reducing the effectiveness of Perl accelerators, but perhaps more inline with simplistic expectations.</p>
<p>Seems to me its time to move to bleadperl, and see if I can offer a fix.</p>
<p>The above tests are done using the dtrace enabled Perl 5.8.8  that is in my <a href="http://distributedinformation.com/svn/projects/dtrace/perl-5.8.8/">svn repository</a>.</p>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F02%2F13%2Fexamining-use-and-require-with-perl-dtrace%2F&amp;title=Examining+%26%238216%3Buse%26%238217%3B+and+%26%238216%3Brequire%26%238217%3B+with+Perl+Dtrace" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2008/02/13/examining-use-and-require-with-perl-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl DTrace load-module probe added &#8211; see what module is &#8216;do&#8217;, &#8216;use&#8217; or &#8216;require&#8217;d</title>
		<link>http://fosiki.com/blog/2008/01/12/perl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required/</link>
		<comments>http://fosiki.com/blog/2008/01/12/perl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 08:45:32 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2008/01/12/perl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required/</guid>
		<description><![CDATA[With the load-module probe, you can see at what point modules are loaded using &#8216;do&#8217;, &#8216;use&#8217; or &#8216;require&#8217;. The following code: #!/usr/local/bin/perl -w use strict; my $initial = "there once was a fish. Its feet were small"; my $post = func($initial); my $post2 = func($initial); print "$post\n"; do 'call2.pl'; #eval `cat call2.pl`; #use CGI::Session; sub [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:812a7c86da176fd418e8caf90dfeb28d8cc44ade'><p>With the load-module probe, you can see at what point modules are loaded using &#8216;do&#8217;, &#8216;use&#8217; or &#8216;require&#8217;.</p>
<p>The following code:</p>
<pre>#!/usr/local/bin/perl -w

use strict;

my $initial = "there once was a fish. Its feet were small";
my $post = func($initial);
my $post2 = func($initial);
print "$post\n";

do 'call2.pl';
#eval `cat call2.pl`;
#use CGI::Session;

sub func {
    $_[0] =~ s/there/There/;
    return $_[0];
}</pre>
<p>produces the following output:</p>
<pre> == call1.pl ==========================================================
  perl*::perl_alloc:main-enter
  perl*::perl_alloc:main-exit,  (0/0) (56 uS)
  perl*::perl_construct:main-enter
  perl*::perl_construct:main-exit,  (12/0) (624 uS)
  perl*::perl_parse:main-enter
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_utilize:load-module-start (strict)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_ck_require:load-module-start (strict)
&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; perl*::Perl_ck_require:load-module-end (strict.pm) (3 uS)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_ck_require:load-module-start (Carp)
&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; perl*::Perl_ck_require:load-module-end (Carp.pm) (2 uS)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_dofile:load-module-start (call2.pl)
&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; perl*::Perl_dofile:load-module-end (call2.pl) (3 uS)
  perl*::perl_parse:main-exit,  (299/46) (3069 uS)
  perl*::perl_run:main-enter
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_utilize:load-module-start (strict)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; perl*::Perl_ck_require:load-module-start (strict)
&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; perl*::Perl_ck_require:load-module-end (strict.pm) (3 uS)
  perl*::perl_run:main-exit,  (69/45) (533 uS)
  perl*::perl_destruct:main-enter
  perl*::perl_destruct:main-exit,  (0/3) (24 uS)</pre>
<p>see <a href="http://trac.distributedinformation.com/index.cgi/timeline">my perl5.8 trac</a> for the code -or grab <a href="http://distributedinformation.com/svn/projects/dtrace/perl-5.8.8/">the modified 5.8.8 source from svn</a></p>
<p>the  perl*::Perl_utilize:load-module-end probe is currently being worked on, and I really would like to see the actual parse component of the load separated out.</p>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2008%2F01%2F12%2Fperl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required%2F&amp;title=Perl+DTrace+load-module+probe+added+%26%238211%3B+see+what+module+is+%26%238216%3Bdo%26%238217%3B%2C+%26%238216%3Buse%26%238217%3B+or+%26%238216%3Brequire%26%238217%3Bd" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2008/01/12/perl-dtrace-load-module-probe-added-see-what-module-is-do-use-or-required/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DTrace shows that readable Perl code is fastest.</title>
		<link>http://fosiki.com/blog/2007/12/29/dtrace-shows-that-readable-perl-code-is-fastest/</link>
		<comments>http://fosiki.com/blog/2007/12/29/dtrace-shows-that-readable-perl-code-is-fastest/#comments</comments>
		<pubDate>Sat, 29 Dec 2007 11:16:05 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[calling conventions]]></category>
		<category><![CDATA[dtrace probes]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2007/12/29/dtrace-shows-that-readable-perl-code-is-fastest/</guid>
		<description><![CDATA[I always wondered why some people write unreadable Perl. The most common reason given seems to be &#8216;Its faster that way&#8217;. And so&#8230; using DTrace, and the extra probes (see the subversion repository with a patched Perl 5.8.8) I added, I thought I&#8217;d take a look. # dtrace -l &#124; grep perl 85614 perl1226 libperl.so [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:3276e6add95c70eb49839b8e4f8185a65c531a92'><p>I always wondered why some people write unreadable Perl. The most common reason given seems to be &#8216;Its faster that way&#8217;.</p>
<p>And so&#8230; using DTrace, and the extra probes (see the <a href="http://distributedinformation.com/svn/projects/dtrace/perl-5.8.8/">subversion repository with a patched Perl 5.8.8</a>) I added, I thought I&#8217;d take a look.</p>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
# dtrace -l | grep perl
85614   perl1226        libperl.so                      Perl_sv_free del_sv
85615   perl1226        libperl.so                   Perl_sv_replace del_sv
85616   perl1226        libperl.so                          perl_run main_enter
85617   perl1226        libperl.so                        perl_parse main_enter
85618   perl1226        libperl.so                     perl_destruct main_enter
85619   perl1226        libperl.so                    perl_construct main_enter
85620   perl1226        libperl.so                        perl_alloc main_enter
85621   perl1226        libperl.so                          perl_run main_exit
85622   perl1226        libperl.so                        perl_parse main_exit
85623   perl1226        libperl.so                     perl_destruct main_exit
85624   perl1226        libperl.so                    perl_construct main_exit
85625   perl1226        libperl.so                        perl_alloc main_exit
85626   perl1226        libperl.so                       Perl_sv_dup new_sv
85627   perl1226        libperl.so                      Perl_newSVrv new_sv
85628   perl1226        libperl.so                      Perl_newSVsv new_sv
85629   perl1226        libperl.so                  Perl_newRV_noinc new_sv
85630   perl1226        libperl.so                      Perl_newSVuv new_sv
85631   perl1226        libperl.so                      Perl_newSViv new_sv
85632   perl1226        libperl.so                      Perl_newSVnv new_sv
85633   perl1226        libperl.so                    Perl_vnewSVpvf new_sv
85634   perl1226        libperl.so               Perl_newSVpvn_share new_sv
85635   perl1226        libperl.so                     Perl_newSVhek new_sv
85636   perl1226        libperl.so                     Perl_newSVpvn new_sv
85637   perl1226        libperl.so                      Perl_newSVpv new_sv
85638   perl1226        libperl.so                 Perl_sv_newmortal new_sv
85639   perl1226        libperl.so                Perl_sv_mortalcopy new_sv
85640   perl1226        libperl.so                        Perl_newSV new_sv
85641   perl1226        libperl.so                      Perl_pp_sort sub-entry
85642   perl1226        libperl.so                   Perl_pp_dbstate sub-entry
85643   perl1226        libperl.so                  Perl_pp_entersub sub-entry
85644   perl1226        libperl.so                      Perl_pp_last sub-return
85645   perl1226        libperl.so                    Perl_pp_return sub-return
85646   perl1226        libperl.so                     Perl_dounwind sub-return
85647   perl1226        libperl.so                Perl_pp_leavesublv sub-return
85648   perl1226        libperl.so                  Perl_pp_leavesub sub-return</pre>
<p>Using these probes, we can write some &#8216;D&#8217; that tells us what Perl is doing at each of its phases &#8211; startup, parsing, execution, and cleanup.</p>
<p>First off, accessing function call parameters:</p>
<p>Given <a href="http://distributedinformation.com/svn/projects/dtrace/blog1/">3 essentially identical programs</a></p>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
#!/usr/local/bin/perl -Tw

use strict;

my $initial = "there once was a fish. Its feet were small";
my $post = func($initial);
print "$post\n";

sub func {
    $_[0] =~ s/there/There/;
    return $_[0];
}</pre>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
#!/usr/local/bin/perl -Tw

use strict;

my $initial = "there once was a fish. Its feet were small";
my $post = func($initial);
print "$post\n";

sub func {
    my ($val) = @_;
    $val =~ s/there/There/;
    return $val;
}</pre>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
#!/usr/local/bin/perl -Tw

use strict;

my $initial = "there once was a fish. Its feet were small";
my $post = func($initial);
print "$post\n";

sub func {
    my $val = shift;
    $val =~ s/there/There/;
    return $val;
}</pre>
<p>There is a myth that using $_[0] is faster, as it doesn&#8217;t create a temporary variable&#8230;<br />
Dtrace (using the <a href="http://distributedinformation.com/svn/projects/dtrace/blog1/perl.d">general perl stats gathering dtrace script</a>) shows this to be untrue:</p>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
== call1.pl ==========================================================
  perl*::perl_alloc:main_enter
  perl*::perl_alloc:main_exit,  (0/0) (53119 nS)
  perl*::perl_construct:main_enter
  perl*::perl_construct:main_exit,  (12/0) (564370 nS)
  perl*::perl_parse:main_enter
   --&gt; BEGIN, ./call1.pl
    --&gt; bits, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- bits, /usr/local/lib/perl5/5.8.8/strict.pm (3/2) (48060 nS)
    --&gt; import, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- import, /usr/local/lib/perl5/5.8.8/strict.pm (1/0) (15398 nS)
   &lt;-- BEGIN, ./call1.pl (160/80) (1025874 nS)
  perl*::perl_parse:main_exit,  (299/42) (2856399 nS)
  perl*::perl_run:main_enter
   --&gt; func, ./call1.pl
   &lt;-- func, ./call1.pl (1/0) (47723 nS)
  perl*::perl_run:main_exit,  (0/1) (265677 nS)
  perl*::perl_destruct:main_enter
  perl*::perl_destruct:main_exit,  (0/2) (20763 nS)
total, total (0/0) (3789064 nS)
== call2.pl ==========================================================
  perl*::perl_alloc:main_enter
  perl*::perl_alloc:main_exit,  (0/0) (53251 nS)
  perl*::perl_construct:main_enter
  perl*::perl_construct:main_exit,  (12/0) (509684 nS)
  perl*::perl_parse:main_enter
   --&gt; BEGIN, ./call2.pl
    --&gt; bits, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- bits, /usr/local/lib/perl5/5.8.8/strict.pm (3/2) (36748 nS)
    --&gt; import, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- import, /usr/local/lib/perl5/5.8.8/strict.pm (1/0) (9797 nS)
   &lt;-- BEGIN, ./call2.pl (160/80) (924250 nS)
  perl*::perl_parse:main_exit,  (299/38) (2545953 nS)
  perl*::perl_run:main_enter
   --&gt; func, ./call2.pl
   &lt;-- func, ./call2.pl (1/0) (42165 nS)
  perl*::perl_run:main_exit,  (0/1) (142393 nS)
  perl*::perl_destruct:main_enter
  perl*::perl_destruct:main_exit,  (0/2) (20851 nS)
total, total (0/0) (3301007 nS)
== call3.pl ==========================================================
  perl*::perl_alloc:main_enter
  perl*::perl_alloc:main_exit,  (0/0) (52927 nS)
  perl*::perl_construct:main_enter
  perl*::perl_construct:main_exit,  (12/0) (607783 nS)
  perl*::perl_parse:main_enter
   --&gt; BEGIN, ./call3.pl
    --&gt; bits, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- bits, /usr/local/lib/perl5/5.8.8/strict.pm (3/2) (37066 nS)
    --&gt; import, /usr/local/lib/perl5/5.8.8/strict.pm
    &lt;-- import, /usr/local/lib/perl5/5.8.8/strict.pm (1/0) (10171 nS)
   &lt;-- BEGIN, ./call3.pl (160/80) (924824 nS)
  perl*::perl_parse:main_exit,  (297/37) (2543981 nS)
  perl*::perl_run:main_enter
   --&gt; func, ./call3.pl
   &lt;-- func, ./call3.pl (1/0) (41833 nS)
  perl*::perl_run:main_exit,  (0/1) (140527 nS)
  perl*::perl_destruct:main_enter
  perl*::perl_destruct:main_exit,  (0/2) (20273 nS)
total, total (0/0) (3395310 nS)

allocations / deallocations:
     474 /      122 call3.pl
     476 /      123 call2.pl
     476 /      127 call1.pl</pre>
<p>Counting up the number of allocations and deallocations in the (0/1) output &#8211; and<br />
&#8220;&lt;&#8211; func, ./call2.pl (1/0) &#8221; is always the same&#8230; one allocation.</p>
<p>After all the test runs, I also print out the total allocations for the script,<br />
and it seems that the &#8220;my $val = shift&#8221; version is the most efficient -<br />
using two fewer allocations (apparently during the parse phase).</p>
<p>The deallocation count is interesting too &#8211; with &#8220;$_[0]&#8221; using 5 more deallocations during<br />
the parse phase and &#8220;my ($val) = @_;&#8221; using one more than the &#8220;my $val = shift&#8221; option.</p>
<p>In an attempt to reduce the allocations doesn&#8217;t seem to help &#8211; the following code resulting in 474 allocations,<br />
shift case, but with 3 extra deallocations, again in the parsing phase. Increasing the number of times that func<br />
is called only increases the benefits of using shift.</p>
<pre style="border-left: 1px solid black; font-size: 8pt; margin-left: 50px; padding-left: 10px">
#!/usr/local/bin/perl -Tw

use strict;

my $initial = "there once was a fish. Its feet were small";
$_ = $initial;
my $post = func();
print "$post\n";

sub func {
    s/there/There/;
    return $_;
}</pre>
<p>Interestingly, &#8220;my $val = shift&#8221;  is not only the fastest of the conventions tested, but it also seems that none of the conventions tested cause allocations at run time &#8211; they are all done during the parse phase. I guess I&#8217;ll have to construct a more complex case, using references / hashes &#8211; next time <img src='http://fosiki.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest.', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F29%2Fdtrace-shows-that-readable-perl-code-is-fastest%2F&amp;title=DTrace+shows+that+readable+Perl+code+is+fastest." title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2007/12/29/dtrace-shows-that-readable-perl-code-is-fastest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new begining for Perl and DTrace?</title>
		<link>http://fosiki.com/blog/2007/12/19/a-new-begining-for-perl-and-dtrace/</link>
		<comments>http://fosiki.com/blog/2007/12/19/a-new-begining-for-perl-and-dtrace/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 09:02:19 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2007/12/19/a-new-begining-for-perl-and-dtrace/</guid>
		<description><![CDATA[I&#8217;ve just created a subversion repository with perl 5.8.8, and the accumulated DTrace patches &#8211; including the using is-enabled to reduce the performance impact of the Probes when disabled. Byran and I, (and anyone else that would like to help) will be working slowly towards making Perl a first class DTrace citizen over the coming [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:15ef432a569f0c064cff42698398e10e35858dae'><p>I&#8217;ve just created a <a href="http://distributedinformation.com/svn/projects/dtrace/" title="Perl 5.8.8 with DTrace">subversion repository</a> with perl 5.8.8, and the accumulated DTrace patches &#8211; including the using is-enabled to reduce the performance impact of the Probes when disabled. <a href="http://mirrorshades.org/overflow/">Byran</a> and I, (and anyone else that would like to help) will be working slowly towards making Perl a first class DTrace citizen over the coming months. Next stop &#8211; <a href="http://gisle.aas.no/perl/illguts/">Perl Guts Illustrated</a></p>
<p>Of course, we&#8217;ll also port it all to Perl 5.10 &#8211; the 20th anniversary release <img src='http://fosiki.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F19%2Fa-new-begining-for-perl-and-dtrace%2F&amp;title=A+new+begining+for+Perl+and+DTrace%3F" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2007/12/19/a-new-begining-for-perl-and-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DTrace, Perl and TWiki &#8211; on Solaris</title>
		<link>http://fosiki.com/blog/2007/12/14/dtrace-perl-and-twiki-on-solaris/</link>
		<comments>http://fosiki.com/blog/2007/12/14/dtrace-perl-and-twiki-on-solaris/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 03:36:10 +0000</pubDate>
		<dc:creator>Sven Dowideit</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[twiki]]></category>

		<guid isPermaLink="false">http://distributedinformation.com/blog/2007/12/14/dtrace-perl-and-twiki-on-solaris/</guid>
		<description><![CDATA[I&#8217;ve been promising myself some time to try out DTrace on TWiki&#8217;s codebase for over a year. By following Bryan Allen&#8217;s instructions using Richard Dawe&#8217;s adaption of Alan Burlison&#8217;s work&#8230; I now have a Perl 5.8.8 with DTrace probes. Sounds great, except for one thing&#8230;. I now have to learn enough about DTrace to use [...]]]></description>
			<content:encoded><![CDATA[<div class='microid-mailto+http:sha1:7335ce60101f6180e82032e076d688628e1ad7e6'><p>I&#8217;ve been promising myself some time to try  out DTrace on TWiki&#8217;s codebase for over a year. By following <a href="http://mirrorshades.org/overflow/2007/10/perl_and_dtrace.shtml" title="Perl and DTrace">Bryan Allen&#8217;s</a><br />
instructions using <a href="http://richdawe.livejournal.com/">Richard Dawe&#8217;s</a> adaption of <a href="http://blogs.sun.com/alanbur/entry/dtrace_and_perl" title="DTrace and Perl">Alan Burlison&#8217;s</a> work&#8230; I now have a Perl 5.8.8 with DTrace probes.</p>
<p>Sounds great, except for one thing&#8230;. I now have to learn enough about DTrace to use it <img src='http://fosiki.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The patch that Alan and Richard have (or at least their DTrace scripts) seem to require a priori knowledge of the Perl process&#8217; pid&#8230; not something thats going to work out for what I want to do.</p>
<p>For a quick test, DTrace -c ./view -s /export/home/sven/src/dtrace/subs-tree.d does show the program flow.</p>
<p>The following is while running some perl scripts &#8211;  the 2 numbers are their pids.</p>
<pre># dtrace -l | grep -i perl</pre>
<pre>17803  perl17669        libperl.so                      Perl_pp_sort sub-entry</pre>
<pre>17804  perl17669        libperl.so                   Perl_pp_dbstate sub-entry</pre>
<pre>17805  perl17669        libperl.so                  Perl_pp_entersub sub-entry</pre>
<pre>17806  perl17669        libperl.so                      Perl_pp_last sub-return</pre>
<pre>17807  perl17669        libperl.so                    Perl_pp_return sub-return</pre>
<pre>17808  perl17669        libperl.so                     Perl_dounwind sub-return</pre>
<pre>17809  perl17669        libperl.so                Perl_pp_leavesublv sub-return</pre>
<pre>17810  perl17669        libperl.so                  Perl_pp_leavesub sub-return</pre>
<pre>88501  perl17760        libperl.so                      Perl_pp_sort sub-entry</pre>
<pre>88502  perl17760        libperl.so                   Perl_pp_dbstate sub-entry</pre>
<pre>88503  perl17760        libperl.so                  Perl_pp_entersub sub-entry</pre>
<pre>88504  perl17760        libperl.so                      Perl_pp_last sub-return</pre>
<pre>88505  perl17760        libperl.so                    Perl_pp_return sub-return</pre>
<pre>88506  perl17760        libperl.so                     Perl_dounwind sub-return</pre>
<pre>88507  perl17760        libperl.so                Perl_pp_leavesublv sub-return</pre>
<pre>88508  perl17760        libperl.so                  Perl_pp_leavesub sub-return</pre>
<p>so&#8230; first ignorant modification &#8211;  in subs-tree.d, it wants to trace perl$target:::sub-entry &#8211; change that to perl*:::sub-entry, and of course, it works exactly as I want &#8211; attaches to all subsequent perl process (running my dtrace-perl build) and tells me whats going on. The only caveat being that the DTrace script will only start if there is a Perl process running &#8211; the provider is obviously not persistent.</p>
<p>Brilliant!</p>
<p>Should be a fun Christmas holiday adventure &#8211; 410 pages of dtrace book, and a myriad of web pages to consume and digest.</p>
</div>
<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ffosiki.com%2Fblog%2F2007%2F12%2F14%2Fdtrace-perl-and-twiki-on-solaris%2F&amp;title=DTrace%2C+Perl+and+TWiki+%26%238211%3B+on+Solaris" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://fosiki.com/blog/2007/12/14/dtrace-perl-and-twiki-on-solaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.388 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-05 10:36:59 -->

