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

<channel>
	<title>international geographic &#187; mysql</title>
	<atom:link href="http://www.chetanislazy.com/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chetanislazy.com/blog</link>
	<description>ooh, shiny!</description>
	<lastBuildDate>Thu, 19 May 2011 04:16:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ghetto Profiling for MySQL</title>
		<link>http://www.chetanislazy.com/blog/2008/07/29/ghetto-profiling-for-mysql/</link>
		<comments>http://www.chetanislazy.com/blog/2008/07/29/ghetto-profiling-for-mysql/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 19:38:31 +0000</pubDate>
		<dc:creator>chetan</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.chetanislazy.com/blog/?p=65</guid>
		<description><![CDATA[MySQL is generally an all-around kickass piece of software, and like any good open source application, there are a host of tools you can use to squeeze every last drop of goodness out of it. Nearly all of them, however, are geared towards the operational DBA, leaving the wayward developer out in the cold. Lately [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL is generally an all-around kickass piece of software, and like any good open source application, there are a <a href="http://www.mysqlperformanceblog.com/tools/">host of tools</a> you can use to squeeze every last drop of goodness out of it. Nearly all of them, however, are geared towards the operational DBA, leaving the wayward developer out in the cold.</p>
<p><span id="more-65"></span></p>
<p>Lately I&#8217;ve been working on optimizing our stored procedure library which is primarily responsible for generating all sorts of fancy reports for the users. We use lots of nested procedure calls and finding potential targets for optimization is a tricky and time consuming job. Enter <strong>Ghetto Profile</strong>.</p>
<p>It&#8217;s still pretty basic but gets the job done. How&#8217;s it work?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ghetto_profile.rb <span style="color: #660033;">--attach</span> crappy_code.sql
mysql <span style="color: #000000; font-weight: bold;">&lt;</span> crappy_code.sql
ghetto_profile.rb <span style="color: #660033;">--stats</span> <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-pmysql</span></pre></td></tr></table></div>

<p>The <strong>attach</strong> command simply wraps all stored procedure calls with debug statements which can later be analyzed using the <strong>stats</strong> command.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CALL</span> debug<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'stored_proc1'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">-- added by ghetto_profile</span>
    <span style="color: #993333; font-weight: bold;">CALL</span> stored_proc1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">...</span>params<span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">CALL</span> debug<span style="color: #66cc66;">.</span>off<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'stored_proc1'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">-- added by ghetto_profile</span></pre></div></div>

<p>And the output of the <strong>stats</strong> command is something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">total time: 3718.3220
&nbsp;
stored_proc1
         pct:   75.3873
         total: 2803.1430 (46.72)
         avg:   0.0895
         count: 31327
         min:   0.0860000000000001
         max:   0.343
&nbsp;
stored_proc2
         pct:   22.9479
         total: 853.2760 (14.22)
         avg:   0.0273
         count: 31240
         min:   0.0
         max:   0.371
&nbsp;
stored_proc3
         pct:   1.1224
         total: 41.7340 (0.70)
         avg:   0.0007
         count: 59020
         min:   0.0
         max:   0.074</pre></div></div>

<p>Wow, that stored_proc1 is taking up 75% of the time! Hacking ensues&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">total time: 1151.3400
&nbsp;
stored_proc1
         pct:   0.4372
         total: 5.0340 (0.08)
         avg:   0.0001
         count: 43892
         min:   0.0
         max:   0.007</pre></div></div>

<p>Totally sweet! Ok, enough talk. Get some:</p>
<p><a href="http://www.operative.com/~csarva/ghetto_profile.rb">Ghetto Profile 0.7</a> (requires <strong>ruby</strong>, BSD licsensed)<br />
<a href="http://www.operative.com/~csarva/debug.tgz">debug.tgz</a> (helper package to setup the debug database and procs)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chetanislazy.com/blog/2008/07/29/ghetto-profiling-for-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

