djangosnippets.org: Latest snippets tagged with 'profile'https://djangosnippets.org/tags/profile/2015-05-12T06:27:17.066313-05:00Quick 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 redistributableExtended Profiling and Timing Middleware using cProfile
2013-10-27T17:34:57.073456-05:00dstrykehttps://djangosnippets.org/snippets/2998/<p>Modified version of <a href="http://djangosnippets.org/snippets/605/">Extended Profiling Middleware</a></p>
Freely redistributableUnit Test Profiling for Django 1.3/1.4
2012-04-22T11:14:27.254272-05:00hoffmajehttps://djangosnippets.org/snippets/2734/<p>The snippet is a modification of <a href="http://djangosnippets.org/snippets/1315/">snippet 1315</a> to fit the needs for Django 1.3 and 1.4. You can follow the explanations and instructions there.</p>
<p>To plot a nice and so useful call-graph with timings, call:</p>
<p>$ gprof2dot -f pstats unittest.profile | dot -Tpng -o unittest.profile.graph.png</p>
<p>where 'unittest.profile' is the …</p>
Freely redistributableMultiple User subclasses custom Auth backend
2011-09-10T15:07:45.543291-05:00ungenio41https://djangosnippets.org/snippets/2546/<p>A project I'm working on requires multiple different classes of users, all with different fields/attributes. Having a single UserProfile class with a generic relation was a complete pain in practice.</p>
<p>So, I changed my classes to all subclass User directly and then used django-model-utils to create a custom ModelBackend that …</p>
Freely redistributableUser Profile minimal code
2011-08-02T04:02:05.273049-05:00Natimhttps://djangosnippets.org/snippets/2501/<p>Usually I start an authentication app with this model.</p>
<p>Don't forget to set it up in the settings file</p>
<pre><code>AUTH_PROFILE_MODULE = 'authentication.UserProfile'
</code></pre>
Freely redistributableInteractive Profiling Middleware
2010-07-28T11:24:40.593525-05:00sfllawhttps://djangosnippets.org/snippets/2126/<p>Based on <a href="http://djangosnippets.org/snippets/605/">Extended Profiling Middleware</a>, this version allows interactive sorting of functions and inspection of SQL queries.</p>
Freely redistributableCombine ProfileForm an UserForm in one.
2010-06-24T04:26:27.488407-05:00sarghttps://djangosnippets.org/snippets/2081/<p>Using this method you can combine form for standart django.contrib.auth.models.User model and for your project profile model. As now, ProfileForm can be used as usual, and it will also contain UserForm fields. </p>
Freely redistributableUserProfileForm
2009-11-13T02:31:30.924002-06:00Natimhttps://djangosnippets.org/snippets/1795/<p>We often need to use a Profile form and we want to be able to modify the first_name, last_name and sometimes the email address.</p>
<pre><code>Here is how I do it.
</code></pre>
<p>In this case I want to check the email so I did a specific form for it. But it is …</p>
Freely redistributablepycallgraph
2009-02-09T10:54:54.970070-06:00ropperthttps://djangosnippets.org/snippets/1316/<p>Simple debug middleware that uses <a href="http://pycallgraph.slowchop.com">pycallgraph</a> to get a visual representation of the call graph, including number of calls and execution times.</p>
<p>Usage:</p>
<ol>
<li>
<p>Replace <em>myapp</em> in the snippet with the name of your application and or adjust include and exclude according to your needs </p>
</li>
<li>
<p>Add CallgraphMiddleware to your middlewares in …</p></li></ol>
Freely redistributableUnit Test Profiling
2009-02-08T11:21:04.474656-06:00justquickhttps://djangosnippets.org/snippets/1315/<p>A test runner for Django unittests which profiles the tests run, and saves the result. Very useful for diagnosing your apps. Place the top portion of the code into a file called <code>profiling.py</code> someplace in your python path. Update your <code>settings.py</code> file with the bottom two lines of the code. …</p>
Freely redistributableAlternative to User.get_profile()
2008-03-19T15:57:36.413278-05:00jpwattshttps://djangosnippets.org/snippets/651/<p><strong>This is an alternative to User.get_profile.</strong></p>
<p>Rather than having you call <code>User.get_profile</code> directly, this retrieves the profile instance for a <code>User</code> and attaches the fields from the profile to the <code>User</code> object when instantiated. The special methods for <code>DateField</code>, <code>FileField</code>, <code>ImageField</code> and fields with <code>choices</code> are also created. …</p>
Freely redistributableExtended Profiling Middleware
2008-02-17T15:03:37.635264-06:00hauserhttps://djangosnippets.org/snippets/605/<p>Modified version of <a href="http://www.djangosnippets.org/snippets/186/">Profiling Middleware</a></p>
<p>Prints profile results for method, additionally groups results by files and by modules (for django uses top level modules as groups). Works for Windows.</p>
<p>Usage: append ?prof or &prof= to any URL pointing to django application after adding ProfileMiddleware to middlewares in yours settings.py.</p>
<p>NOTICE: …</p>
Freely redistributableDjango profiler
2007-11-10T10:05:25.109342-06:00dogadahttps://djangosnippets.org/snippets/461/<p>The script that can be used to profile any Django-powered web-site and find how many SQL-queries are used per page, how heavy html-pages are, etc.</p>
<p>To use the the script it's enough to put django-profile.py somewhere in PYTHONPATH and call it from the directory that holds projects' settings.py.</p>
<p>For more …</p>
Freely redistributableDebug Page Load Time Stats Middleware
2007-08-07T15:38:15.097383-05:00udfalksohttps://djangosnippets.org/snippets/358/<p>Use this to display a split of page execution time between python and the db in your base template when debugging. </p>
<p>I originally got the base of this code from another snippet, but I can't find it anymore and want to share with new folks because I find this handy. </p>
Freely redistributableSQL Log Middleware + duplicates
2007-07-27T03:51:35.148635-05:00guettlihttps://djangosnippets.org/snippets/344/<p>This is based on <a href="/snippets/161/">Snippet 161</a>
It marks duplicated SQL queries.</p>
<p>To avoid duplicates read:</p>
<p><a href="http://www.djangoproject.com/documentation/db-api/#caching-and-querysets">Caching and Queryset</a></p>
<p>Sept. 07: Updated for current trunk: 'response' behaves like 'response.header'
22. October '07: Log into directory.</p>
Freely redistributable