While improving the performance of a project, I needed to "zoom in" at
a known heavy part of a template. I could have created a script for
loading and rendering the isolated template snippet. While profiling
such a script would have done the job, I preferred to mark the part of
the template for profiling and run the development server otherwise
unmodified.
I propose this template tag:
{% load template_profiling %}
{% profiling "/tmp/profile.prof" %}
{% for item in large_list %}
{# heavy processing here #}
{% endfor %}
{% endprofiling %}
A quick-and-dirty implementation which supports cProfile only and
outputs only in the KCacheGrind format is available here:
http://gist.github.com/321180
It can be dropped at django_extensions/templatetags/
template_profiling.py and used as shown above. The profiling data can
then be viewed:
$ kcachegrind /tmp/profile.prof
Thanks