Changes between Version 6 and Version 7 of ProfilingDjango


Ignore:
Timestamp:
07/30/2007 05:58:02 AM (8 years ago)
Author:
Michael Twomey <micktwomey@…>
Comment:

Showing an alternative profiling approach using WSGI and wsgiref

Legend:

Unmodified
Added
Removed
Modified
  • ProfilingDjango

    v6 v7  
    1313
    1414You can also use [http://code.djangoproject.com/browser/django/trunk/django/bin/profiling/gather_profile_stats.py gather_profile_stats.py] in the Django distribution to aggregate the generated profilings and open them with pstats.Stats
     15
     16== Using WSGI to profile ==
     17
     18An alternative approach is to run django from a boring WSGI server and profile that. For example using wsgiref you can create a really simple WSGI server for running django:
     19
     20{{{
     21from wsgiref.simple_server import make_server
     22from django.core.handlers.wsgi import WSGIHandler
     23httpd = make_server('', 8000, WSGIHandler())
     24httpd.serve_forever()
     25}}}
     26
     27Run this using:
     28
     29{{{
     30$ DJANGO_SETTINGS_MODULE=mysite.settings python myserver.py
     31}}}
     32
     33To profile this run using cProfile (or profile):
     34
     35{{{
     36$ DJANGO_SETTINGS_MODULE=mysite.settings python -m cProfile myserver.py
     37}}}
     38
     39The default invocation will print the profile stats when you kill the server, it's probably more useful to write to a file and use pstats to read it:
     40
     41{{{
     42$ DJANGO_SETTINGS_MODULE=mysite.settings python -m cProfile -o mysite.profile myserver.py
     43... lots of requests ...
     44
     45$ python
     46>>> import pstats
     47>>> s = pstats.Stats("mysite.profile")
     48>>> s.sort_stats("time").print_stats(20)
     49}}}
     50
Back to Top