<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Not this... &#187; nytprof</title>
	<atom:link href="http://blog.timbunce.org/tag/nytprof/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.timbunce.org</link>
	<description>Listen. Reflect. Explore. Solve.</description>
	<lastBuildDate>Thu, 24 Dec 2009 23:16:13 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.timbunce.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/eb188a9f7199a98e44133dc454d3873b?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Not this... &#187; nytprof</title>
		<link>http://blog.timbunce.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.timbunce.org/osd.xml" title="Not this&#8230;" />
	<atom:link rel='hub' href='http://blog.timbunce.org/?pushpress=hub'/>
		<item>
		<title>NYTProf v3 &#8211; Worth the wait!</title>
		<link>http://blog.timbunce.org/2009/12/24/nytprof-v3-worth-the-wait/</link>
		<comments>http://blog.timbunce.org/2009/12/24/nytprof-v3-worth-the-wait/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 23:08:54 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=362</guid>
		<description><![CDATA[After more than six months, and more than a few technical hurdles, NYTProf v3 has been released at last.
In this post I&#8217;ll review the major changes and significant new features.
What&#8217;s new in Devel::NYTProf v3?

Treemap
The first big feature is a visualization of the exclusive time spent in subroutines represented as a treemap:

That&#8217;s a treemap of a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=362&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>After more than six months, and more than a few technical hurdles, NYTProf v3 has been released at last.</p>
<p>In this post I&#8217;ll review the major changes and significant new features.<span id="more-362"></span><br />
<h1>What&#8217;s new in Devel::NYTProf v3?<br />
</h1>
<h2>Treemap</h2>
<p>The first big feature is a visualization of the exclusive time spent in subroutines represented as a <a href="http://en.wikipedia.org/wiki/Treemap">treemap</a>:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/07/filename.png?w=770" alt="filename.png" border="0" width="770" height="550	" /></p>
<p>That&#8217;s a treemap of a profile of perlcritic 1.088. The colors don&#8217;t mean anything. They&#8217;re just used to visually group subroutines in the same package. (I&#8217;m not very happy with the colors but the <a href="http://thejit.org/">JIT toolkit</a> I&#8217;m using doesn&#8217;t make it easy to use an attractive colour range. It interpolates a value in RGB color space. It would be much better to interpolate the value in HSV color space.)</p>
<p>The treemap is interactive! If you click on a square then the treemap is redrawn &#8220;zoomed in&#8221; one package level &#8216;closer&#8217; to the package of the subroutine you clicked on.</p>
<h2>Subroutine Caller Tracking</h2>
<p>The subroutine profiler has been almost completely rewritten, yielding another major new feature. It now finds and records the name of the <em>calling</em> subroutine. (You might have assumed that NYTProf always did that. In fact it <em>guessed</em> based on the calling file and line number, and so was easily confused by nested subroutines and closures.) By properly tracking the calling subroutine NYTProf can now generate a more accurate call graph.</p>
<p>One immediate beneficiary is the nytprofcg utility (contributed by <a href="http://search.cpan.org/~clkao/">Chia-liang Kao</a>). nytprofcg reads NYTProf profile data and generates callgrind data for viewing via <a href="http://kcachegrind.sourceforge.net/html/Home.html">Kcachegrind</a>. The previous guessing behaviour limited the usefulness of nytprofcg. Now it works well, as you can see here: </p>
<p><img src="http://timbunce.files.wordpress.com/2009/07/zz4f06129a.png?w=799&#038;h=562" alt="ZZ4F06129A.png" border="0" width="799" height="562" /></p>
<p>I&#8217;ve not played with it much yet. If you do, <a href="http://groups.google.com/group/develnytprof-dev">let us know</a> how it works out for you!</p>
<p>The subroutine called <code>main::RUNTIME</code> in the image above is the fake name that NYTProf gives to &#8216;caller&#8217; of the main script code. Code run at compile time will have a top-level caller of <code>main::BEGIN</code>.</p>
<h2>BEGIN</h2>
<p>Speaking of <code>BEGIN</code>s, they&#8217;ve always been a problem because there can be many of them in a single package. Each <code>use</code> statement, for example, generates a <code>BEGIN</code> sub that&#8217;s immediately executed then discarded. Previously the data for all those <code>BEGIN</code>s was mashed together and so almost useless.</p>
<p>The NYTProf subroutine profiler now renames <code>BEGIN</code>s by appending <code>@<em>linenumber</em></code> to make them unique. A whole new level of detail is opened up by this change. (This, along with a few other new features, requires perl 5.10.1+ or 5.8.9+.)</p>
<h2>Goto</h2>
<p>NYTProf now handles <code>goto &amp;sub;</code> properly. That tail-call construct is commonly found at the end of <code>AUTOLOAD</code> subroutines&mdash;so it&#8217;s more common than you might think.</p>
<p>The calling and called subroutine call counts and timings are updated correctly. For the call graph, the destination subroutine appears to have been called by the subroutine that called the subroutine that executed the goto. In other words, if A calls B and B does a goto &amp;C, that call to C will show A as the caller. That fits the way goto &amp;sub works, and ensures inclusive and exclusive times make sense.</p>
<h2>Slow Opcode Profiling</h2>
<p>This is another major new feature. NYTProf can now profile the time spent executing certain opcodes (the lowest-level units of execution in the perl interpreter).</p>
<p>I originally envisaged adding the mechanism for opcodes that corresponded to system calls (read, write, mkdir, chdir etc.) and called the feature &#8217;sys ops&#8217;. Then I realised there were other perl opcodes that would be worth profiling. The main two being <code>match</code> (<code>m/.../</code>) and <code>subst</code> (<code>s/.../.../</code>). So now the NYTProf subroutine profiler can now profile time spent in regular expressions!</p>
<p>Here&#8217;s an example:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/zz1f7ce510.png?w=755&#038;h=235" alt="ZZ1F7CE510.png" border="0" width="755" height="235" /></p>
<p>The opcodes are given pseudo-subroutine names <em>in the package that invoked the opcode</em> with &#8220;<code>CORE:</code>&#8221; prepended to the opcode name. In the example above you can see  two instances of <code>CORE:match</code>. One accounting for matches performed in the <code>main::</code> package, and another accounting for matches performed in the <code>File::Find::</code> package. (They&#8217;re marked &#8216;xsub&#8217; above but I&#8217;ve changed that to &#8216;opcode&#8217; now.)</p>
<p>Profiling of &#8217;slowops&#8217;, as I&#8217;ve called them, is controlled by the <code>slowops=N</code> option. A value of 0 turns off slowop profiling. A value of 2 (the default) gives the behaviour shown above, with opcodes called in different packages being accounted for separately. A value of 1 will put all the slowops into a single package named &#8220;<code>CORE::</code>&#8220;.</p>
<h2>GraphViz</h2>
<p>Another spin-off from the work on call graphs: NYTProf now also outputs representations of the subroutine call graph as GraphViz <a href="http://en.wikipedia.org/wiki/DOT_language">dot language</a> files. These can be rendered by<br />
<a href="http://www.graphviz.org/">a variety of viewers</a>. I use <a href="http://www.pixelglow.com/graphviz/">GraphViz by pixelglow</a>.</p>
<p>Here&#8217;s a simple example showing the calling relationship between packages in a little demo script I use for testing:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/subs-callgraph.png?w=514&#038;h=282" alt="subs-callgraph.png" border="0" width="514" height="282" /></p>
<p>The dot file for that inter-package view is available as a link on the top-level index page of the report.</p>
<p>On the individual report pages for each source file there&#8217;s a link to another dot file. This one shows the calls into, out of, and between the subroutines in package(s) in that source file. For example, here&#8217;s the call graph for the subs in the File::Find module:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/call-graphviz-file-find-pm.png?w=682&#038;h=365" alt="call-graphviz-File-Find-pm.png" border="0" width="682" height="365" /></p>
<p>There are many things that could be improved with that graph, such as adding call counts. Overall though, I&#8217;m pretty happy with it.</p>
<h2>Report Format Changes</h2>
<p>There have been some changes to the main report columns:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/zz5dc6382a.png" alt="ZZ5DC6382A.png" border="0"/></p>
<p>There are two new columns, &#8220;Calls&#8221; and &#8220;Time in Subs&#8221;. They show the number of subroutine calls executed on that line, and the total time spent in those subroutines due to those calls. Both are color coded, <em>relative to the other values in the same columns</em>, using the same <a href="http://en.wikipedia.org/wiki/Median_absolute_deviation">Median Average Deviation</a> that&#8217;s used elsewhere.</p>
<p>To make room for the new columns, the column showing the average statement execution time has been removed (it wasn&#8217;t much use anyway) and the column headings tightened up. The average value, if you&#8217;re interested, is available as a tool-tip, as shown above.</p>
<h2>New Options</h2>
<p>A few new options have been added, including:</p>
<ul>
<li><code>sigexit=<em>S</em> </code> Some signals will abort a process leaving a corrupt profile data file. The <code>sigexit</code> option can be used to tell NYTProf to catch those signals and close the profile cleanly before exiting.
</li>
<li><code>forkdepth=<em>N</em> </code>When a process being profiled is forked the child process is also profiled. The <code>forkdepth=N</code> option can be used to limit the number of generations that are profiled. The default is -1 (all generations). A value of 0 effectively disables profiling of child processes.
</li>
<li><code>log=<em>F</em> </code>If you enable NYTProf trace output, via the <code>trace=<em>N</em></code> option, it&#8217;s normally written to stderr. The <code>log=<em>F</em> </code> can be used to write the log to a specific file instead.
</li>
</ul>
<h2>nytprofmerge</h2>
<p>As I mentioned above, when a profiled process forks, the child is also profiled, with the profile being written to a new file. So processes which have many children, like mod_perl, end up with many profile data files. Naturally many people have expressed a wish for NYTProf to be able to merge multiple profiles into a single report. Sadly no one has stepped up actually do the work, till now.</p>
<p><a href="http://www.ccl4.org/~nick/">Nicholas Clark</a>, who contributed the great <a href="http://blog.timbunce.org/2008/10/03/nytprof-204-gives-you-90-smaller-data-files/">zip compression</a> for v2.04 (and a major contributor to the perl core and pumpkin for the 5.8.2+ releases) has come up trumps again. NYTProf v3 includes a new nytprofmerge utility that&#8217;ll read multiple profiles and write out a new, merged, profile. It&#8217;s very new, and somewhat experimental, but answers a very real need. Give it a whirl and <a href="http://groups.google.com/group/develnytprof-dev">let us know</a> how it goes. </p>
<h2>Screencast</h2>
<p>I gave a talk on Devel::NYTProf at the (excellent) <a href="http://conferences.yapceurope.org/ipw2009">Italian Perl Workshop</a> in October. I covered both the features in version 3 and the phased approach I take to optimizing perl code. You can <a href="http://blip.tv/file/2840795">watch the screencast</a>.</p>
<h2>And finally</h2>
<p>For more information on the changes in Devel::NYTProf v3 you can <a href="http://search.cpan.org/~timb/Devel-NYTProf-3.00/Changes">read the Changes file</a>.</p>
<p>It&#8217;s <a href="http://en.wikipedia.org/wiki/Christmas_Eve">Christmas Eve</a> here in Ireland. After days, and nights, of hard frost the countryside is spectacularly encased in tiny ice crystals sparking in the bright sunshine. I&#8217;m delighted to have stumbled into working on NYTProf. It&#8217;s a great project at the intersection of two of my professional passions: performance and visualization. And I&#8217;m delighted to give you NYTProf v3 in time for <em>this</em> Christmas.</p>
<p>Enjoy!</p>
<p>Tim.</p>
<br />Posted in perl Tagged: nytprof <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=362&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/12/24/nytprof-v3-worth-the-wait/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/07/filename.png" medium="image">
			<media:title type="html">filename.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/07/zz4f06129a.png" medium="image">
			<media:title type="html">ZZ4F06129A.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/zz1f7ce510.png" medium="image">
			<media:title type="html">ZZ1F7CE510.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/subs-callgraph.png" medium="image">
			<media:title type="html">subs-callgraph.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/call-graphviz-file-find-pm.png" medium="image">
			<media:title type="html">call-graphviz-File-Find-pm.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/zz5dc6382a.png" medium="image">
			<media:title type="html">ZZ5DC6382A.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Can you help me generate an alpha channel gradient image?</title>
		<link>http://blog.timbunce.org/2009/08/31/can-you-help-me-generate-an-alpha-channel-gradient-image/</link>
		<comments>http://blog.timbunce.org/2009/08/31/can-you-help-me-generate-an-alpha-channel-gradient-image/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:19:48 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[nytprof]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=313</guid>
		<description><![CDATA[Here&#8217;s an extract from a treemap generated by the perl Devel::NYTProf profiler:

Notice the shading on the boxes? That&#8217;s done by setting the background color of the box to green, and also setting the background image to one that&#8217;s mostly transparent. The image doesn&#8217;t contain any color. It&#8217;s just an &#8216;alpha channel gradient&#8217; &#8212; in this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=313&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an extract from a treemap generated by the perl <a href="http://search.cpan.org/dist/Devel-NYTProf/">Devel::NYTProf</a> profiler:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/zz60011314.png?w=200&#038;h=200" alt="ZZ60011314.png" border="0" width="200" height="200" /></p>
<p>Notice the shading on the boxes? <span id="more-313"></span>That&#8217;s done by setting the background color of the box to green, and also setting the background image to one that&#8217;s mostly transparent. The image doesn&#8217;t contain <em>any</em> color. It&#8217;s just an &#8216;alpha channel gradient&#8217; &mdash; in this case a radial gradient that&#8217;s nearly fully transparent at the center and less transparent at the edges. It overlays the color and creates a visually pleasant effect. (I didn&#8217;t come up with this idea, I saw it used in <a href="http://thejit.org/Jit/Examples/Treemap/example3.html">one</a> of the <a href="http://thejit.org/home/">JIT</a> examples.)</p>
<p>Here&#8217;s an example of a transparent alpha channel gradient image (of course, this may not show up well as it&#8217;s mostly transparent :-)</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/gradient40.png?w=200&#038;h=200" alt="gradient40.png" border="0" width="200" height="200" /></p>
<p>The transparent image gets stretched to fit the box, as you can see above. That works fairly well but ideally I&#8217;d like to get a more &#8216;cushioned&#8217; effect with a &#8216;highlight&#8217;, like the illumination was coming from the top-left direction.</p>
<p>Something more like the boxes in this treemap from <a href="http://www.flickr.com/photos/schoschie/100056488/">schoschie</a>:<br /><img src="http://timbunce.files.wordpress.com/2009/04/82244d56-fa2c-4044-ae46-ee53b63861be.jpg?w=500&#038;h=398" alt="82244D56-FA2C-4044-AE46-EE53B63861BE.jpg" border="0" width="500" height="398" /><br />(Though if you look at that image carefully you&#8217;ll see that the location of the highlight isn&#8217;t consistent. I&#8217;m not sure what logic was used for that, or why.) </p>
<p>So anyway, I want to create a new alpha channel gradient image, but one where the gradient isn&#8217;t simply radial.</p>
<p>I&#8217;ve struggled with this in tools like <a href="http://www.flyingmeat.com/acorn/">Acorn</a> and <a href="http://seashore.sourceforge.net/">Seashore</a> but failed. Mostly, I imagine, because I&#8217;m very unfamiliar with the tools, and especially working with the alpha-channel in non-trivial ways. There seem to be very few resources that cover more than simple examples.</p>
<p>Here&#8217;s an image that contains a monochrome mask that gives a rough idea of what I&#8217;m looking for as an alpha channel image. Here darker represents less transparent:</p>
<p><img src="http://timbunce.files.wordpress.com/2009/08/square-gradient-mask.png?w=200&#038;h=200" alt="square gradient mask.png" border="0" width="200" height="200" /></p>
<p>As you can see, I want the bulk of the central space to be nearly fully-transparent, with a fully-transparent highlight near a top corner. The lower-level of transparency should be limited to a fairly sharp gradient near the edges of the square image. That should work well when stretched to fit the variously sized rectangles in the treemap.</p>
<p>So, can you walk me though generating a non-trivial transparent alpha channel gradient image in a tool like Acorn or Seashore? Or perhaps the simplest approach would be a command-line utility to convert a monochrome gradient like the one above into a pure alpha channel gradient. If there is such a thing, can you talk me though using that?</p>
<p>Of course none of this is <em>essential</em> to NYTProf, and I won&#8217;t hold up the next release for this. This is pure gloss &mdash; but sometimes gloss is important.</p>
<br />Posted in tech Tagged: image, nytprof <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=313&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/08/31/can-you-help-me-generate-an-alpha-channel-gradient-image/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/zz60011314.png" medium="image">
			<media:title type="html">ZZ60011314.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/gradient40.png" medium="image">
			<media:title type="html">gradient40.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/04/82244d56-fa2c-4044-ae46-ee53b63861be.jpg" medium="image">
			<media:title type="html">82244D56-FA2C-4044-AE46-EE53B63861BE.jpg</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/08/square-gradient-mask.png" medium="image">
			<media:title type="html">square gradient mask.png</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf v3 &#8211; a sneak peak</title>
		<link>http://blog.timbunce.org/2009/08/07/nytprof-v3-a-sneak-peak/</link>
		<comments>http://blog.timbunce.org/2009/08/07/nytprof-v3-a-sneak-peak/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 02:12:49 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[oscon]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[slideshare]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=301</guid>
		<description><![CDATA[I&#8217;ve had a great week at OSCON. The talks are excellent but the real value is in the relationships formed and renewed in the &#8220;hallway track&#8221;. I&#8217;m honoured and humbled to be able to call many great people my friends.
My talk on Devel::NYTProf seemed to go well. This year I covered not just NYTProf and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=301&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a great week at OSCON. The talks are excellent but the real value is in the relationships formed and renewed in the &#8220;hallway track&#8221;. I&#8217;m honoured and humbled to be able to call many great people my friends.</p>
<p>My <a href="http://en.oreilly.com/oscon2009/public/schedule/detail/7941">talk on Devel::NYTProf</a> seemed to go well. This year I covered not just NYTProf and the new features in v3 (not yet released) but also added a section on how to use NYTProf to optimize your perl code.</p>
<p>Here&#8217;s a quick summary, with links to the slides and screen-cast, and outline what&#8217;s still to be done before v3 gets released (getting closer by the day).<span id="more-301"></span>The first two-thirds of the talk covered general profiling topics and an overview of NYTProf v3. This was an updated and compressed version of the talk I gave last year.</p>
<p>The final third covered optimization techniques.</p>
<p>I began with stern warning against optimization unless there&#8217;s a clear need, followed by a selection of quotes, among which is the well known classic from <a href="http://en.wikipedia.org/wiki/Donald_Knuth">Donald Knuth</a>: &#8220;premature optimization is the root of all evil&#8221;. What few people remember is that that&#8217;s just a fragment of a more balanced statement:</p>
<blockquote><p><em>“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. <strong>Yet we should not pass up our opportunities in that critical 3%.</strong>”</em></p></blockquote>
<p>After getting an implicit nod from Donald I quoted <a href="http://en.wikipedia.org/wiki/Rob_Pike">Rob Pike</a> on the importance of measurement:</p>
<blockquote><p><em>“Bottlenecks occur in surprising places, so don&#8217;t try to second guess and put in a speed hack until you have </em>proven<em> that&#8217;s where the bottleneck is.”</em></p></blockquote>
<p>Then I outlined the sequence of steps I usually take when performance profiling and optimizing code. These were grouped into three phases: &#8220;Low Hanging Fruit&#8221;, &#8220;Deeper Changes&#8221;, and &#8220;Structural Changes&#8221;.</p>
<p>I&#8217;ve generated a <a href="http://assets.en.oreilly.com/1/event/27/State-of-the-art%20Profiling%20with%20Devel__NYTProf%20Presentation.pdf">PDF of the slides</a> and made it <a href="http://www.slideshare.net/Tim.Bunce/develnytprof-200907">available on slideshare.net</a>. I&#8217;ve also uploaded <a href="http://blip.tv/file/2396942">the 45 minute screencast</a> to <a href="http://timbunce.blip.tv/">my blip.tv channel</a>.</p>
<p>Let me know if you find them useful.</p>
<hr />
p.s. This was originally a large post highlighting features of NYTProf v3. I hate talking about vapourware and with every day that passes the code is getting closer to being ready. In the end I decided to split the post in two. The shiny goodness in v3 will get its own blog post when it&#8217;s released. Meanwhile the slides and screencast will give you a sneak peek.</p>
<br />Posted in perl Tagged: conference, nytprof, oscon, presentation, slideshare, video <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/301/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=301&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/08/07/nytprof-v3-a-sneak-peak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>Has NYTProf helped you? Tell me how&#8230;</title>
		<link>http://blog.timbunce.org/2009/06/05/has-nytprof-helped-you-tell-me-how/</link>
		<comments>http://blog.timbunce.org/2009/06/05/has-nytprof-helped-you-tell-me-how/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 21:24:06 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[oscon]]></category>
		<category><![CDATA[oscon2009]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=278</guid>
		<description><![CDATA[At OSCON this year1 I&#8217;m giving a &#8220;State-of-the-art Profiling with Devel::NYTProf&#8221; talk. It&#8217;ll be an update of the one I gave last year, including coverage of new features added since then (including, hopefully, two significant new features that are in development).
This year I&#8217;d like to spend some time talking about how interpret the raw information [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=278&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>At OSCON this year<sup><a href="#1">1</a></sup> I&#8217;m giving a &#8220;State-of-the-art Profiling with Devel::NYTProf&#8221; <a href="http://en.oreilly.com/oscon2009/public/schedule/detail/7941">talk</a>. It&#8217;ll be an update of the one I gave last year, including coverage of new features added since then (including, hopefully, two significant new features that are in development).</p>
<p>This year I&#8217;d like to spend some time talking about how interpret the raw information and using it to guide code changes. Approaches like common sub-expression elimination and moving invariant code out of loops are straight-forward. They&#8217;re &#8216;low hanging fruit&#8217; with no API changes involved. Good for a first-pass through the code.</p>
<p>Moving loops down into lower-level code is an example of a deeper change I&#8217;ve found useful. There are many more. I&#8217;d like to collect them to add to the talk and the NYTProf documentation.</p>
<p>So here&#8217;s a question for you: after looking at the NYTProf report, how did <em>you</em> identify what you needed to do to <em>fix</em> the problems?</p>
<p>I&#8217;m interested in your experiences. How you used NYTProf, how you interpreted the raw information NYTProf presented, and then, critically, how you decided what code changes to make to improve performance. What worked, what didn&#8217;t. The practice, not the theory. </p>
<p>Could you to take a moment to think back over the times you&#8217;ve used NYTProf, the testing strategy you&#8217;ve used, and the code changes you&#8217;ve made as a result? Ideally go back and review the diffs and commit comments.</p>
<p>Then send me an email &#8212; <em>tell me your story</em>!</p>
<p>The more detail the better! Ideally with actual code (or pseudo-code) snippets<sup><a href="#2">2</a></sup>.</p>
<hr />
<ol>
<li><a name="1"></a>OSCON is in San Jose this year, July 20-24th. You can use the code &#8216;os09fos&#8217; to get a 20% discount.
</li>
<li><a name="2"></a>Annotated diff&#8217;s would be greatly appreciated. I&#8217;ll give credit for any examples used, naturally, and I&#8217;ll happily anonymize any code snippets that aren&#8217;t open source.
</li>
</ol>
<br />Posted in perl Tagged: nytprof, oscon, oscon2009, perl <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=278&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/06/05/has-nytprof-helped-you-tell-me-how/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>Generate Treemaps for HTML from Perl, please.</title>
		<link>http://blog.timbunce.org/2009/04/04/generate-treemaps-for-html-from-perl-please/</link>
		<comments>http://blog.timbunce.org/2009/04/04/generate-treemaps-for-html-from-perl-please/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 11:55:35 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=258</guid>
		<description><![CDATA[Seeing this video of treemap for perlcritic memory usage reminded me of something&#8230;
I&#8217;d really like to be able to use treemaps in NYTProf reports to visualize the time spent in different parts, and depths, of the package namespace hierarchy. Currently that information is reported in a series of tables.
A much better interface could be provided [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=258&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Seeing <a href="http://www.youtube.com/watch?v=etYau_Xf9AM">this video</a> of treemap for perlcritic memory usage reminded me of something&#8230;</p>
<p>I&#8217;d <em>really</em> like to be able to use <a href="http://en.wikipedia.org/wiki/Treemap">treemaps</a> in <a href="http://blog.timbunce.org/tag/nytprof/">NYTProf</a> reports to visualize the time spent in different parts, and depths, of the package namespace hierarchy. Currently that information is <a href="http://blog.timbunce.org/2009/02/15/nytprof-208-better-faster-more-cuddly/">reported in a series of tables</a>.</p>
<p>A much better interface could be provided by treemaps. Ideally allowing the user to drill-down into deeper levels of the package namespace hierarchy. (It needn&#8217;t be <a href="http://www.youtube.com/watch?v=lQ5kiMwVtUY">this flashy</a>, just 2D would be fine :-)</p>
<p>In case you&#8217;re not familiar with them, treemaps are a great way to visualise hierarchical data. Here&#8217;s an example treemap of the disk space used by the files in a directory tree (from <a href="http://www.flickr.com/photos/schoschie/100056488/">schoschie</a>) <img src="http://timbunce.files.wordpress.com/2009/04/82244d56-fa2c-4044-ae46-ee53b63861be.jpg?w=500&#038;h=398" alt="82244D56-FA2C-4044-AE46-EE53B63861BE.jpg" border="0" width="500" height="398" /></p>
<p>Perl already has a <a href="http://search.cpan.org/dist/Treemap/">Treemap</a> module, which can generate treemap images via the <a href="http://search.cpan.org/perldoc?Imager">Imager</a> module. Treemap is designed to support more output formats by sub-classing.</p>
<p>I guess it wouldn&#8217;t be hard to write a sub-class to generate HTML client-side <a href="http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.6">image map</a> data along with the image, so clicks on the image could be used to drill-down into treemaps that have more detail of the specific area that was clicked on.</p>
<p>More interesting, and more flexible, would be a sub-class to generate the treemap as a Scalable Vector Graphics diagram using the <a href="http://search.cpan.org/dist/SVG/">SVG</a> module (and <a href="http://search.cpan.org/search?query=svg&amp;mode=dist">others</a>).</p>
<p>I&#8217;m not going to be able to work on either of those ideas anytime soon.</p>
<p>Any volunteers?</p>
<br />Posted in perl Tagged: nytprof, perl, visualization <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=258&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/04/04/generate-treemaps-for-html-from-perl-please/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/04/82244d56-fa2c-4044-ae46-ee53b63861be.jpg" medium="image">
			<media:title type="html">82244D56-FA2C-4044-AE46-EE53B63861BE.jpg</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf 2.09 &#8211; now handles modules using AutoLoader, like POSIX and Storable</title>
		<link>http://blog.timbunce.org/2009/03/30/nytprof-209-now-handles-modules-using-autoloader-like-posix-and-storable/</link>
		<comments>http://blog.timbunce.org/2009/03/30/nytprof-209-now-handles-modules-using-autoloader-like-posix-and-storable/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 08:36:48 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=247</guid>
		<description><![CDATA[I&#8217;ve uploaded Devel::NYTProf 2.09 to CPAN.
If you&#8217;re using VMS the big news is that Peter (Stig) Edwards has contributed patches that enable NYTProf to work on VMS. Yeah! Thanks Peter.
For the rest of us there&#8217;s only one significant new feature in this release: NYTProf now includes a heuristic (that&#8217;s geek for &#8220;it&#8217;ll be wrong sometimes&#8221;) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=247&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve uploaded Devel::NYTProf 2.09 to CPAN.</p>
<p>If you&#8217;re using VMS the big news is that Peter (Stig) Edwards has contributed patches that enable NYTProf to work on VMS. Yeah! Thanks Peter.</p>
<p>For the rest of us there&#8217;s only one significant new feature in this release: NYTProf now includes a heuristic (that&#8217;s geek for &#8220;it&#8217;ll be wrong sometimes&#8221;) to handle modules using <a href="http://search.cpan.org/dist/AutoLoader/">AutoLoader</a>. The most common of which are Storable and POSIX. You may have encountered a warning like this when running nytprofhtml:</p>
<p>  <code>Unable to open '/../../lib/Storable.pm' for reading: No such file or directory</code></p>
<p>It&#8217;s a symptom of a deeper problem caused by <a href="http://search.cpan.org/perldoc?AutoSplit">AutoSplit</a>, the companion to AutoLoader. The details of the cause, effect, and fix aren&#8217;t worth going into now. If you&#8217;re interested you can read my <a href="http://groups.google.com/group/develnytprof-dev/tree/browse_frm/thread/2de2aecf1d5b153d/db48188f787b85d4?rnum=1&amp;q=Storable.pm&amp;_done=%2Fgroup%2Fdevelnytprof-dev%2Fbrowse_frm%2Fthread%2F2de2aecf1d5b153d%2F0f7ecccaca93b23d%3Flnk%3Dgst%26q%3DStorable.pm%26#doc_0f7ecccaca93b23d">summary</a> to the mailing list.</p>
<p>The upshot is that NYTProf now reports times for autoloaded subs as if the sub was part of the parent module. Just what you want. Time spent in the AUTOLOAD&#8217;er sub is also reported, naturally.</p>
<p>There is a small chance that the heuristic will pick the wrong &#8216;parent&#8217; module file for the autoloaded subroutine file. That can happen if there are other modules that use the same name for the last portion of the package name (e.g., Bar::Foo and Baz::Foo). If it ever happens to you, please let me know. Ideally with a small test case.</p>
<p>The list of changes can be found <a href="http://search.cpan.org/~timb/Devel-NYTProf-2.09/Changes#Changes_in_Devel::NYTProf_2.09_(svn_r733)_29th_March_2009">here</a> (or <a href="http://code.google.com/p/perl-devel-nytprof/source/list">here</a> if you&#8217;re a detail fanatic).</p>
<p>One other particularly notable item is that the <code>savesrc</code> option wasn&#8217;t working reliably. Thanks to Andy Grundman providing a good test case, that&#8217;s now been fixed.</p>
<p>Enjoy!</p>
<br />Posted in perl Tagged: nytprof, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/247/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=247&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/03/30/nytprof-209-now-handles-modules-using-autoloader-like-posix-and-storable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf screencast from the 2008 London Perl Workshop</title>
		<link>http://blog.timbunce.org/2009/02/25/nytprof-screencast-from-the-2008-london-perl-workshop/</link>
		<comments>http://blog.timbunce.org/2009/02/25/nytprof-screencast-from-the-2008-london-perl-workshop/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:09:21 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=234</guid>
		<description><![CDATA[I&#8217;ve uploaded the screencast of my NYTProf talk at the London Perl Workshop in November 2008.
It&#8217;s based on a not-quite-2.08 version and includes some coverage of an early draft of the &#8216;timings per rolled-up package name&#8217; feature I discussed previously.
It also shows how and why anonymous subroutines, defined at the same line of different executions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=234&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve uploaded the <a href="http://blip.tv/file/1812013">screencast of my NYTProf talk</a> at the <a href="http://conferences.yapceurope.org/lpw2008/talk/1673">London Perl Workshop</a> in November 2008.</p>
<p>It&#8217;s based on a not-quite-2.08 version and includes some coverage of an early draft of the &#8216;timings per rolled-up package name&#8217; feature I <a href="http://blog.timbunce.org/2009/02/15/nytprof-208-better-faster-more-cuddly/">discussed previously</a>.</p>
<p>It also shows how and why anonymous subroutines, defined at the same line of different executions of the same string eval, get &#8216;merged&#8217;.</p>
<p>The demos use perlcritic and Moose code. It also includes a nice demonstration showing NYTProf highlighting a performance problem with File::Spec::Unix when called using Path::Class::Dir objects.</p>
<p>It&#8217;s 36 minutes long, including a good Q&amp;A session at the end (wherein a market rate for performance improvements is established). Enjoy.</p>
<br />Posted in perl Tagged: nytprof, performance, perl <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=234&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/02/25/nytprof-screencast-from-the-2008-london-perl-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf 2.08 &#8211; better, faster, more cuddly</title>
		<link>http://blog.timbunce.org/2009/02/15/nytprof-208-better-faster-more-cuddly/</link>
		<comments>http://blog.timbunce.org/2009/02/15/nytprof-208-better-faster-more-cuddly/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 22:06:45 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=227</guid>
		<description><![CDATA[I&#8217;ve just released NYTProf 2.08 to CPAN, some three and a half months after 2.07.
If you&#8217;ve been profiling large applications then the first difference you&#8217;ll notice is that the new version generates reports much faster.
The next thing you may notice is that statement timings are now nicely formatted with units. Gisle Aas contributed the formatting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=227&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released NYTProf 2.08 to CPAN, some three and a half months after 2.07.</p>
<p>If you&#8217;ve been profiling large applications then the first difference you&#8217;ll notice is that the new version generates reports <em>much</em> faster.</p>
<p><img src="http://timbunce.files.wordpress.com/2009/02/nytprof-208-timings1.png?w=326&#038;h=201" alt="NYTProf 2.08 timings.png" border="0" width="326" height="201" align="left" />The next thing you may notice is that statement timings are now nicely formatted with units. Gisle Aas contributed the formatting code for 2.07 but I had to do some refactoring to get it working for the statement timings.</p>
<p>Another nice refinement is that hovering over a time will show a tool-tip with the time expressed as a percentage of the overall runtime.</p>
<p>Almost all <em>the tables are now sortable</em>. I used <a href="http://jquery.com/">jQuery</a> and the <a href="http://tablesorter.com">tablesorter</a> plugin for that. I&#8217;ve not added any fancy buttons, just click on a table heading to sort by that column. You&#8217;ll see a little black arrow to show the column is sorted. (You can hold the shift key down to add second and third columns to the sort order.)</p>
<p>A profiler isn&#8217;t much use if it&#8217;s not accurate. NYTProf now has tests for correct handling of times for string evals within string evals. In fact the handling of string evals got a big overhaul for this version as part of ongoing improvements in the underlying data model. I&#8217;m working towards being able to show annotated performance reports for the <em>contents of string evals</em>. It&#8217;s not there yet, but definitely getting closer.</p>
<p>A related feature is the new <code>savesrc=1</code> option. When enabled, with a recent version of perl, the source code for each source file is written into the profile data file. That makes the profile self-contained and, significantly, means that accurate reports can be generated even after the original source files have been modified.</p>
<p>Another new option is <code>optimize=0</code>. You can use it to disable the <a href="http://www.google.com/search?q=perl+optimizer">perl optimizer</a>. That can be worth doing if the statement timings, or counts, for some chunk of code seem odd and you suspect that the perl optimizer has rewritten it.</p>
<p>The final new feature noted in the NYTProf 2.08 Changes file is that it&#8217;s now possible to generate multiple profile data files from a single application. Since v2.0 you could call <code>DB::disable_profile()</code> and <code>DB::enable_profile()</code> to control profiling at runtime. Now you can pass an optional filename to <code>enable_profile</code> to make it close the previous profile and open a new one. I imagine this would be most useful in long running applications where you&#8217;d leave profiling disabled (using the <code>start=none</code> option) and then call <code>enable_profile</code> and <code>disable_profile</code> around some specific code in specific situations &#8211; like certain requests to a mod_perl app.</p>
<p>There&#8217;s one more new feature that I&#8217;ve just realised I&#8217;d forgotten to add to the Changes file before the release: Timings per rolled-up package name. What&#8217;s that? Well, it&#8217;s probably easiest to show you&#8230;</p>
<p>These images are taken from a profile of <a href="http://search.cpan.org/perldoc?perlcritic">perlcritic</a>. Each shows the time spent exclusively in subroutines belonging to a certain package <em>and any packages below it</em>. Hovering over a time gives the percentage, so I can see that the 57.3s spent in the 36 PPI packages accounted for 42% of the runtime.</p>
<p><img src="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg1.png?w=517&#038;h=321" alt="NYTProf 2.08 pkg1.png" border="0" width="517" height="321" /></p>
<p>This gives you a quick overview for large (wide) codebases that would be hard to get in any other way.</p>
<p>Tables are generated for upto five levels of package name hierarchy, so you can drill-down to finer levels of detail.</p>
<p><img src="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg2.png?w=530&#038;h=322" alt="NYTProf 2.08 pkg2.png" border="0" width="530" height="322" /></p>
<p>&nbsp;</p>
<p><img src="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg3.png?w=650&#038;h=322" alt="NYTProf 2.08 pkg3.png" border="0" width="650" height="322" /></p>
<p>I can visualize a much better UI for this data than the series of tables nytprofhtml currently produces, but my limited free time and jQuery skills prevent me doing more. Patches welcome, naturally.</p>
<p>Enjoy!</p>
<p>p.s. I&#8217;ve a screencast from my NYTProf talk at the London Perl Workshop in November I hope to (finally) upload soon. It includes a demo of the package roll-up timing tables.</p>
<br />Posted in perl Tagged: nytprof, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/227/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=227&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/02/15/nytprof-208-better-faster-more-cuddly/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/02/nytprof-208-timings1.png" medium="image">
			<media:title type="html">NYTProf 2.08 timings.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg1.png" medium="image">
			<media:title type="html">NYTProf 2.08 pkg1.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg2.png" medium="image">
			<media:title type="html">NYTProf 2.08 pkg2.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2009/02/nytprof-208-pkg3.png" medium="image">
			<media:title type="html">NYTProf 2.08 pkg3.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Can you reproduce this NYTProf failure?</title>
		<link>http://blog.timbunce.org/2009/01/28/can-you-reproduce-this-nytprof-failure/</link>
		<comments>http://blog.timbunce.org/2009/01/28/can-you-reproduce-this-nytprof-failure/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:24:12 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=215</guid>
		<description><![CDATA[I&#8217;ve a new release of NYTProf ready to upload but I&#8217;m stuck.
The CPAN Testers service is reporting a failure on a number of systems but I can&#8217;t reproduce it locally or work out the cause.
Can you reproduce the failure with Devel::NYTProf 2.07_94? If so, could you give me remote access via ssh? (Or spare some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=215&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve a new release of NYTProf ready to upload but I&#8217;m stuck.</p>
<p>The CPAN Testers service is reporting a <a href="http://bbbike.radzeit.de/~slaven/cpantestersmatrix.cgi?dist=Devel-NYTProf%202.07_94">failure on a number of systems</a> but I can&#8217;t reproduce it locally or work out the cause.</p>
<p>Can you reproduce the failure with <a href="http://search.cpan.org/~timb/Devel-NYTProf-2.07_94/">Devel::NYTProf 2.07_94</a>? If so, could you give me remote access via ssh? (Or spare some time to investigate yourself &#8211; I&#8217;ll happily clue you in if you can reproduce the problem.)</p>
<p><em>Update</em>: No one could reproduce it. It seems that the failures was not what it appeared to be. A clue was that only one tester was affected. Devel-NYTProf-2.07_94.tar.gz unpacked itself into a directory called Devel-NYTProf-2.07. It seems that when using  CPANPLUS if the user had already got an old Devel-NYTProf-2.07 directory its contents got merged and tests would fail. I&#8217;m not convinced that&#8217;s the whole story, but Devel-NYTProf-2.07_95.tar.gz unpacked into a Devel-NYTProf-2.07_95 directory and didn&#8217;t run into the problem.</p>
<p><em>Update</em>: More usefully, Andreas made <a href="http://www.nntp.perl.org/group/perl.qa/2009/01/msg11895.html">my wish</a> come true by <a href="http://www.nntp.perl.org/group/perl.qa/2009/01/msg11907.html">pointing out</a> the &#8211;solve parameter to the <a href="http://search.cpan.org/perldoc?ctgetreports">ctgetreports</a> utility in his <a href="http://search.cpan.org/dist/CPAN-Testers-ParseReport/">CPAN::Testers::ParseReports</a> distribution. It  &#8220;<em>tries to identify the best contenders for a blame using Statistics::Regression. [...] The function prints the [...]  top 3 candidates according to R^2 with their regression analysis.</em>&#8221; Cool.</p>
<br />Posted in perl Tagged: nytprof <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=215&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2009/01/28/can-you-reproduce-this-nytprof-failure/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>Crouching Tiger</title>
		<link>http://blog.timbunce.org/2008/12/17/crouching-tiger/</link>
		<comments>http://blog.timbunce.org/2008/12/17/crouching-tiger/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 12:31:37 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[dashprofiler]]></category>
		<category><![CDATA[gofer]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[tigerlead]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=213</guid>
		<description><![CDATA[After almost exactly two years working for Shopzilla I&#8217;ve moved on.
I&#8217;ve enjoyed my time with Shopzilla, met some great people, and worked on some challenging problems. I&#8217;m especially grateful to them for giving me the opportunity to develop and release some very useful Open Source software: Gofer, DashProfiler, and especially NYTProf v2.
When I started with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=213&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>After almost exactly two years working for Shopzilla I&#8217;ve moved on.</p>
<p>I&#8217;ve enjoyed my time with Shopzilla, met some great people, and worked on some challenging problems. I&#8217;m especially grateful to them for giving me the opportunity to develop and release some very useful Open Source software: <a href="http://search.cpan.org/perldoc?DBD::Gofer">Gofer</a>, <a href="http://search.cpan.org/perldoc?DashProfiler">DashProfiler</a>, and especially <a href="http://search.cpan.org/perldoc?Devel::NYTProf">NYTProf v2</a>.</p>
<p>When I started with ValueClick back in 1999 it was a small company. Over the years I was with them it grew rapidly, both from within and via mergers. When I left in 2006 it had become a very large company. For me Shopzilla was always a very large company.</p>
<p>I <em>really</em> like to make a significant positive impact where I work. I believe I did that at ValueClick and Shopzilla, but it&#8217;s always easier at a smaller company. There&#8217;s far less inertia to overcome.</p>
<p>So I&#8217;m delighted to be working now at a small company with a great team, product, technology, approach, and growth: <a href="http://tigerlead.com/">TigerLead.com</a></p>
<p>I&#8217;m not keen on job titles, but I needed to put <em>something</em> on my <a href="http://www.linkedin.com/in/timbunce">LinkedIn profile</a>. After <a href="http://putthingsoff.com/dont-use-these-job-titles/">exploring</a> <a href="http://positivesharing.com/2007/12/who-cares-about-your-job-title-tell-me-what-you-do/">some</a> <a href="http://www.bullshitjob.com/titles.html">options</a> I settled on &#8220;Entropy Minimizer&#8221;!</p>
<p>I&#8217;m also delighted to be working with the <a href="http://www.postgresql.org/">PostgreSQL</a> database, at last, as I&#8217;ve not had a chance to work with it before. (Although I used to be good at tuning <a href="http://en.wikipedia.org/wiki/INGRES">Ingres</a>, the distant forerunner of PostgreSQL, back in the days when RDBMS were novel and we thought a 50MHz cpu was fast.)</p>
<br />Posted in life, software Tagged: dashprofiler, gofer, nytprof, postgresql, tigerlead <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=213&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/12/17/crouching-tiger/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf 2.07 &#8211; Even better, and now for Windows too</title>
		<link>http://blog.timbunce.org/2008/11/01/nytprof-207-even-better-and-now-for-windows-too/</link>
		<comments>http://blog.timbunce.org/2008/11/01/nytprof-207-even-better-and-now-for-windows-too/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 08:34:39 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=195</guid>
		<description><![CDATA[NYTProf development rolls on, with 2.07 being another significant release.

After the fold is a summary of highlights from the many improvements, with images and links for you reading pleasure.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=195&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>NYTProf development rolls on, with 2.07 being another significant release.</p>
<p>Here&#8217;s a summary of highlights from the <a href="http://search.cpan.org/~timb/Devel-NYTProf/Changes">many improvements</a>.</p>
<h2>Windows, at last</h2>
<p>Windows wizard <a href="http://search.cpan.org/~jdb/">Jan Dubois</a> has contributed patches that enable NYTProf to run on Windows. Many thanks Jan!</p>
<h2>Corrected Subroutine Total Time</h2>
<p>A significant error in time reported as spent in a subroutine has been fixed. It was showing the sum of the inclusive and exclusive time instead of just the inclusive time.</p>
<h2>String Evals</h2>
<p>One of NYTProf&#8217;s innovative features is tracking of subroutine calls <em>by calling location</em>. In earlier versions you couldn&#8217;t see calls made from within string evals. Now you can. Even for evals within evals:</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/11/nytprof-string-eval.png?w=777&#038;h=389" alt="NYTProf string eval.png" border="0" width="777" height="389" /></div>
<p>That&#8217;s a big step forward for profiling code that makes heavy use of evals.</p>
<p>(The use of the &micro; micro symbol is also new &#8211; part of some helpful interface polishing contributed by <a href="http://search.cpan.org/~gaas/">Gisle Aas</a>. They&#8217;re not used on the statement timings yet, but will be at some point.)</p>
<h2>Recursion</h2>
<p>Previously the &#8216;inclusive time&#8217; reported for a subroutine wasn&#8217;t useful for subroutines called recursively. The overall inclusive time included the inclusive time of nested calls, typically inflating it beyond usefulness.</p>
<p>Now the inclusive time only measures the inclusive time of the <em>outermost</em> calls. NYTProf now also tracks and reports the <em>maximum call depth</em> for each calling location.</p>
<h2>Disabling the Statement Profiler</h2>
<p>NYTProf started life as a statement profiler. I added a subroutine profiler later and was delighted with how well that worked out. The subroutine profiler is novel in a few ways and also extremely robust and efficient. Part of the efficiency comes from not streaming data to disk while the program is running. It accumulates the counts and timings in memory.</p>
<p>When profiling large and/or performance sensitive applications the costs of NYTProf&#8217;s statement profiler, in performance impact and disk space, can be prohibitive. So now I&#8217;ve added an option to disable the statement profiler. Setting the <code>stmts=0</code> option turns NYTProf into a very lightweight subroutine profiler.</p>
<h2>Caller Information for XSubs</h2>
<p>NYTProf reports time spent in subroutines broken down by calling location. It&#8217;s one of its key features. The caller details are embedded as comment annotation into the report for each perl source code file.</p>
<p>That has worked very well for perl subs, but there&#8217;s no natural home for XS subroutines because there was no source code file available to annotate.</p>
<p>There&#8217;s a partial solution included in NYTProf 2.07: XS subs that are in the same package as profiled perl subs, get annotated subroutine &#8217;stubs&#8217; appended to the report for the corresponding perl source file.</p>
<p>It works quite well, in particular the common UNIVERSAL methods get annotated:</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/11/nytprof-xsub-callers.png?w=756&#038;h=114" alt="NYTProf xsub callers.png" border="0" width="756" height="114" /></div>
<p>Also, now these subs have a place in the reports, any references to them are hyper links, naturally.</p>
<p>Sadly it doesn&#8217;t work so well for packages that don&#8217;t contain any perl subs, like <code>DBI::st</code>. I plan to add per-package report pages for them in a future release.</p>
<h2>Clock Docs</h2>
<p>I&#8217;ve greatly expanded the <a href="http://search.cpan.org/~timb/Devel-NYTProf/lib/Devel/NYTProf.pm#CLOCKS">description of the various clocks</a> available for profiling: POSIX real-time clocks, <code>gettimeofday()</code>, and <code>Time::HiRes</code>.</p>
<p>I&#8217;ve also added a <a href="http://search.cpan.org/~timb/Devel-NYTProf/lib/Devel/NYTProf.pm#SMP_Systems">caveats</a> section that discusses issues with SMP systems, processor affinity, and virtual machines.</p>
<h2>Feedback Wanted</h2>
<p>How has NYTProf helped you optimize your applications? Let me know.</p>
<p>Perhaps as blog posts of your own, linking back here, or comments here, or <a href="http://cpanratings.perl.org/d/Devel-NYTProf">CPAN ratings</a>, or email to <a href="http://groups.google.com/group/develnytprof-dev/">the mailing list</a> or just to me. I&#8217;d love to hear from you.</p>
<p>Thanks!</p>
<br />Posted in perl Tagged: nytprof, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=195&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/11/01/nytprof-207-even-better-and-now-for-windows-too/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/11/nytprof-string-eval.png" medium="image">
			<media:title type="html">NYTProf string eval.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/11/nytprof-xsub-callers.png" medium="image">
			<media:title type="html">NYTProf xsub callers.png</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf 2.05 &#8211; assorted fixes</title>
		<link>http://blog.timbunce.org/2008/10/08/nytprof-205-assorted-fixes/</link>
		<comments>http://blog.timbunce.org/2008/10/08/nytprof-205-assorted-fixes/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 23:34:53 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=192</guid>
		<description><![CDATA[Hot on the heels of NYTProf 2.04, I&#8217;ve just released NYTProf 2.05. It has a few small but significant bug fixes. From the Changes file:

  Fixed alteration of $! during profiling, thanks to Slaven Rezic.
  Fixed clock_gettime() clock selection to fallback to CLOCK_REALTIME
    if CLOCK_MONOTONIC is not available, e.g, on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=192&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Hot on the heels of NYTProf 2.04, I&#8217;ve just released NYTProf 2.05. It has a few small but significant bug fixes. From the Changes file:</p>
<pre>
  Fixed alteration of $! during profiling, thanks to Slaven Rezic.
  Fixed clock_gettime() clock selection to fallback to CLOCK_REALTIME
    if CLOCK_MONOTONIC is not available, e.g, on linux 2.4.
  Fixed error when application ends after DB::disable_profile().
  Added some docs to Devel::NYTProf::Apache
  Added clock=N option to enable user to select the clock.
</pre>
<p>All the bugs were long-standing ones that happened to come to light and get fixes after 2.04 was released.</p>
<p>The first was the cause of a couple of <a href="http://rt.cpan.org/Ticket/Display.html?id=39396">odd</a> <a href="http://rt.cpan.org/Ticket/Display.html?id=39773">bugs</a> were applications would behave differently when profiled. The problem was that in certain situations the profiler would alter the value of $! between statements, so code that tested for $! would think something had gone wrong.</p>
<p>The second caused weird timing values on some platforms. The statement times would be zero and the subroutine times would be garbage. The problem was that some systems, such as Linux 2.4, define the CLOCK_MONOTONIC macro but don&#8217;t implement that clock in the kernel. NYTProf wasn&#8217;t testing that the clock worked. Now it does. If the clock_gettime() call fails with the selected clock it falls back to CLOCK_REALTIME (and if that fails NYTProf aborts).</p>
<p>As a bonus I&#8217;ve added the ability to select what clock you want to use by setting <code>clock=<em>N</em></code> in the NYTPROF environment variable, where N is the integer id of the clock you want to use (usually you can find the CLOCK_* macros in the /usr/include/time.h file). This only works if your system supports <a href="http://www.freebsd.org/cgi/man.cgi?query=clock_gettime">clock_gettime()</a>, which most modern unix-like systems do, with the notable exception of OS X.</p>
<p>Why would you want to use a different clock?</p>
<p>Well the default, CLOCK_MONOTONIC, is <a href="http://www.nabble.com/Micro-benchmark-for-various-time-syscalls...-to17594175.html#a17606351">relatively expensive</a> to call, and NYTProf calls it <em>twice per statement</em>. So it&#8217;s the dominant cost of the profiler.</p>
<p>Some systems, like Linux 2.6, offer other clocks, like CLOCK_MONOTONIC_FAST that returns the most recently <em>cached</em> value of the clock. That&#8217;s typically just 1/10th the cost of CLOCK_MONOTONIC, so your code runs much faster under the profiler.</p>
<p>Naturally there&#8217;s a trade-off: the accuracy of the timings drops significantly. Still <a href="http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/">far better than Devel::DProf</a>, but far worse than normal. You&#8217;re dependent on how often the cached time value gets updated by your kernel. I saw a figure of &#8220;600 times per second&#8221; quoted for one system, but I can&#8217;t find the link now. My advice would be to steer clear of this feature unless you feel comfortable with the issues <a href="http://www.nabble.com/Micro-benchmark-for-various-time-syscalls...-to17594175.html#a17606351">like</a> <a href="http://sean.chittenden.org/news/2008/06/01/">these</a>.</p>
<p>Enjoy!</p>
<br />Posted in perl Tagged: nytprof, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=192&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/10/08/nytprof-205-assorted-fixes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf 2.04 gives you 90% smaller data files</title>
		<link>http://blog.timbunce.org/2008/10/03/nytprof-204-gives-you-90-smaller-data-files/</link>
		<comments>http://blog.timbunce.org/2008/10/03/nytprof-204-gives-you-90-smaller-data-files/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 11:15:27 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=166</guid>
		<description><![CDATA[At OSCON this year I gave a talk on my new pet project Devel::NYTProf v2 to a packed room. Turned out to be a lot of fun. 
&#8220;The first thing I need to do is talk about Devel::DProf because it needs to be taken out and shot.&#8221;
I made a screencast of the 40 minute talk [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=166&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>At OSCON this year I gave a talk on my new pet project Devel::NYTProf v2 to a packed room. Turned out to be a lot of fun. </p>
<blockquote><p>&#8220;The first thing I need to do is talk about Devel::DProf because it needs to be <a href="http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/">taken out and shot</a>.&#8221;</p></blockquote>
<p>I made a screencast of the 40 minute talk which you can watch on blip.tv <a href="http://blip.tv/file/1130150">here</a>. Worth watching for the background on profilers, the demo of NYTProf, and the questions, not to mention the teasing I get along the way.</p>
<p>One of the final questions was about the size of the profile data file that NYTProf produces. One of the major drawbacks of statement-level profiling is the volume of data it generates while profiling your code. For every statement executed the profiler streams out the file id, the line number, and the time spent. For every statement! When trying to profile a full application doing real work the volume of data generated quickly becomes impractical to deal with. Multi-gigabyte files are common.</p>
<p>This was the major problem with <a href="http://search.cpan.org/perldoc?Devel::SmallProf">Devel::SmallProf</a>, which generated text files while profiling. Salvador Fandiño García addressed that in <a href="http://search.cpan.org/perldoc?Devel::FastProf">Devel::FastProf</a> by writing the data in a compact binary form. A <em>vast</em> improvement that contributed to Devel::FastProf (on which Devel::NYTProf is based) being the first statement-level profiler worth using on large applications. Even so, the volume of data generated was still a problem when profiling all but short running applications.</p>
<p>NYTProf 2.03 was producing profile data at the rate of about 13MB per million statements executed. That might not sound too bad until you realise that on modern systems with cpu intensive code, perl can execute millions of statements every few seconds.</p>
<p>I could see a way to approximately halve the data volume by changing the format to optimize of the common case of consecutive statements being in the same file, but that wasn&#8217;t going to be enough. The best way forward would be to add zip compression. It would be easy enough to pipe the output stream through a separate zip process, but that approach has a problem: the zip process will be soaking up cpu time asynchronously from the app being profiled. That would affect the realtime measurements in an unpredictable way.</p>
<p>I realized back <a href="http://code.google.com/p/perl-devel-nytprof/source/detail?r=333#">in June</a> that a better approach would be to embed zip compression into NYTProf itself. Around the end of July Nicholas Clark, current Perl Pumpkin, <a href="http://groups.google.com/group/develnytprof-dev/tree/browse_frm/thread/5caf1b8e598639be/8d86aa83b7ba45f0?rnum=1&amp;_done=%2Fgroup%2Fdevelnytprof-dev%2Fbrowse_frm%2Fthread%2F5caf1b8e598639be%2F9a4a6a76ca2ae013%3F#doc_55c101d6c8499465">got involved</a> and was motivated to implement the internal zipping because he was &#8220;<em>generating over 4Gb of profile data trying to profile the harness in the Perl 5 core running tests in parallel</em>&#8220;.</p>
<p>He did a great job. The zlib library is automatically detected at build time and, if available, the code to dynamically route i/o through the zip library gets compiled in. The output stream starts in normal mode, so you can easily see and read the plain text headers in the data file, then switches to zip compression for the profile data. How well did it work out? This graph tells the story:</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/10/nytprof-204-compression.png?w=845&#038;h=641" alt="NYTProf 2.04 compression.png" border="0" width="845" height="641" /></div>
<p><em>(The data relates to profiling perlcritic running on a portion of its own source code on my MacBook Pre 2GHz laptop. I only took one sample at each compression level so there may be some noise in the results.)</em></p>
<p>The data file size (red) plummets even at the lowest compression level. Also note the corresponding drop in system time (yellow) due to the reduction in context switches and file i/o. </p>
<p>I&#8217;ve set the default compression level to 6. I doubt you&#8217;ll want to change it, but you can by adding <code>compression=N</code> to the <code>NYTPROF</code> environment variable.</p>
<p>Here are the change notes for the 2.04 release:</p>
<pre>
  Fixed rare divide-by-zero error in reporting code.
  Fixed rare core dump in reporting code.
  Fixed detection of #line directives to be more picky.
  Fixed some compiler warnings thanks to Richard Foley.
  Added on-the-fly ~90% zip compression thanks to Nicholas Clark.
    Reduces data file size per million statements executed
    from approx ~13MB to ~1MB (depends on code being profiled).
  Added extra table of all subs sorted by inclusive time.
  No longer warns about '/loader/0x800d8c/...' synthetic file
    names perl assigns reading code from a CODE ref in @INC
</pre>
<p>Enjoy!</p>
<br />Posted in perl Tagged: graphs, nytprof, performance, video <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=166&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/10/03/nytprof-204-gives-you-90-smaller-data-files/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/10/nytprof-204-compression.png" medium="image">
			<media:title type="html">NYTProf 2.04 compression.png</media:title>
		</media:content>
	</item>
		<item>
		<title>The Italian Perl Workshop</title>
		<link>http://blog.timbunce.org/2008/09/24/the-italian-perl-workshop/</link>
		<comments>http://blog.timbunce.org/2008/09/24/the-italian-perl-workshop/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 12:56:03 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[myths]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=141</guid>
		<description><![CDATA[I spent a very pleasant few days in Pisa, Italy, last week. I&#8217;d been invited to speak at the Fourth Italian Perl Workshop. The workshop was a great success. In fact calling it a &#8220;workshop&#8221; is selling it short. It&#8217;s more of a mini-conference:
&#8220;2 days of conference, 2 simultaneous tracks, more than 30 talks, 120 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=141&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://timbunce.files.wordpress.com/2008/09/pisa-cathedral-wall.jpg?w=150&#038;h=320" alt="Pisa Cathedral Wall.jpg" border="0" width="150" height="320" align="right" />I spent a very pleasant few days in Pisa, Italy, last week. I&#8217;d been invited to speak at the <a href="http://conferences.yapceurope.org/ipw2008/">Fourth Italian Perl Workshop</a>. The workshop was a great success. In fact calling it a &#8220;workshop&#8221; is selling it short. It&#8217;s more of a mini-conference:</p>
<blockquote><p>&#8220;2 days of conference, 2 simultaneous tracks, more than 30 talks, 120 attendees, 20 sponsors and many international guests&#8221;</p></blockquote>
<p>The whole event ran very smoothly thanks to a great team lead by Gianni Ceccarelli, Francesco Nitido, and Enrico Sorcinelli. I&#8217;ll echo <a href="http://www.perl.it/blog/archives/000614.html">the compliments of one attendee</a> <em>&#8220;Complimenti sinceri agli organizzatori! Bravissimi! Tutto perfetto!</em>&#8220;</p>
<p>I gave short talk on Gofer on the Thursday, and then two 40 minutes talks on Friday: Perl Myths, and Devel::NYTProf. I hope to upload screencasts and slides next week. The talks were all recorded on video so I imagine they&#8217;ll be uploaded at some point. I&#8217;ll add links here to them when they are.</p>
<p>The majority of the sessions were in Italian so, since my Italian is practically non-existant, I had plenty of time to work.</p>
<p>Or at least try to. The one disappointment of the trip for me was the apparent poor quality of the Italian internet. Using <a href="http://en.wikipedia.org/wiki/Mtr_(My_traceroute)">mtr</a> I&#8217;d regularly see over 20% packet loss within <em>telecomitalia.it</em> and <em>interbusiness.it</em> from my hotel room. Occasionally over 50%. It got much better at night, so I&#8217;d do more work then. At the conference venue the Italian academic network (<em>garr.net</em>) also regularly had over 20% packet loss at its link to the internet. All this was, of course, outside the control of the organisers.</p>
<p>The &#8220;corridoor track&#8221; at perl conferences is always good. I had a chance to talk to Rafel Garcia-Suarez (and meet his lovely wife and new baby son), Matt S Trout, Hakim Cassimally, Michel Rodriguez,  Marcus Ramberg, and many others.</p>
<p>I had opted to take a very early fight so I&#8217;d have a day being a tourist in Pisa before the conference started. The weather was beautiful and I had a lovely time strolling though the streets of this ancient city.</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/09/pisa-knights-square.jpg?w=640&#038;h=480" alt="Pisa Knights Square.jpg" border="0" width="640" height="480" /></div>
<p>I didn&#8217;t take my camera with me, but I did take my iPhone so I was able to capture a few snaps as I strolled around and climbed the tower. (Yes, it really does lean in a disconcerting &#8220;it must be about to fall down&#8221; way. All the more dramatic when you&#8217;re up close and can appreciate the massive scale of the tower.)</p>
<div style="text-align:center;">
<img src="http://timbunce.files.wordpress.com/2008/09/pisa-framed-view.jpg"/></p>
<p><img /></p>
<p><img src="http://timbunce.files.wordpress.com/2008/09/pisa-cathedral-ceiling.jpg"/></p>
<p><img src="http://timbunce.files.wordpress.com/2008/09/pisa-tower-steps.jpg"/></p>
<p><img src="http://timbunce.files.wordpress.com/2008/09/pisa-view-over-cathedral.jpg?w=640&#038;h=480" alt="Pisa View over Cathedral.jpg" border="0" width="640" height="480" />
</div>
<br />Posted in life, perl Tagged: conference, myths, nytprof, presentation, video <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=141&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/09/24/the-italian-perl-workshop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/09/pisa-cathedral-wall.jpg" medium="image">
			<media:title type="html">Pisa Cathedral Wall.jpg</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/09/pisa-knights-square.jpg" medium="image">
			<media:title type="html">Pisa Knights Square.jpg</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/09/pisa-view-over-cathedral.jpg" medium="image">
			<media:title type="html">Pisa View over Cathedral.jpg</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf v2 &#8211; the background story</title>
		<link>http://blog.timbunce.org/2008/07/16/nytprof-v2-the-background-story/</link>
		<comments>http://blog.timbunce.org/2008/07/16/nytprof-v2-the-background-story/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 06:06:37 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=67</guid>
		<description><![CDATA[This is the back story to the development of NYTProf v2.
Earlier this year (2008) I needed to do some performance profiling of the source code of a large application. Like many perl developers, my first instinct was to try using Devel::DProf (actually the Apache::DProf wrapper as it was a mod_perl application). It was not a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=67&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>This is the back story to the <a href="http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/">development of NYTProf v2</a>.</p>
<p>Earlier this year (2008) I needed to do some performance profiling of the source code of a large application. Like many perl developers, my first instinct was to try using Devel::DProf (actually the Apache::DProf wrapper as it was a mod_perl application). It was not a great experience.</p>
<h2>DProf</h2>
<p>DProf seems easily confused by unusual control flow, spewing &#8220;&#8230; has unstacked calls&#8221; warnings. Also, the subroutines it said were taking the most time didn&#8217;t make sense to me. Eventually I worked out that <a href="http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/">Devel::DProf is effectively broken</a>.</p>
<p>The application I was trying to profile has quite a few large subroutines, so knowing just the time spent in the subroutine as a whole didn&#8217;t help much for those. I wanted to know <em>where</em> in the subroutine the time was being spent.</p>
<h2>FastProf</h2>
<p>That led me to look at line-based profilers. At the time there as only one worth looking at, <a href="http://search.cpan.org/perldoc?Devel::FastProf">Devel::FastProf</a> by <a href="http://search.cpan.org/~salva/">Salvador Fandiño García </a> (which was based on <a href="http://search.cpan.org/dist/Devel-SmallProf/">Devel::SmallProf</a> by <a href="http://search.cpan.org/~ashted/">Ted Ashton</a>).</p>
<p>Line profilers spit out a stream of &#8220;file id, line number, time spent&#8221; records to a file. The time between starting one statement and starting the next is measured and associated with the line number of the statement.</p>
<p>Devel::FastProf was great. Fast and effective. It gave me far more accurate timings, and when I made changes in the code it highlighted I could see an immediate effect on performance.</p>
<p>Devel::FastProf was great, but I wanted more. The lack of subroutine level timing was frustrating. When you have a ~100,000 lines of code, knowing the time spent on each, and how many times it was executed, is less useful than you may think &#8211; there&#8217;s just too much detail. Especially when looking for structural problems in the code, or for good places to add caching, or pass extra information down a call chain to save expensive calls deeper in the code. There&#8217;s a need for <em>both</em> subroutine and line level timings when profiling.</p>
<h2>Idea</h2>
<p>I&#8217;d had an idea: The line number output in the FastProf profile need not be the line number of the statement. It could output the <em>line number of the subroutine containing the statement</em>. Then you&#8217;d automatically get subroutine level timings! Simple.<br />
Then I wondered if it was possible to find the line number of the <em>block</em> the statement was in. That would give block level timing! A first for any perl profiler.</p>
<p>My perl internals knowledge was getting rusty as it was a few years since I&#8217;d been Pumpkin for the 5.4.x release, so <a href="http://markmail.org/message/rvfvucvhq2iesl3h">I asked the wizards</a> on perl5-porters. They gave me hope and enough clues to get going.</p>
<p>Salvador kindly moved the Devel::FastProf code to a public svn, so I could contribute more easily, and <a href="http://code.google.com/p/devel-fastprof/source/list">I started hacking</a>. I added code to find the nearest enclosing block or sub and it proved very useful.</p>
<p>When I&#8217;m optimizing I start by identifying &#8220;locally inefficient code&#8221;. That is, code you can optimize without significant structural changes. Without making changes outside the subroutine. Moving code outside loops is a common example. Subroutine timings identify the hot subs, then block and line timings pinpoint the hot spots in the code.</p>
<p>That&#8217;s the low hanging fruit. Easy pickings, and often very effective. But there&#8217;s a limit to how far that&#8217;ll take you.</p>
<h2>Callers and Callees</h2>
<p>There are two ways to optimize a hot piece of code: make it faster, or execute it less often. The former tends to get much more attention than the latter. It&#8217;s important to remember to keep stepping back. To keep looking for the bigger picture.</p>
<p>When I&#8217;m optimizing I often use a well defined chunk of work, like 10 requests to the same URL, so I can see of the number of times a subroutine is called &#8220;feels right&#8221;. That often shows subs being called &#8220;too often&#8221;. But what then? You need to know <em>why</em> the sub is being called too often, so you need to know <em>where</em> it&#8217;s being called from.</p>
<p>In Devel::FastProf I added counting of subroutine callers two-levels up the call stack. So I could see that foo() was called 10 times by bar() and that <em>of those 10 calls</em> from bar() 7 has come from baz() and 3 from boo(). It was very simplistic, slow (implemented in perl) and only had counts, not timings, but proved <em>very useful</em>.</p>
<p>Using these additions to Devel::FastProf I reduced the CPU usage of the application by over 40%. Not bad. (I could see another 10% or so to be gained fairly easily but had to draw the line somewhere.)</p>
<h2>NYTProf</h2>
<p>Meanwhile Adam Kaplan had forked Devel::FastProf, added a test harness and tests, made some internal improvements, grafted on an html report derived from <a href="http://search.cpan.org/perldoc?Devel::Cover">Devel::Cover</a>, and <a href="http://perlbuzz.com/mechanix/2008/03/develnytprof-is-the-hot-new-pr.html">released it as Devel::NYTProf</a>.</p>
<p>When I saw NYTProf I switched to working on that. Again, Adam was kind enough to move the code to a public <a href="http://code.google.com/p/perl-devel-nytprof/">svn repository</a>. I was attracted not so much by the html report as by the test harness. A lesson to anyone wanting to attract developers to an open source project!</p>
<p>Testing profilers is hard and Adam had come up with a good basic testing framework which was easy to extend. NYTProf now has a strong test suite that profiles 19 different perl scripts with four different combinations of profiler options. The test suite has proven <em>invaluable</em> in identifying regressions during development, and for identifying portability issues between perl versions.</p>
<p>I re-implemented the block/sub level profiling and the subroutine caller tracking from FastProf in NYTProf, but with more care, more attention to performance, and now tests.</p>
<p>I was particularly pleased with the subroutine caller tracking. It intercepts the <code>entersub</code> opcode and uses the save stack for storage and to trigger a &#8216;destructor&#8217; call to end the timing when the subroutine is exited by any means. The end result is an extremely fast and robust subroutine call profiler. I plan to add an option to disable the other profiler so you can just get subroutine profile details when you don&#8217;t need statement level details. It currently lacks the ability to give exclusive times but I think I&#8217;ve an efficient solution for that. (Update: Implemented in <a href="http://code.google.com/p/perl-devel-nytprof/source/detail?r=340">r340</a> and <a href="http://code.google.com/p/perl-devel-nytprof/source/detail?r=343">r343</a> so will be in the 2.02 release.)</p>
<h2>Accuracy</h2>
<p>Another key innovation was to fix a fundamental problem inherent in all statement profilers. Consider a statement that calls a subroutine and then performs some other work that doesn&#8217;t execute new statements, for example:</p>
<pre>    foo(...) || mkdir(...);</pre>
<p>In all other statement profilers the time spent in <em>remainder</em> of the expression (mkdir in the example) will be recorded as having been spent on <em>the last statement executed in foo()</em>! Here&#8217;s another example:</p>
<pre>    while (&lt;&gt;) {
        ...
        1;
    }</pre>
<p>After the first time around the loop, any further time spent evaluating the condition (waiting for input in this example) would be be recorded as having been spent <em>on the last statement executed in the loop</em>!</p>
<p>I fixed this in NYTProf by intercepting all the opcodes which indicate that control is returning into some previous statement and adjusting the profile accordingly.</p>
<h2>Reporting</h2>
<p>As much effort, if not more, went into the reporting side of the code. And there&#8217;s a lot more to be done there. My goal is to keep growing the data model classes to the point where any reporting code can get the information it needs easily enough that there&#8217;s no longer a need for the rather limiting Reporter class.</p>
<p>I&#8217;d like to see a single &#8216;nytprof&#8217; command line tool that loads a class to generate the report. That would replace nytprofhtml and nytprofcsv. That would make it easy for other developers to release &#8216;nytprof reporting modules&#8217; to CPAN.</p>
<p>For example, one very useful report that FastProf has but NTProf currently lacks is a list of most expensive lines (or blocks, or subs) output in the format used by compiler error messages. The format is important because most editors have a special mode for reading such files that means you can hop from one &#8216;most expensive line&#8217; to the next with a single key stroke. (For vim that&#8217;s called <a href="http://www.vim.org/htmldoc/quickfix.html">quickfix mode</a>.) That&#8217;s a wonderful way to browse the hotspots and make edits on the spot.</p>
<h2>Future</h2>
<p>There are many, many, ways NYTProf can be enhanced further. As I&#8217;ve worked on it I&#8217;ve dumped ideas, issues and random notes into the <a href="http://code.google.com/p/perl-devel-nytprof/source/browse/trunk/HACKING">HACKING</a> file.</p>
<h2>Thanks</h2>
<p>I&#8217;d like to end by expressing my thanks to Salvador Fandiño García and especially Adam Kaplan for allowing me to contribute to the modules they created and tolerating my strong ideas with understanding. Thank you both. It&#8217;s been quite a ride.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/timbunce.wordpress.com/67/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/timbunce.wordpress.com/67/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=67&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/07/16/nytprof-v2-the-background-story/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
		<item>
		<title>NYTProf v2 &#8211; A major advance in perl profilers</title>
		<link>http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/</link>
		<comments>http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 03:56:42 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=52</guid>
		<description><![CDATA[After much hacking, and just in time for OSCON, I&#8217;m delighted to announce the release of Devel::NYTProf version 2. A powerful, efficient, feature-rich perl source code profiler.
&#8220;If NYTProf 1 is a Toyota, then 2.0 is a Cadillac&#8221;
— Adam Kaplan, author of NYTProf 1.
The Short Story
(I&#8217;ve written up the long story, for the record, in another [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=52&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>After <em>much</em> hacking, and just in time for OSCON, I&#8217;m delighted to announce the release of Devel::NYTProf version 2. A powerful, efficient, feature-rich perl source code profiler.</p>
<blockquote><p>&#8220;If NYTProf 1 is a Toyota, then 2.0 is a Cadillac&#8221;<br />
— Adam Kaplan, author of NYTProf 1.</p></blockquote>
<h1>The Short Story</h1>
<p>(I&#8217;ve written up the long story, for the record, <a href="http://blog.timbunce.org/2008/07/16/nytprof-v2-the-background-story/">in another post</a>.)</p>
<p>Adam forked <a href="http://search.cpan.org/perldoc?Devel::FastProf">Devel::FastProf</a> (the best statement-level profiler at the time), added a test harness and tests, made some internal improvements, and grafted on an html report derived from <a href="http://search.cpan.org/perldoc?Devel::Cover">Devel::Cover</a>. The resulting Devel::NYTProf v1 was a big hit.</p>
<p>Meanwhile I&#8217;d been working on Devel::FastProf, <a href="http://code.google.com/p/devel-fastprof/source/list">contributing</a> some interesting new profiling features, but it had no test harness and no html reports. When Adam released NYTProf I switched. Attracted not so much by the html report as by the test harness. (A lesson to anyone wanting to attract developers to an open source project.)</p>
<p>I started out by adding in the same new features I&#8217;d been adding to FastProf, albeit with more polish and tests. And then I got carried away&#8230;</p>
<blockquote><p>&#8220;Holy shit! That is amazing.&#8221;<br />
— Andy Lester, after using a recent development version.</p></blockquote>
<h1>Example Screen Shots</h1>
<p>As an example I&#8217;ve used NYTProf to profile <a href="http://search.cpan.org/perldoc?perlcritic">perlcritic</a> 1.088 running on its own source code.</p>
<pre>$ cd Perl-Critic-1.088
$ perl -d:NYTProf -S perlcritic .
$ nytprofhtml
$ open nytprof/index.html</pre>
<p>The first image is the main index page, showing the top few subroutines and the start of the list of all source files.</p>
<div style="text-align:center;border:1px;"><img src="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-index.png?w=660&#038;h=749" border="1" alt="NYTProf perlcritic index.png" width="660" height="749" /></div>
<p>Each source file has links to separate line-level, block-level, and sub-level reports (though I hope to merge them in future). Clicking on a subroutine name takes you to the line-level report for the file it&#8217;s defined in and positions you at the subroutine definition.</p>
<p>(The color coding is based on <a href="http://en.wikipedia.org/wiki/Median_absolute_deviation">Median Absolute Deviation</a> of all the values in the column, same as in NYProf v1.)</p>
<p>Here&#8217;s the all_perl_files() subroutine, for example:</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-all-perl-files.png?w=663&#038;h=552" border="1" alt="NYTProf perlcritic all_perl_files.png" width="663" height="552" /></div>
<p>The colored numbers show the number of statements executed, the total time taken, and the average. The statement times are always <em>exclusive</em> times. Time actually spent <em>on</em> that statement, the expressions and any built-in functions it uses. It doesn&#8217;t include any time spent executing statements elsewhere in subroutines called by it. In NYTProf subroutine timings are inclusive and statement timings are exclusive.</p>
<h2>Where did you come from and where are you going?</h2>
<p>Notice the grey text.</p>
<p>On lines that <em>define</em> a subroutine NYTProf now adds &#8216;comments&#8217; giving the total number of times the sub was called, the inclusive time spent in that sub, and the average. Then it adds a break-down of the same details <em>for every location that called the subroutine</em>. Here&#8217;s a better example of that:</p>
<p><img src="http://timbunce.files.wordpress.com/2008/07/nytprof-sub-callers1.png?w=725&#038;h=137" border="0" alt="NYTProf sub-callers.png" width="725" height="137" /></p>
<p>On lines that <em>call</em> subroutines NYTProf now adds &#8216;comments&#8217; giving the name of the actual subroutines called (resolving code refs to subroutine names, including the class that handled a method call). It also tells you how many calls were made and how much time was spent in that subroutine <em>for calls made from that line</em>. Here&#8217;s an example:</p>
<p><img src="http://timbunce.files.wordpress.com/2008/07/nytprof-subs-called1.png?w=817&#038;h=106" border="0" alt="NYTProf subs-called.png" width="817" height="106" /></p>
<p>When you mouse-over the grey text it turns black and you can click on embedded links to take you to the callers or callees. <em>So with a few clicks you can run up and down the call stack exploring where the time is being spent and where the hot spots are being called from</em>. The ability to <em>explore</em> the code so easily, guided by these performance signposts is incredibly useful.</p>
<h2>Rolling up for a higher level view</h2>
<p>Sometimes per-statement timing can overwhelming. In large subroutines it becomes &#8220;hard to see the wood for the trees&#8221;. So, for the first time in any Perl profiler, NYTProf now provides a block-level view of the timing data:</p>
<div style="text-align:center;"><img src="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-all-perl-files-block-level.png?w=662&#038;h=552" border="1" alt="NYTProf perlcritic all_perl_files block level.png" width="662" height="552" /></div>
<p>What&#8217;s happening here is that NYTProf is taking the same time measurements per statement, but instead of accumulating the time against the line the statement is on, it accumulates it against the line of the first statement in the enclosing block. (The actual line it accumulates it against isn&#8217;t ideal in some cases. I&#8217;m hoping to improve that soon.)</p>
<p>This report is a little more tricky to read but can be very useful, especially in large subroutines. (I hope to improve the readability with some css :hover magic in future.)</p>
<p>The subroutine-level report is very similar except that all the timings are accumulated against line of the first statement in the subroutine.</p>
<h2>Have a Look</h2>
<p>Back in June I gave a talk at the <a>Irish Open Source Technology</a> conference where I showed the first version of the annotated html report (which I&#8217;d been hacking on till 3am the night before while struggling with a cold &#8211; presentations are great motivators). You can see the 15 minute video <a href="http://link.brightcove.com/services/link/bcpid1659850726/bctid1662507092">here</a> or <a href="http://idisk.mac.com/tim.bunce-Public/perl/NYTProf/NYTProf-200806c.mov">here</a>).</p>
<h2>Explore for yourself</h2>
<p>I&#8217;ve uploaded the full set of reports for you to explore <a href="http://idisk.mac.com/tim.bunce-Public/perl/NYTProf/nytprof-perlcritic-20080812/index.html" target="_new">here</a>. Take a look. Let me know what you think.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/timbunce.wordpress.com/52/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/timbunce.wordpress.com/52/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=52&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
<enclosure url="http://idisk.mac.com/tim.bunce-Public/perl/NYTProf/NYTProf-200806c.mov" length="56934512" type="video/quicktime" />
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-index.png" medium="image">
			<media:title type="html">NYTProf perlcritic index.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-all-perl-files.png" medium="image">
			<media:title type="html">NYTProf perlcritic all_perl_files.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/07/nytprof-sub-callers1.png" medium="image">
			<media:title type="html">NYTProf sub-callers.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/07/nytprof-subs-called1.png" medium="image">
			<media:title type="html">NYTProf subs-called.png</media:title>
		</media:content>

		<media:content url="http://timbunce.files.wordpress.com/2008/07/nytprof-perlcritic-all-perl-files-block-level.png" medium="image">
			<media:title type="html">NYTProf perlcritic all_perl_files block level.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Devel::DProf &#8211; broken by the passage of time</title>
		<link>http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/</link>
		<comments>http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 23:05:53 +0000</pubDate>
		<dc:creator>TimBunce</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://timbunce.wordpress.com/?p=48</guid>
		<description><![CDATA[&#8220;Measure twice, cut once.&#8220;
To measure the performance of your Perl code many developers instinctively reach for Devel::DProf. The venerable perl profiler dates back to 1995.
When profiling you have two broad choices: cpu-time vs wallclock time, and subroutine-level profiling vs line-level profiling. DProf is a subroutine-level profiler. (I&#8217;ll talk more about subroutine-level profiling vs line-level profiling [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=48&subd=timbunce&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;<em>Measure twice, cut once.</em>&#8220;</p></blockquote>
<p>To measure the performance of your Perl code many developers instinctively reach for Devel::DProf. The venerable perl profiler dates back to 1995.</p>
<p>When profiling you have two broad choices: cpu-time vs wallclock time, and subroutine-level profiling vs line-level profiling. DProf is a subroutine-level profiler. (I&#8217;ll talk more about subroutine-level profiling vs line-level profiling in an upcoming post about <span style="text-decoration:line-through;">the soon-to-be-released</span> <a href="http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/">NYTProf 2.0</a>.)</p>
<p>Measuring cpu-time should, in theory, give you a clear picture of the time spent by perl executing your code, independent of the load on the machine or delays waiting for i/o. Sadly life isn&#8217;t so simple.</p>
<p>The big problem is that on most systems cpu-time measurement has a resolution of 0.01 seconds (a HZ value of 100). That may not sound like much time, but you can execute a <em>lot</em> of perl code, and a lot of subroutine calls, in that time.</p>
<p>So any profiler using cpu-time with such a course granularity is going to give &#8216;noisy&#8217; results. Some subroutines may appear to be slow because the cpu-time &#8216;tick&#8217; happened to occur more while those subs were running. Other subroutines may appear to be fast because the cpu-time &#8216;tick&#8217; doesn&#8217;t happen much while they&#8217;re running.</p>
<p>Try playing around with the venerable <a href="http://search.cpan.org/perldoc?Devel::DProf">Devel::DProf</a> like this:</p>
<pre>$ perl -we 'print "sub s$_ { sqrt(42) for 1..100 }; s$_({});\n" for 1..1000' &gt; x.pl
$ perl -d:DProf x.pl
$ dprofpp
Total Elapsed Time = 0.047999 Seconds
  User+System Time = 0.047999 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 20.8   0.010  0.010      1   0.0100 0.0100  main::s986
 20.8   0.010  0.010      1   0.0100 0.0100  main::s29
 20.8   0.010  0.010      1   0.0100 0.0100  main::s321
 0.00       - -0.000      1        -      -  main::s322
 0.00       - -0.000      1        -      -  main::s323
 0.00       - -0.000      1        -      -  main::s329
 0.00       - -0.000      1        -      -  main::s330</pre>
<p>Clearly nonsense. Out of 1000 subroutines that would all take about the same length of time, a cpu-time &#8216;tick&#8217; happened to occur in those three. The rest of the subroutines appear to be &#8216;free&#8217;. (If you play with this yourself you&#8217;ll probably need to adjust the 1..100 to see the effect on your system.)</p>
<p>Using <code>dprofpp -r</code> (to &#8220;display elapsed real times&#8221; instead of cpu-times) gives a very similar granular result. That&#8217;s because Devel::DProf <em>artificially reduces the resolution of real time to match the granular cpu-time</em>! It&#8217;s also odd that <code>dprofpp</code> doesn&#8217;t provide an option to <em>sort</em> by elapsed time, but there&#8217;d be little value anyway given the low resolution.</p>
<p>Many people have reported strange results from Devel::DProf over the years. Design decisions that made sense back in 1995 are now causing problems as CPUs have got so much faster. Several have implemented <a href="http://search.cpan.org/search?query=devel+prof&amp;mode=dist">alternative profilers</a>.</p>
<p>Using cpu-time is effectively a kind of <a href="http://en.wikipedia.org/wiki/Performance_analysis#Statistical_profilers">statistical sampling</a>. That&#8217;s fine as long as you remember it and interpret the results accordingly. The work-around for the course granularity is to execute the code for long enough for the effects to be averaged out. But that can be inconvenient, and how do you know how much is enough?</p>
<p>Personally I&#8217;d recommend using wallclock time for profiling. I <em>want</em> to know how much time was spent waiting for network, waiting for disk, waiting for cpu. Those are often significant factors in performance issues. Too many network round trips, or too many individual disk requests, for example, can easily kill performance. If you only profile cpu time you may not spot these kinds of problems. You may just be chasing the random ghosts of occasional cpu clock ticks.</p>
<p> </p>
<p>So which profiler would I recommend? <span style="text-decoration:line-through;">Stay tuned for an announcement in a day or so.</span> Easy! <a href="http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/">NYTProf 2.0</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/timbunce.wordpress.com/48/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/timbunce.wordpress.com/48/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timbunce.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timbunce.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/timbunce.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/timbunce.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/timbunce.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/timbunce.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/timbunce.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/timbunce.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/timbunce.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/timbunce.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.timbunce.org&blog=2562816&post=48&subd=timbunce&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.timbunce.org/2008/07/12/devel-dprof-broken-by-the-passage-of-time/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cf82705f5ab43c73273ab5d690866b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">TimBunce</media:title>
		</media:content>
	</item>
	</channel>
</rss>