ProfilingDjango: runserver-profiler2.2.diff
File runserver-profiler2.2.diff, 1.2 KB (added by , 18 years ago) |
---|
-
management.py
7 7 from optparse import OptionParser 8 8 from django.utils import termcolors 9 9 10 PROF_PATH = '/tmp' 11 12 import hotshot, time, os 13 def 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 10 21 # For Python 2.3 11 22 if not hasattr(__builtins__, 'set'): 12 23 from sets import Set as set … … 1188 1199 try: 1189 1200 import django 1190 1201 path = admin_media_dir or django.__path__[0] + '/contrib/admin/media' 1191 handler = AdminMediaHandler(WSGIHandler(), path)1202 handler = make_profiler_handler(AdminMediaHandler(WSGIHandler(), path)) 1192 1203 run(addr, int(port), handler) 1193 1204 except WSGIServerException, e: 1194 1205 # Use helpful error messages instead of ugly tracebacks.