Profiling Merengue

The Django Debug Toolbar

Merengue has a customized version of the Django debug toolbar deactivated by default.

To activate this toolbar, set the DEBUG_TOOLBAR setting to True.

You can activate specific debug toolbar panels by setting the DEBUG_TOOLBAR_PANELS variable.

Profiling Middleware

Merengue has ProfilingMiddleware deactivated by default. To use it, you have to install python-profiler.

To activate it, remove the comments from merengue/settings.py to activate the middleware:

PRE_MERENGUE_MIDDLEWARE_CLASSES = (
    # ... stuff
    'cmsutils.middleware.ProfileMiddleware',
    # ... stuff

When the middleware is activated with DEBUG set to True, just access the page you want to profile, adding a HTTP profile GET parameter. For example, if your server is running at localhost:8000, point your browser to:

http://localhost:8000/?profile

And Merengue will show a page like this:

119364 function calls (110393 primitive calls) in 0.842 CPU seconds

Ordered by: internal time, call count

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    4796    0.076    0.000    0.076    0.000 /tmp/venv2.6/lib/python2.6/posixpath.py:307(normpath)
      11    0.075    0.007    0.076    0.007 /tmp/django_src_1.3.X/django/db/models/fields/related.py:759(db_type)
    2398    0.042    0.000    0.191    0.000 /tmp/django_src_1.3.X/django/utils/_os.py:24(safe_join)
      88    0.035    0.000    0.055    0.001 /tmp/django_src_1.3.X/django/template/debug.py:10(tokenize)
      79    0.032    0.000    0.191    0.002 /tmp/django_src_1.3.X/django/template/loaders/app_directories.py:48(load_template_source)
      ... # more stuff