ProfilingDjango: runserver-profiler2.diff

File runserver-profiler2.diff, 1.2 KB (added by LawrenceOluyede, 8 years ago)

updated the patch against the latest revision

  • management.py

     
    77from optparse import OptionParser
    88from django.utils import termcolors
    99
     10import hotshot, time, os
     11def make_profiler_handler(inner_handler):
     12    def handler(environ, start_response):
     13        profname = "%s.%.3f.prof" % (environ['PATH_INFO'].strip("/").replace('/', '.'), time.time())
     14        profname = os.path.join('/tmp', profname)
     15        prof = hotshot.Profile(profname)
     16        return prof.runcall(inner_handler, environ, start_response)
     17    return handler
     18
    1019# For Python 2.3
    1120if not hasattr(__builtins__, 'set'):
    1221    from sets import Set as set
     
    11881197        try:
    11891198            import django
    11901199            path = admin_media_dir or django.__path__[0] + '/contrib/admin/media'
    1191             handler = AdminMediaHandler(WSGIHandler(), path)
     1200            handler = make_profiler_handler(AdminMediaHandler(WSGIHandler(), path))
    11921201            run(addr, int(port), handler)
    11931202        except WSGIServerException, e:
    11941203            # Use helpful error messages instead of ugly tracebacks.
Back to Top