djangosnippets.org: Latest snippets posted by ibestuzhevhttps://djangosnippets.org/users/ibestuzhev/2015-05-12T06:27:17.066313-05:00ibestuzhevQuick line profiler decorator
2015-05-12T06:27:17.066313-05:00ibestuzhevhttps://djangosnippets.org/snippets/10483/<p>Requires <a href="https://pypi.python.org/pypi/line_profiler">line_profiler</a></p>
<pre><code>pip install line_profiler
</code></pre>
<p>Will print profile info into console</p>
<pre><code>@line_profiler
def my_view(request):
context = some_quick_func()
return some_heavy_func(context)
</code></pre>
<p>It does not work good when nested, so don't wrap <code>some_heavy_func</code>. If you want to profile also some nested call - use <code>extra_view</code> parameter:</p>
<pre><code>@line_profiler(extra_view=[some_heavy_func])
def my_view(request):
context = some_quick_func() …</code></pre>
Freely redistributable