Profiling parts of templates

96 views
Skip to first unread message

akaihola

unread,
Mar 3, 2010, 6:19:51 PM3/3/10
to django-extensions
Django-extensions provides the runprofileserver management command for
producing profiling data per HTTP request.

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

Bas van Oostveen

unread,
Apr 8, 2010, 9:02:57 AM4/8/10
to django-e...@googlegroups.com
Can you make this into a change (fork) that I can pull directly into the
github repository ?

Thanks

Reply all
Reply to author
Forward
0 new messages