ProfilingDjango: runserver-profiler2.2.diff

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

updated the patch against the latest revision and made the path configurable

  • management.py

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