<?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>Silas Sewell - line_profiler</title>
        <atom:link href="http://www.silassewell.com/blog/tag/line_profiler/rss2.xml" rel="self" type="application/rss+xml" />
        <link>http://www.silassewell.com/blog/tag/line_profiler</link>
        <description>Infrastructure Development</description>
        <lastBuildDate>Sat, 08 Jan 2011 00:00:00 GMT</lastBuildDate>
        <generator>http://www.silassewell.com/</generator>
        <language>en</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>

        <item>
            <title>Python Line-by-line Profiler (line_profiler and kernprof)</title>
            <link>http://www.silassewell.com/blog/2009/05/28/python-line-by-line-profiler-line_profiler-and-kernprof/</link>
            <pubDate>Thu, 28 May 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Fedora]]></category><category><![CDATA[kernprof]]></category><category><![CDATA[line_profiler]]></category><category><![CDATA[Programming]]></category><category><![CDATA[Python]]></category><category><![CDATA[RPM]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/05/28/python-line-by-line-profiler-line_profiler-and-kernprof/</guid>
            <description><![CDATA[<p>The following is a quick and dirty guide to getting started with
<a href="http://packages.python.org/line_profiler/" title="line profiler">line_profiler</a>, a Python line-by-line profiler, on Fedora.</p>

<ol>
<li><a href="http://code.google.com/p/silassewell/wiki/PackagingRPMs" title="Packaging RPMS">Build</a> and install the <a href="http://silassewell.googlecode.com/files/python-line_profiler-1.0-0.1.b2.fc10.src.rpm" title="line profiler SRPM">python-line_profiler</a> package</li>
<li><p>Create a file called <code class="prettyprint">test.py</code> with the code below</p>

<pre><code class="prettyprint">import random, time

def sleep():
    seconds = random.randint(0, 5)
    print 'Sleeping %s seconds' % seconds
    time.sleep(seconds)

@profile
def test():
    sleep()
    sleep()
    sleep()

test()
</code></pre></li>
<li><p>Profile <code class="prettyprint">test.py</code></p>

<pre><code class="prettyprint">[silas@silas ~]$ kernprof.py -l test.py
Sleeping 4 seconds
Sleeping 5 seconds
Sleeping 2 seconds
Wrote profile results to test.py.lprof
</code></pre></li>
<li><p>View the results</p>

<pre><code class="prettyprint">[silas@silas ~]$ python -m line_profiler test.py.lprof
Timer unit: 1e-06 s

File: test.py
Function: test at line 8
Total time: 10.9994 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     8                                           @profile
     9                                           def test():
    10         1      3999416 3999416.0     36.4      sleep()
    11         1      4999982 4999982.0     45.5      sleep()
    12         1      1999990 1999990.0     18.2      sleep()
</code></pre></li>
</ol>

<p>NOTE: I have a <a href="https://bugzilla.redhat.com/show_bug.cgi?id=502978" title="Package Review">package review</a> up for line_profiler and it should be
available via yum eventually.</p>]]></description>
        </item>

    </channel>
</rss>
